Fix lookup of walk time to the stop
This commit is contained in:
parent
ccf7c62727
commit
e39e18d243
23
config.py
23
config.py
|
|
@ -4,40 +4,41 @@ class Config:
|
|||
def __init__(self):
|
||||
# Load the config file
|
||||
with open("config.yaml") as f:
|
||||
self.__config = yaml.safe_load(f.read())
|
||||
self.config = yaml.safe_load(f.read())
|
||||
|
||||
# Pre-load some dictionaries to simplify lookups
|
||||
self.__walk_time_by_stop = {}
|
||||
for s in self.__config.get("stops", []):
|
||||
self.__walk_time_by_stop[s["stop_id"]] = s["walk_time"]
|
||||
self.walk_time_by_stop = {}
|
||||
for s in self.config.get("stops", []):
|
||||
self.walk_time_by_stop[str(s["stop_id"])] = s["walk_time"]
|
||||
|
||||
@property
|
||||
def gtfs_feed_url(self) -> str:
|
||||
return self.__config.get("gtfs-feed-url")
|
||||
return self.config.get("gtfs-feed-url")
|
||||
|
||||
@property
|
||||
def gtfs_api_url(self) -> str:
|
||||
return self.__config.get("gtfs-r-api-url")
|
||||
return self.config.get("gtfs-r-api-url")
|
||||
|
||||
@property
|
||||
def gtfs_api_key(self) -> str:
|
||||
return self.__config.get("gtfs-r-api_key")
|
||||
return self.config.get("gtfs-r-api_key")
|
||||
|
||||
@property
|
||||
def update_interval_seconds(self) -> int:
|
||||
return self.__config.get("update-interval-seconds")
|
||||
return self.config.get("update-interval-seconds")
|
||||
|
||||
@property
|
||||
def stop_codes(self) -> list[str]:
|
||||
return [str(s["stop_id"]) for s in self.__config.get("stops")]
|
||||
return [str(s["stop_id"]) for s in self.config.get("stops")]
|
||||
|
||||
def minutes_to_stop(self, stop_id) -> int:
|
||||
return self.__walk_time_by_stop.get(stop_id, 0)
|
||||
minutes = self.walk_time_by_stop.get(stop_id, 0)
|
||||
return minutes
|
||||
|
||||
def routes_for_stops(self) -> map:
|
||||
result = {}
|
||||
|
||||
for s in self.__config.get("stops"):
|
||||
for s in self.config.get("stops"):
|
||||
for r in s.get("routes", []):
|
||||
routes = (result.get(s.get("stop_id")) or [])
|
||||
routes.append(r)
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ class GTFSClient():
|
|||
if arrival_time < int(time.time()):
|
||||
continue
|
||||
new_arrival = ArrivalTime(
|
||||
stop_id = stop_time_update.get("stop_id"),
|
||||
stop_id = stop_time_update.get("stop_code"),
|
||||
route_id = self.feed.routes[self.feed.routes["route_id"] == route_id]["route_short_name"].item(),
|
||||
destination = self.__lookup_headsign_by_route(route_id, direction_id),
|
||||
due_in_seconds = arrival_time - int(time.time()),
|
||||
|
|
@ -374,7 +374,7 @@ class GTFSClient():
|
|||
if delta != 0:
|
||||
print("Delta for route {} stop {} is {}".format(bus["route_short_name"], bus["stop_id"], delta))
|
||||
|
||||
arrival = ArrivalTime(stop_id = bus["stop_id"],
|
||||
arrival = ArrivalTime(stop_id = bus["stop_code"],
|
||||
route_id = bus["route_short_name"],
|
||||
destination = bus["trip_headsign"],
|
||||
due_in_seconds = self.__due_in_seconds(bus["arrival_time"]) + delta,
|
||||
|
|
|
|||
Loading…
Reference in New Issue