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):
|
def __init__(self):
|
||||||
# Load the config file
|
# Load the config file
|
||||||
with open("config.yaml") as f:
|
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
|
# Pre-load some dictionaries to simplify lookups
|
||||||
self.__walk_time_by_stop = {}
|
self.walk_time_by_stop = {}
|
||||||
for s in self.__config.get("stops", []):
|
for s in self.config.get("stops", []):
|
||||||
self.__walk_time_by_stop[s["stop_id"]] = s["walk_time"]
|
self.walk_time_by_stop[str(s["stop_id"])] = s["walk_time"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gtfs_feed_url(self) -> str:
|
def gtfs_feed_url(self) -> str:
|
||||||
return self.__config.get("gtfs-feed-url")
|
return self.config.get("gtfs-feed-url")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gtfs_api_url(self) -> str:
|
def gtfs_api_url(self) -> str:
|
||||||
return self.__config.get("gtfs-r-api-url")
|
return self.config.get("gtfs-r-api-url")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gtfs_api_key(self) -> str:
|
def gtfs_api_key(self) -> str:
|
||||||
return self.__config.get("gtfs-r-api_key")
|
return self.config.get("gtfs-r-api_key")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def update_interval_seconds(self) -> int:
|
def update_interval_seconds(self) -> int:
|
||||||
return self.__config.get("update-interval-seconds")
|
return self.config.get("update-interval-seconds")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stop_codes(self) -> list[str]:
|
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:
|
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:
|
def routes_for_stops(self) -> map:
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for s in self.__config.get("stops"):
|
for s in self.config.get("stops"):
|
||||||
for r in s.get("routes", []):
|
for r in s.get("routes", []):
|
||||||
routes = (result.get(s.get("stop_id")) or [])
|
routes = (result.get(s.get("stop_id")) or [])
|
||||||
routes.append(r)
|
routes.append(r)
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,7 @@ class GTFSClient():
|
||||||
if arrival_time < int(time.time()):
|
if arrival_time < int(time.time()):
|
||||||
continue
|
continue
|
||||||
new_arrival = ArrivalTime(
|
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(),
|
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),
|
destination = self.__lookup_headsign_by_route(route_id, direction_id),
|
||||||
due_in_seconds = arrival_time - int(time.time()),
|
due_in_seconds = arrival_time - int(time.time()),
|
||||||
|
|
@ -374,7 +374,7 @@ class GTFSClient():
|
||||||
if delta != 0:
|
if delta != 0:
|
||||||
print("Delta for route {} stop {} is {}".format(bus["route_short_name"], bus["stop_id"], delta))
|
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"],
|
route_id = bus["route_short_name"],
|
||||||
destination = bus["trip_headsign"],
|
destination = bus["trip_headsign"],
|
||||||
due_in_seconds = self.__due_in_seconds(bus["arrival_time"]) + delta,
|
due_in_seconds = self.__due_in_seconds(bus["arrival_time"]) + delta,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue