Skip to content

Commit

Permalink
Finetune local stops
Browse files Browse the repository at this point in the history
allow to find cross midnight
  • Loading branch information
vingerha committed Jan 3, 2024
1 parent 70bcb35 commit e463ae7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_components/gtfs2/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def _async_update_data(self) -> dict[str, str]:
)
self._data = {
"schedule": self._pygtfs,
"include_tomorrow": False,
"include_tomorrow": True,
"gtfs_dir": DEFAULT_PATH,
"name": data["name"],
"file": data["file"],
Expand Down
13 changes: 7 additions & 6 deletions custom_components/gtfs2/gtfs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def get_local_stops_next_departures(self):
{tomorrow_select}
calendar.start_date AS start_date,
calendar.end_date AS end_date,
"" as calendar_date,
:today as calendar_date,
0 as today_cd
FROM trips trip
INNER JOIN calendar calendar
Expand All @@ -716,7 +716,7 @@ def get_local_stops_next_departures(self):
ON route.route_id = trip.route_id
WHERE
trip.service_id not in (select service_id from calendar_dates where date = :today and exception_type = 2)
and time(st.departure_time) between time('now','localtime') and time('now','localtime',:timerange)
and datetime(calendar_date || ' ' || time(st.departure_time) ) between datetime('now','localtime') and datetime('now','localtime',:timerange)
AND calendar.start_date <= :today
AND calendar.end_date >= :today
)
Expand All @@ -741,7 +741,7 @@ def get_local_stops_next_departures(self):
ON trip.service_id = calendar_date_today.service_id
WHERE
today_cd = 1
and time(st.departure_time) between time('now','localtime') and time('now','localtime',:timerange)
and datetime(calendar_date || ' ' || time(st.departure_time) ) between datetime('now','localtime') and datetime('now','localtime',:timerange)
{tomorrow_calendar_date_where}
)
order by stop_id, departure_time
Expand All @@ -760,7 +760,7 @@ def get_local_stops_next_departures(self):
timetable = []
local_stops_list = []
prev_stop_id = ""
prev_entry = entry = {}
for row_cursor in result:
row = row_cursor._asdict()
entry = {"stop_id": row['stop_id'], "stop_name": row['stop_name'], "latitude": row['latitude'], "longitude": row['longitude'], "departure": timetable}
Expand All @@ -783,8 +783,9 @@ def get_local_stops_next_departures(self):
timetable = []

prev_stop_id = str(row["stop_id"])

local_stops_list.append(entry)

if entry:
local_stops_list.append(entry)
data_returned = local_stops_list
_LOGGER.debug("Stop data returned: %s", data_returned)
return data_returned
Expand Down

0 comments on commit e463ae7

Please sign in to comment.