summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-04-02 10:34:56 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-04-02 10:34:56 +0200
commitb5955549ccbdd71c42b6ef621a6d87ded2972ad4 (patch)
tree36ec8160e7b46a731333b1f554f3f3d29b705997 /bin
parentd273ecaaee8ddae3bf04016b43f63e2759104890 (diff)
report likelihood in addition to estimated distance
Diffstat (limited to 'bin')
-rwxr-xr-xbin/lookup-server7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/lookup-server b/bin/lookup-server
index d54f03d..ea19880 100755
--- a/bin/lookup-server
+++ b/bin/lookup-server
@@ -18,6 +18,8 @@ import numpy as np
import os
import pytz
+max_distance = 50
+
class Stop:
def __init__(self, eva, name, coord, ts):
@@ -216,6 +218,7 @@ class Train:
"tripId": self.tripId,
"location": self.coarse_location,
"distance": round(self.distance, 1),
+ "likelihood": round(100 - self.distance * 100 / max_distance, 0),
"stops": [self.prev_stop.to_json(), self.next_stop.to_json()],
}
@@ -353,8 +356,8 @@ async def handle_search(request):
logging.debug(f"{len(trains)} trains remain after deduplication")
- # If a train's coarse location is 50km+ away, it's fine (polyline-based) location is highly unlikely to be much closer
- trains = list(filter(lambda train: train.distance < 50, trains))
+ # If a train's coarse location is more than max_distance km away, it's fine (polyline-based) location is highly unlikely to be much closer
+ trains = list(filter(lambda train: train.distance < max_distance, trains))
need_fine = list(filter(lambda train: not train.location, trains))
need_fine = list(filter(is_in_transit, trains))
logging.debug(f"{len(need_fine)} trains need a polyline")