Skip to content

Commit

Permalink
feat: remove upper bound constraint for orig_dep_date (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsarrco committed Dec 16, 2023
2 parents 4116ebf + 03f262f commit 9e40ff3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions server/base/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,18 @@ def get_stop_times(self, stops_ids, line, start_dt: datetime, offset: int | tupl
else:
stmt = select(StopTime)

day = start_dt.date()
day_minus_one = day - timedelta(days=1)
start_day_minus_one = start_dt.date() - timedelta(days=1)
stmt = stmt.filter(StopTime.orig_dep_date >= start_day_minus_one)

if end_dt:
stmt = stmt.filter(StopTime.orig_dep_date <= end_dt.date())

stmt = stmt.filter(StopTime.orig_dep_date.between(day_minus_one, day), StopTime.stop_id.in_(stops_ids))
stmt = stmt.filter(StopTime.stop_id.in_(stops_ids))

if direction == 1:
stmt = stmt.filter(StopTime.sched_dep_dt >= start_dt)
if end_dt:
stmt = stmt.filter(StopTime.sched_dep_dt < end_dt)
stmt = stmt.filter(StopTime.sched_dep_dt <= end_dt)
else:
stmt = stmt.filter(StopTime.sched_dep_dt <= start_dt)
if end_dt:
Expand Down
3 changes: 2 additions & 1 deletion tgbot/stop_times_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def get_times(self, db_file: Source) -> list[Liner]:
if start_dt.day < self.day.day:
start_dt = datetime.combine(self.day, time())

end_dt = datetime.combine(self.day + timedelta(days=1), time())
# end_at is same day as start_at at 23:59
end_dt = datetime.combine(self.day, time(23, 59))

if self.arr_stop_ids:
arr_stop = Station(name=self.arr_cluster_name, ids=self.arr_stop_ids)
Expand Down

0 comments on commit 9e40ff3

Please sign in to comment.