From 751e03fce196413f5db1aa02a042363bc62c3df6 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 29 Mar 2021 15:15:41 +0200 Subject: lookup-server: add some more notes --- bin/lookup-server | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'bin/lookup-server') diff --git a/bin/lookup-server b/bin/lookup-server index 8a17002..2966995 100755 --- a/bin/lookup-server +++ b/bin/lookup-server @@ -101,8 +101,8 @@ def set_coarse_location(train, latlon): coords[1][1] * ratio + coords[0][1] * (1 - ratio), ) - if distance(train["coords"][0], train["coords"][1]).km < 15: - # do not request polyline if the train is between stops less than 15km apart. This speeds up requests + if distance(train["coords"][0], train["coords"][1]).km < 20: + # do not request polyline if the train is between stops less than 20km apart. This speeds up requests # (and reduces transport.rest load) at a hopefully low impact on accuracy. train["location"] = train["coarse_location"] @@ -112,6 +112,8 @@ def set_coarse_location(train, latlon): else: train["preferred"] = False + # the time (i.e., number of minutes) the train needs to travel to reach the requested position + # might be a better metric than raw distance. train["distance"] = distance(train["coarse_location"], latlon).km @@ -127,6 +129,10 @@ async def set_location(train): content = json.loads(content) +def is_in_transit(train): + return 0 < train["progress_ratio"] < 1 + + def format_train(train): train_type, line_no = train["line"]["name"].split() train_no = train["line"]["fahrtNr"] @@ -210,13 +216,12 @@ async def handle_search(request): set_coarse_location(train, (lat, lon)) trains = list(filter(lambda train: "coarse_location" in train, trains)) + logging.debug(f"{len(trains)} trains have a coarse location") trains = sorted( trains, key=lambda train: 0 if train["preferred"] else train["distance"] ) - logging.debug(f"{len(trains)} trains have a coarse location") - # remove duplicates. for now, we keep the preferred version, or the one with the lowest estimated distance. # later on, we'll need to request polylines and perform accurate calculations. # TODO polyline requests are not needed for trains currently located at a station (ratio == 0 / == 1) @@ -231,6 +236,7 @@ async def handle_search(request): logging.debug(f"{len(trains)} trains remain after deduplication") need_fine = list(filter(lambda train: "location" not in train, trains)) + need_fine = list(filter(is_in_transit, trains)) logging.debug(f"{len(need_fine)} trains need a polyline") for train in trains: -- cgit v1.2.3