Special column applies only on non-rest days
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
63a36333fb
commit
8649d3abd0
3 files changed
+19
-6
No files matched your search
@@ -97,13 +97,15 @@ effects in their pure functions so they are unit-testable.
|
|||||||
### Choosing the column (schedule.py)
|
### Choosing the column (schedule.py)
|
||||||
|
|
||||||
For a given date:
|
For a given date:
|
||||||
1. If the date is in a `special` column's explicit dates → that column.
|
1. If the date is not a rest day and is in a `special` column's explicit dates → that column
|
||||||
|
(the special column is workdays during school holidays, so it never applies on a
|
||||||
|
Saturday, Sunday or state holiday).
|
||||||
2. Else if it is a Saturday, Sunday or Czech state holiday → the `rest_day` column.
|
2. Else if it is a Saturday, Sunday or Czech state holiday → the `rest_day` column.
|
||||||
3. Else → the `workday` column.
|
3. Else → the `workday` column.
|
||||||
|
|
||||||
Among columns of the same kind, use the one with the latest `valid_from <= date`;
|
Among columns of the same kind, use the one with the latest `valid_from <= date`;
|
||||||
if none yet applies, use the earliest. Steps 1–3 are the proposed default order
|
if none yet applies, use the earliest. Steps 1–3 are the proposed default order
|
||||||
(special date beats holiday/weekend); the user writes and may change this function,
|
(a special date on a workday beats the workday column; rest days always use the rest-day column); the user writes and may change this function,
|
||||||
see "User-written code" below.
|
see "User-written code" below.
|
||||||
|
|
||||||
`next_departures` looks at today's selected column from `now`, and rolls into the
|
`next_departures` looks at today's selected column from `now`, and rolls into the
|
||||||
|
|||||||
+5
-1
@@ -17,12 +17,15 @@ def select_column(columns: Sequence[Column], day: date, rest_day: bool) -> Colum
|
|||||||
"""The column that applies on `day`, or None if the timetable has no usable column.
|
"""The column that applies on `day`, or None if the timetable has no usable column.
|
||||||
|
|
||||||
Rules (see spec "Choosing the column"):
|
Rules (see spec "Choosing the column"):
|
||||||
1. a KIND_SPECIAL column whose `dates` contain `day` wins;
|
1. on a non-rest day, a KIND_SPECIAL column whose `dates` contain `day` wins
|
||||||
|
(the special column is workdays-during-school-holidays, so it never applies
|
||||||
|
on a Saturday, Sunday or state holiday);
|
||||||
2. otherwise rest days use KIND_REST_DAY columns, other days KIND_WORKDAY;
|
2. otherwise rest days use KIND_REST_DAY columns, other days KIND_WORKDAY;
|
||||||
3. among columns of that kind the one with the latest valid_from <= day;
|
3. among columns of that kind the one with the latest valid_from <= day;
|
||||||
if none has started yet, the one with the earliest valid_from;
|
if none has started yet, the one with the earliest valid_from;
|
||||||
4. no column of the needed kind -> None.
|
4. no column of the needed kind -> None.
|
||||||
"""
|
"""
|
||||||
|
if not rest_day:
|
||||||
for column in columns:
|
for column in columns:
|
||||||
if column.kind == KIND_SPECIAL and day in column.dates:
|
if column.kind == KIND_SPECIAL and day in column.dates:
|
||||||
return column
|
return column
|
||||||
@@ -59,6 +62,7 @@ def next_departures(
|
|||||||
for dep in column.departures:
|
for dep in column.departures:
|
||||||
when = datetime.combine(day, dep.time)
|
when = datetime.combine(day, dep.time)
|
||||||
if when >= start:
|
if when >= start:
|
||||||
|
# naive local-time difference: off by one hour on the two DST nights (00:00-03:00)
|
||||||
minutes = int((when - start).total_seconds() // 60)
|
minutes = int((when - start).total_seconds() // 60)
|
||||||
found.append(Upcoming(dep, when, minutes, day != now.date()))
|
found.append(Upcoming(dep, when, minutes, day != now.date()))
|
||||||
if len(found) >= count:
|
if len(found) >= count:
|
||||||
|
|||||||
+10
-3
@@ -55,9 +55,16 @@ def test_special_column_ignored_on_other_days():
|
|||||||
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 11, 2), rest_day=False) is WORK_NEW
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 11, 2), rest_day=False) is WORK_NEW
|
||||||
|
|
||||||
|
|
||||||
def test_special_date_beats_rest_day():
|
def test_special_date_is_ignored_on_a_rest_day():
|
||||||
# Default precedence (your call to change): a special date wins even on a rest day.
|
# Decision: the special column is "Prac.dny-skolni prazdniny", i.e. workdays during
|
||||||
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 29), rest_day=True) is SPECIAL
|
# school holidays only, so it never applies on a Saturday, Sunday or state holiday
|
||||||
|
# (rule set by the controller on 2026-10-07 after the final review).
|
||||||
|
assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 29), rest_day=True) is REST
|
||||||
|
|
||||||
|
|
||||||
|
def test_special_dates_on_a_saturday_use_the_rest_column():
|
||||||
|
special = col(KIND_SPECIAL, date(2026, 10, 29), [date(2026, 10, 29), date(2026, 10, 31)])
|
||||||
|
assert select_column([WORK_NEW, REST, special], date(2026, 10, 31), rest_day=True) is REST
|
||||||
|
|
||||||
|
|
||||||
def test_no_column_of_the_needed_kind_returns_none():
|
def test_no_column_of_the_needed_kind_returns_none():
|
||||||
|
|||||||
Reference in new issue
Block a user