summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-03-28 21:58:27 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-03-28 21:58:27 +0200
commitb3d58de021114765a4aedd0c7f5edacfb33b6dba (patch)
tree09bb111e3c410d1236aa9fa88ee8eff2e61abc9b
parenta7438499c9445da4fb80877c7e867d121b7b65fe (diff)
add some todos
-rwxr-xr-xbin/lookup-server19
1 files changed, 12 insertions, 7 deletions
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}