mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 19:07:16 +01:00
A sick day is now a date in the shared sickdays pool (utils sickdays 0.1.0) and nothing else. Removed: the 7/30/90-day budget, the escalating lockout countdown, the justification form, the commitment prompt and its double debt, the workout-debt counter, the -60 min shutdown cut and its sick_day_state.json, the post-sick-day --verify-workout mode, the sick auto-upgrade, scripts/revoke_sick_day.py and their tests. - Lock screen: "I'm sick" on the retry, no-phone and both Tue-Thu screens; one tap -> sickdays.add_sick_day(today) -> sick floor -> best-effort background sickdays.sync_quietly -> unlock. Refusals (free day, unreadable pool) are shown and the lock stays. - Shutdown: the reset resolves with earned_time.resolve(..., sick=True) (max(20:00, ladder), capped 23:00) and saves the sick lift with the grace lift, so later credits absorb it instead of stacking on 20:00. A day marked after the reset is lifted by the new _sick_floor live pass (every 5-min tick, --sync-only, --apply-bonuses, and the tap itself). - Workout lock and grace floor stand down on a sick day; workouts that day credit normally through the sync paths. - wake-alarm workday_penalty.json is void when its issued_date or penalty_date is a sick day. - Status window, i3 line, CLI --status, MCP flags and web reasons read sickdays. - scripts/migrate_sick_history.py imports sick_history.json's dates via sickdays.import_legacy, verifies and removes the file; idempotent, run by install.sh. - Pins: earned-time 0.11.0, freedays 0.4.0, sickdays 0.1.0 (tags pending); pre-commit 4.7.0, ruff 0.17.1 (freshness gate). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xfj1sxKH9VBPqpcAni8Jry
114 lines
4.0 KiB
Python
114 lines
4.0 KiB
Python
"""Shutdown projection and the one-line i3blocks summary.
|
|
|
|
Split out of :mod:`screen_locker._status_data` to keep every file under the
|
|
250-line cap. ``format_summary_line`` is re-exported from there, so
|
|
``status_view`` and the i3blocks CLI are unaffected.
|
|
|
|
Projects what time the PC will shut down on each remaining day of the week,
|
|
and renders the compact status line.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime, timedelta
|
|
from typing import TYPE_CHECKING
|
|
|
|
from screen_locker._earned import hhmm
|
|
from screen_locker._shutdown import read_shutdown_config
|
|
from screen_locker._shutdown_base import base_minutes
|
|
from screen_locker._status_types import ShutdownProjection, ShutdownProjectionDay
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
from screen_locker._status_types import StatusSnapshot
|
|
|
|
_RELAXED_DAY_EXPLANATION = (
|
|
"Shutdown time and the screen lock are two separate systems: the lock "
|
|
"decides whether you must log a workout right now; shutdown time only "
|
|
"controls how late the PC stays on tonight."
|
|
)
|
|
_WEEKDAY_LABELS = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
|
|
_MON_WED_WEEKDAYS = frozenset({0, 1, 2})
|
|
|
|
|
|
def _week_rows(monday: date, *, speculative: bool) -> tuple[ShutdownProjectionDay, ...]:
|
|
"""Build 7 labeled rows, Mon-Sun from ``monday``, each on its own day's base.
|
|
|
|
Each row asks ``base_minutes`` for its own date, so a registry cut dated
|
|
mid-week (or next week) shows on the day it lands, not from today's base.
|
|
"""
|
|
return tuple(
|
|
ShutdownProjectionDay(
|
|
label=label,
|
|
minutes=base_minutes(monday + timedelta(days=weekday)),
|
|
speculative=speculative,
|
|
)
|
|
for weekday, label in enumerate(_WEEKDAY_LABELS)
|
|
)
|
|
|
|
|
|
def _shutdown_projection(
|
|
*,
|
|
shutdown_config_file: Path,
|
|
today_local: datetime,
|
|
) -> ShutdownProjection:
|
|
"""Build the shutdown-time projection: tonight, rest of week, next week.
|
|
|
|
Every row is the plain per-day base: no week carries a banked shutdown
|
|
bonus (dropped 2026-10-10).
|
|
"""
|
|
tonight = read_shutdown_config(shutdown_config_file)
|
|
monday = today_local.date() - timedelta(days=today_local.weekday())
|
|
rest_of_week = _week_rows(monday, speculative=False)
|
|
next_week_preview = _week_rows(monday + timedelta(weeks=1), speculative=True)
|
|
|
|
return ShutdownProjection(
|
|
tonight=tonight,
|
|
rest_of_week=rest_of_week,
|
|
next_week_preview=next_week_preview,
|
|
explanation=_RELAXED_DAY_EXPLANATION,
|
|
)
|
|
|
|
|
|
def _tonight_minutes(snapshot: StatusSnapshot) -> int | None:
|
|
"""Pick the shutdown band (Mon-Wed vs Thu-Sun) matching today, in minutes.
|
|
|
|
Uses ``snapshot.generated_at`` (not a fresh ``datetime.now()``) so the
|
|
summary line is a pure function of the snapshot it was handed.
|
|
"""
|
|
if snapshot.shutdown.tonight is None:
|
|
return None
|
|
mon_wed, thu_sun, _morning = snapshot.shutdown.tonight
|
|
generated_weekday = (
|
|
datetime.fromisoformat(snapshot.generated_at).astimezone().weekday()
|
|
)
|
|
return mon_wed if generated_weekday in _MON_WED_WEEKDAYS else thu_sun
|
|
|
|
|
|
def format_summary_line(snapshot: StatusSnapshot) -> str:
|
|
"""Cheap one-liner for the i3blocks summary (e.g. before/after a click)."""
|
|
week = snapshot.week
|
|
mark = "✓" if week.remaining == 0 else "…"
|
|
tonight = _tonight_minutes(snapshot)
|
|
tonight_str = hhmm(tonight) if tonight is not None else "?"
|
|
sick = " · sick day" if snapshot.today.is_sick_day else ""
|
|
return (
|
|
f"{mark} {week.counted_count}/{week.minimum} workouts · "
|
|
f"{tonight_str} tonight{sick}"
|
|
)
|
|
|
|
|
|
def compliance_state_word(snapshot: StatusSnapshot) -> str:
|
|
"""One-word compliance state for the tray icon: ``ok`` / ``warn`` / ``lock``.
|
|
|
|
``lock`` — the lock would fire right now (no skip condition applies).
|
|
``warn`` — not locked, but this week's minimum isn't met yet.
|
|
``ok`` — not locked and the weekly minimum is already met.
|
|
"""
|
|
if snapshot.lock_explanation.fired:
|
|
return "lock"
|
|
if snapshot.week.remaining > 0:
|
|
return "warn"
|
|
return "ok"
|