From b3d58de021114765a4aedd0c7f5edacfb33b6dba Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 28 Mar 2021 21:58:27 +0200 Subject: add some todos --- bin/lookup-server | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'bin/lookup-server') diff --git a/bin/lookup-server b/bin/lookup-server index 6e33724..19f79cd 100755 --- a/bin/lookup-server +++ b/bin/lookup-server @@ -58,6 +58,8 @@ def set_coarse_location(train): stopover["stop"]["location"]["longitude"], ), ) + # XXX known bug: we're saving departure at i-1 and departure at i. For a more accurate coarse position estimate later on, + # we need to track departure at i-1 and arrival at i. But we don't have it... train_times = (stopovers[i - 1]["departure"], departure) break if not train_evas: @@ -188,13 +190,6 @@ async def handle_search(request): if is_candidate: trains.append(train) - seen = set() - trains = [ - seen.add(train["line"]["fahrtNr"]) or train - for train in trains - if train["line"]["fahrtNr"] not in seen - ] - for train in trains: set_coarse_location(train) @@ -204,6 +199,16 @@ async def handle_search(request): calculate_distance(train, (lat, lon)) trains = sorted(trains, key=lambda train: train["distance"]) + + # remove duplicates. for now, we keep the version with the lowest estimated distance. + # later on, we'll need to request polylines and perform accurate calculations. + seen = set() + trains = [ + seen.add(train["line"]["fahrtNr"]) or train + for train in trains + if train["line"]["fahrtNr"] not in seen + ] + trains = list(map(format_train, trains[:10])) response = {"evas": list(evas), "trains": trains} -- cgit v1.2.3