Take into account cancelled stops for route & destination
This commit is contained in:
parent
4c534b7a1f
commit
21044e1407
13
run.py
13
run.py
|
@ -30,6 +30,10 @@ def route_from(route, station):
|
|||
def get_trains(dbi, station):
|
||||
return dbi.get_trains(station)
|
||||
|
||||
def filter_route(route):
|
||||
# Filter all cancelled stops from a route
|
||||
return [stop for stop in route if not stop.get('isCancelled')]
|
||||
|
||||
|
||||
def update_display(display, dbi):
|
||||
display.clear()
|
||||
|
@ -42,7 +46,7 @@ def update_display(display, dbi):
|
|||
elif PLATFORMS_EXCLUDE:
|
||||
trains = list(filter(lambda t: t['platform'] not in PLATFORMS_EXCLUDE, trains))
|
||||
# Remove arrivals
|
||||
trains = list(filter(lambda t: not any(filter(lambda arrival_station_name: t['destination'].startswith(arrival_station_name), ARRIVAL_STATIONS)), trains))
|
||||
trains = list(filter(lambda t: not any(filter(lambda arrival_station_name: filter_route(t['route'])[-1]['name'].startswith(arrival_station_name), ARRIVAL_STATIONS)), trains))
|
||||
except:
|
||||
traceback.print_exc()
|
||||
display.info_1.set(OUT_OF_ORDER_TEXT)
|
||||
|
@ -72,7 +76,7 @@ def update_display(display, dbi):
|
|||
if train_type == "RE":
|
||||
display.info_2.set(NO_STOP_EVERYWHERE_TEXT)
|
||||
|
||||
is_arrival = any(filter(lambda arrival_station_name: train['destination'].startswith(arrival_station_name), ARRIVAL_STATIONS))
|
||||
is_arrival = any(filter(lambda arrival_station_name: filter_route(train['route'])[-1]['name'].startswith(arrival_station_name), ARRIVAL_STATIONS))
|
||||
|
||||
#if train['platform'] != PLATFORM:
|
||||
# platform = int("".join(c for c in train['platform'] if c.isdigit()))
|
||||
|
@ -119,7 +123,7 @@ def update_display(display, dbi):
|
|||
train_type_text = TRAIN_TYPE_MAP.get(train_type, "")
|
||||
display.info_1.set(train_type_text)
|
||||
|
||||
route = route_from([VIA_MAP.get(stop['name'], stop['name']) for stop in train['route']], STATION_NAME)[:-1]
|
||||
route = route_from([VIA_MAP.get(stop['name'], stop['name']) for stop in [s for s in train['route'] if not s.get('isCancelled')]], STATION_NAME)[:-1]
|
||||
via_combination = get_vias(route, VIA_WEIGHTS, VIA_1, VIA_2, check_dashes=False, debug=True)
|
||||
if via_combination:
|
||||
via_code_1, via_code_2 = via_combination
|
||||
|
@ -131,7 +135,8 @@ def update_display(display, dbi):
|
|||
text = text.rstrip("Hbf").strip()
|
||||
display.destination.set(text)
|
||||
else:
|
||||
text = DESTINATION_MAP.get(train['destination'], train['destination']).replace("ß", "ss")
|
||||
dest = filter_route(train['route'])[-1]['name']
|
||||
text = DESTINATION_MAP.get(dest, dest).replace("ß", "ss")
|
||||
if train_type == "S":
|
||||
text = "".join(train['train'].split()) + " " + text
|
||||
display.destination.set(text)
|
||||
|
|
Loading…
Reference in New Issue