mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-28 02:09:15 +01:00
earned-time-v0.2.0 (anki); shutdown projection prices each day on its own date
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
275a0862fc
commit
2dd719e6a4
@ -134,7 +134,7 @@ repos:
|
|||||||
# than merely an old one.
|
# than merely an old one.
|
||||||
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
|
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
|
||||||
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
|
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
|
||||||
- earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.1.0#subdirectory=earned_time
|
- earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.2.0#subdirectory=earned_time
|
||||||
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
|
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
|
||||||
- mcp>=2,<3
|
- mcp>=2,<3
|
||||||
- pydantic
|
- pydantic
|
||||||
@ -155,7 +155,7 @@ repos:
|
|||||||
# than merely an old one.
|
# than merely an old one.
|
||||||
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
|
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
|
||||||
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
|
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
|
||||||
- earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.1.0#subdirectory=earned_time
|
- earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.2.0#subdirectory=earned_time
|
||||||
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
|
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
|
||||||
- mcp>=2,<3
|
- mcp>=2,<3
|
||||||
- pydantic
|
- pydantic
|
||||||
|
|||||||
@ -10,7 +10,7 @@ dependencies = [
|
|||||||
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock",
|
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock",
|
||||||
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync",
|
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync",
|
||||||
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays",
|
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays",
|
||||||
"earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.1.0#subdirectory=earned_time",
|
"earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.2.0#subdirectory=earned_time",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
|
|||||||
@ -4,7 +4,7 @@ bandit==1.9.4
|
|||||||
codespell==2.4.3
|
codespell==2.4.3
|
||||||
coverage==7.16.2
|
coverage==7.16.2
|
||||||
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
|
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
|
||||||
earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.1.0#subdirectory=earned_time
|
earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.2.0#subdirectory=earned_time
|
||||||
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
|
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
|
||||||
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
|
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
|
||||||
mcp==2.3.0
|
mcp==2.3.0
|
||||||
|
|||||||
@ -10,7 +10,7 @@ and renders the compact status line.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import date, datetime, timedelta
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from screen_locker._earned import hhmm
|
from screen_locker._earned import hhmm
|
||||||
@ -41,13 +41,17 @@ _MINUTES_PER_HOUR = 60
|
|||||||
|
|
||||||
|
|
||||||
def _week_rows(
|
def _week_rows(
|
||||||
mon_wed: int, thu_sun: int, *, speculative: bool
|
monday: date, bonus: int, *, speculative: bool
|
||||||
) -> tuple[ShutdownProjectionDay, ...]:
|
) -> tuple[ShutdownProjectionDay, ...]:
|
||||||
"""Build 7 labeled rows, one per weekday, from a Mon-Wed/Thu-Sun band pair."""
|
"""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(
|
return tuple(
|
||||||
ShutdownProjectionDay(
|
ShutdownProjectionDay(
|
||||||
label=label,
|
label=label,
|
||||||
minutes=mon_wed if weekday in _MON_WED_WEEKDAYS else thu_sun,
|
minutes=base_minutes(monday + timedelta(days=weekday)) + bonus,
|
||||||
speculative=speculative,
|
speculative=speculative,
|
||||||
)
|
)
|
||||||
for weekday, label in enumerate(_WEEKDAY_LABELS)
|
for weekday, label in enumerate(_WEEKDAY_LABELS)
|
||||||
@ -67,16 +71,19 @@ def _shutdown_projection(
|
|||||||
weekly_shutdown_bonus_hours(extra_benefits_file, today=today_local)
|
weekly_shutdown_bonus_hours(extra_benefits_file, today=today_local)
|
||||||
* _MINUTES_PER_HOUR
|
* _MINUTES_PER_HOUR
|
||||||
)
|
)
|
||||||
base = base_minutes(today_local.date())
|
monday = today_local.date() - timedelta(days=today_local.weekday())
|
||||||
rest_of_week = _week_rows(base + bonus, base + bonus, speculative=False)
|
rest_of_week = _week_rows(monday, bonus, speculative=False)
|
||||||
|
|
||||||
this_week_count = count_weekly_workouts(log_file, today=today_local)
|
this_week_count = count_weekly_workouts(log_file, today=today_local)
|
||||||
streak = current_streak(extra_benefits_file)
|
streak = current_streak(extra_benefits_file)
|
||||||
_would_be_streak, would_be_bonus = preview_bonus_if_week_ended_now(
|
_would_be_streak, would_be_bonus = preview_bonus_if_week_ended_now(
|
||||||
this_week_count, streak
|
this_week_count, streak
|
||||||
)
|
)
|
||||||
would_be = base + would_be_bonus * _MINUTES_PER_HOUR
|
next_week_preview = _week_rows(
|
||||||
next_week_preview = _week_rows(would_be, would_be, speculative=True)
|
monday + timedelta(weeks=1),
|
||||||
|
would_be_bonus * _MINUTES_PER_HOUR,
|
||||||
|
speculative=True,
|
||||||
|
)
|
||||||
|
|
||||||
return ShutdownProjection(
|
return ShutdownProjection(
|
||||||
tonight=tonight,
|
tonight=tonight,
|
||||||
|
|||||||
@ -101,7 +101,11 @@ class TestLedgerFile:
|
|||||||
|
|
||||||
class TestFlatEarners:
|
class TestFlatEarners:
|
||||||
def test_registry_order_without_the_counted_workout(self) -> None:
|
def test_registry_order_without_the_counted_workout(self) -> None:
|
||||||
assert flat_earners() == (earned_time.LEETCODE, earned_time.READING)
|
assert flat_earners() == (
|
||||||
|
earned_time.LEETCODE,
|
||||||
|
earned_time.READING,
|
||||||
|
earned_time.ANKI,
|
||||||
|
)
|
||||||
|
|
||||||
def test_a_newly_registered_earner_is_picked_up(
|
def test_a_newly_registered_earner_is_picked_up(
|
||||||
self, monkeypatch: pytest.MonkeyPatch
|
self, monkeypatch: pytest.MonkeyPatch
|
||||||
@ -211,7 +215,7 @@ class TestCannotCheck:
|
|||||||
class TestFlatAnswers:
|
class TestFlatAnswers:
|
||||||
def test_every_flat_earner_answers_by_name(self, key: Path) -> None:
|
def test_every_flat_earner_answers_by_name(self, key: Path) -> None:
|
||||||
write_ledger(earned_time.LEETCODE, [credit(earned_time.LEETCODE)])
|
write_ledger(earned_time.LEETCODE, [credit(earned_time.LEETCODE)])
|
||||||
assert flat_answers() == {"leetcode": True, "reading": False}
|
assert flat_answers() == {"leetcode": True, "reading": False, "anki": False}
|
||||||
|
|
||||||
def test_an_unknown_answer_is_none_and_warned(
|
def test_an_unknown_answer_is_none_and_warned(
|
||||||
self,
|
self,
|
||||||
@ -221,14 +225,19 @@ class TestFlatAnswers:
|
|||||||
) -> None:
|
) -> None:
|
||||||
monkeypatch.setattr(_earned, "HMAC_KEY_FILE", tmp_path / "no.key")
|
monkeypatch.setattr(_earned, "HMAC_KEY_FILE", tmp_path / "no.key")
|
||||||
with caplog.at_level(logging.WARNING):
|
with caplog.at_level(logging.WARNING):
|
||||||
assert flat_answers() == {"leetcode": None, "reading": None}
|
assert flat_answers() == {"leetcode": None, "reading": None, "anki": None}
|
||||||
assert "LeetCode state could not be checked" in caplog.text
|
assert "LeetCode state could not be checked" in caplog.text
|
||||||
assert "reading state could not be checked" in caplog.text
|
assert "reading state could not be checked" in caplog.text
|
||||||
|
assert "Anki state could not be checked" in caplog.text
|
||||||
|
|
||||||
def test_a_no_is_not_warned(
|
def test_a_no_is_not_warned(
|
||||||
self, key: Path, caplog: pytest.LogCaptureFixture
|
self, key: Path, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
write_ledger(earned_time.LEETCODE, [])
|
write_ledger(earned_time.LEETCODE, [])
|
||||||
with caplog.at_level(logging.WARNING):
|
with caplog.at_level(logging.WARNING):
|
||||||
assert flat_answers() == {"leetcode": False, "reading": False}
|
assert flat_answers() == {
|
||||||
|
"leetcode": False,
|
||||||
|
"reading": False,
|
||||||
|
"anki": False,
|
||||||
|
}
|
||||||
assert "could not be checked" not in caplog.text
|
assert "could not be checked" not in caplog.text
|
||||||
|
|||||||
@ -36,6 +36,8 @@ if TYPE_CHECKING:
|
|||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from screen_locker._status_types import ShutdownProjection
|
||||||
|
|
||||||
|
|
||||||
def _mixin() -> MagicMock:
|
def _mixin() -> MagicMock:
|
||||||
mixin = MagicMock()
|
mixin = MagicMock()
|
||||||
@ -160,19 +162,26 @@ class TestRealLedgers:
|
|||||||
|
|
||||||
|
|
||||||
class TestProjectionFollowsTheCut:
|
class TestProjectionFollowsTheCut:
|
||||||
@pytest.mark.parametrize(
|
"""Every projected row is priced on its own date, not on today's base."""
|
||||||
("now", "expected"),
|
|
||||||
[
|
def _shutdown(self, tmp_path: Path, now: datetime) -> ShutdownProjection:
|
||||||
(datetime(2026, 9, 30, 12, 0, tzinfo=UTC), 20 * 60),
|
|
||||||
(datetime(2026, 10, 2, 12, 0, tzinfo=UTC), 19 * 60),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_rest_of_week_uses_the_base_for_that_day(
|
|
||||||
self, tmp_path: Path, now: datetime, expected: int
|
|
||||||
) -> None:
|
|
||||||
with patch(
|
with patch(
|
||||||
"screen_locker._status_data.has_workout_skip_today", return_value=False
|
"screen_locker._status_data.has_workout_skip_today", return_value=False
|
||||||
):
|
):
|
||||||
snap = gather_status(**_files(tmp_path), now=now)
|
return gather_status(**_files(tmp_path), now=now).shutdown
|
||||||
assert snap.shutdown.rest_of_week[0].minutes == expected
|
|
||||||
assert snap.shutdown.next_week_preview[0].minutes == expected
|
def test_the_reading_cut_lands_mid_week(self, tmp_path: Path) -> None:
|
||||||
|
"""Wed 2026-09-30 is the last 20:00 day; Thu 2026-10-01 is the first 19:00."""
|
||||||
|
shutdown = self._shutdown(tmp_path, datetime(2026, 9, 30, 12, 0, tzinfo=UTC))
|
||||||
|
assert [d.minutes for d in shutdown.rest_of_week] == [20 * 60] * 3 + [
|
||||||
|
19 * 60
|
||||||
|
] * 4
|
||||||
|
|
||||||
|
def test_next_week_preview_includes_a_cut_dated_after_today(
|
||||||
|
self, tmp_path: Path
|
||||||
|
) -> None:
|
||||||
|
"""On Mon 2026-10-05, Anki's cut from Tue already shows; next week has it."""
|
||||||
|
shutdown = self._shutdown(tmp_path, datetime(2026, 10, 5, 12, 0, tzinfo=UTC))
|
||||||
|
lowered = 19 * 60 - earned_time.ANKI.shutdown_minutes
|
||||||
|
assert [d.minutes for d in shutdown.rest_of_week] == [19 * 60] + [lowered] * 6
|
||||||
|
assert [d.minutes for d in shutdown.next_week_preview] == [lowered] * 7
|
||||||
|
|||||||
@ -61,8 +61,10 @@ class TestBaseHour:
|
|||||||
assert earned_time.READING.penalty_from == date(2026, 10, 1)
|
assert earned_time.READING.penalty_from == date(2026, 10, 1)
|
||||||
assert base_minutes(date(2026, 10, 1)) == 19 * 60
|
assert base_minutes(date(2026, 10, 1)) == 19 * 60
|
||||||
|
|
||||||
def test_long_after_the_cut_stays_nineteen(self) -> None:
|
def test_long_after_the_cut_stays_lowered(self) -> None:
|
||||||
assert base_minutes(date(2030, 1, 1)) == 19 * 60
|
"""No drift back to 20:00; Anki's cut (from 2026-10-06) holds too."""
|
||||||
|
later_cuts = earned_time.ANKI.shutdown_minutes
|
||||||
|
assert base_minutes(date(2030, 1, 1)) == 19 * 60 - later_cuts
|
||||||
|
|
||||||
def test_default_is_the_local_today(self) -> None:
|
def test_default_is_the_local_today(self) -> None:
|
||||||
assert base_minutes() == base_minutes(datetime.now().astimezone().date())
|
assert base_minutes() == base_minutes(datetime.now().astimezone().date())
|
||||||
@ -148,7 +150,7 @@ class TestResetIncludesReading:
|
|||||||
base = base_minutes()
|
base = base_minutes()
|
||||||
assert (
|
assert (
|
||||||
f"Daily base reset: {hhmm(base + 60)} (base {hhmm(base)} + 0h workout + "
|
f"Daily base reset: {hhmm(base + 60)} (base {hhmm(base)} + 0h workout + "
|
||||||
"0h LeetCode + 1h reading already earned today)."
|
"0h LeetCode + 1h reading + 0h Anki already earned today)."
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user