feat(signage,scenes): schedule lines with screens and smart days, screens' defaults, horizontal timeline, scenes
- Scenes (Alembic 0043, models/scene.py, /api/scenes, core.scenes.manage): named modes on or off (optionally until a time); price rules / deals get the condition "a scene is on"; signage lines can play only during a scene; turning one on tells every screen and pushes the online menu. - Signage schedules are lines (signage_schedule_items): playlist, screens ([] = every screen), priority, days, smart days (1st / last day, first / last week, Greek public holidays or not: core/calendar_days.py, mirrored in @xenia/signage), hours, dates, scene. No line → the screen's default playlist. 0043 turns the old named schedules into lines for their screens. - Screens: default playlist, TV shape, turn; what plays now and why. - Manager: tabs Screens · Playlists · Schedules · Slides (placeholder) · Message and weather; schedule lines with playlist / screens / priority / delete on one line; the playlist editor's horizontal timeline of fixed cards, the slide's basics beside its preview (one height), then its content; Management → Scenes; the scene condition in pricing. - Tests: backend (lines, smart days, scenes, prices), player logic, e2e. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Smart day filters (owner 2026-11-21): the 1st / last day of the month, its first / last week, and
|
||||
Greek public holidays (fixed dates and those that follow the Orthodox Easter).
|
||||
|
||||
The same rules in JavaScript: packages/signage/src/logic.js (a screen applies its schedule while
|
||||
the server is down); both sides are tested with the same dates.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import calendar
|
||||
from datetime import date, timedelta
|
||||
|
||||
# the filters a schedule line can have: any one that holds is enough, except "not_holiday",
|
||||
# which keeps the line off on public holidays
|
||||
MONTH_DAYS = ("first", "last", "first_week", "last_week", "holiday", "not_holiday")
|
||||
|
||||
_FIXED = ((1, 1), (1, 6), (3, 25), (5, 1), (8, 15), (10, 28), (12, 25), (12, 26))
|
||||
# days from the Orthodox Easter Sunday: Clean Monday, Good Friday, Easter Sunday, Easter Monday, Whit Monday
|
||||
_FROM_EASTER = (-48, -2, 0, 1, 50)
|
||||
|
||||
|
||||
def orthodox_easter(year: int) -> date:
|
||||
"""The Orthodox Easter Sunday (Meeus' Julian algorithm, + 13 days to the Gregorian calendar, 1900-2099)."""
|
||||
a, b, c = year % 4, year % 7, year % 19
|
||||
d = (19 * c + 15) % 30
|
||||
e = (2 * a + 4 * b - d + 34) % 7
|
||||
month = (d + e + 114) // 31
|
||||
day = (d + e + 114) % 31 + 1
|
||||
return date(year, month, day) + timedelta(days=13)
|
||||
|
||||
|
||||
def is_holiday(day: date) -> bool:
|
||||
"""A Greek public holiday (nationwide)."""
|
||||
if (day.month, day.day) in _FIXED:
|
||||
return True
|
||||
easter = orthodox_easter(day.year)
|
||||
return any(day == easter + timedelta(days=n) for n in _FROM_EASTER)
|
||||
|
||||
|
||||
def month_days_ok(tokens, day: date) -> bool:
|
||||
"""Does a day pass a line's smart filters (empty = every day)?"""
|
||||
tokens = [t for t in (tokens or []) if t in MONTH_DAYS]
|
||||
if not tokens:
|
||||
return True
|
||||
hol = is_holiday(day)
|
||||
if "not_holiday" in tokens and hol:
|
||||
return False
|
||||
wanted = [t for t in tokens if t != "not_holiday"]
|
||||
if not wanted:
|
||||
return True
|
||||
last = calendar.monthrange(day.year, day.month)[1]
|
||||
return any((t == "first" and day.day == 1) or (t == "last" and day.day == last)
|
||||
or (t == "first_week" and day.day <= 7) or (t == "last_week" and day.day > last - 7)
|
||||
or (t == "holiday" and hol) for t in wanted)
|
||||
Reference in New Issue
Block a user