earned_time 0.2.0: register the anki earner (30/30, penalty from 2026-10-06)
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
earned_time pre-commit / pre-commit (push) Waiting to run
earned_time tests / test (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-10-05 13:51:44 +02:00
parent ac1aae4f7a
commit 957b4df642
6 changed files with 59 additions and 18 deletions

View File

@ -25,7 +25,7 @@ fact — HMAC-signed `credit` rows in its ledger — and is registered here once
label="Anki",
gaming_minutes=30,
shutdown_minutes=30,
penalty_from=date(2026, 10, 10), # base drops by the same 30/30 from then on
penalty_from=date(2026, 10, 6), # base drops by the same 30/30 from then on
ledger=".local/share/anki_guard/ledger.json",
match=_anki_match, # which verified credit rows count today
missing_ledger_is_no=True,

View File

@ -30,6 +30,7 @@ from __future__ import annotations
from earned_time._ledger import done_today, entry_signature, today_window, verified
from earned_time._policy import (
ANKI,
EARNERS,
GAMING_BASE_MINUTES,
GAMING_CEILING_MINUTES,
@ -44,6 +45,7 @@ from earned_time._policy import (
from earned_time._resolve import Base, Resolution, Term, base_for, resolve
__all__ = [
"ANKI",
"EARNERS",
"GAMING_BASE_MINUTES",
"GAMING_CEILING_MINUTES",

View File

@ -136,6 +136,17 @@ def _reading_match(row: dict[str, object], window: Window) -> bool:
return landed
def _anki_match(row: dict[str, object], window: Window) -> bool:
"""An Anki credit counts on its Anki day (``detail.anki_day``).
anki-guard writes one row per Anki day, keyed on the collection's own day
boundary, so the day it names is the day it pays -- no stamp to parse.
"""
detail = row.get("detail")
local = datetime.fromtimestamp(window[0], tz=UTC).astimezone().date()
return isinstance(detail, dict) and detail.get("anki_day") == local.isoformat()
WORKOUT: Final = Earner(
name="workout",
label="workout",
@ -162,9 +173,19 @@ READING: Final = Earner(
match=_reading_match,
missing_ledger_is_no=True,
)
ANKI: Final = Earner(
name="anki",
label="Anki",
gaming_minutes=30,
shutdown_minutes=30,
penalty_from=date(2026, 10, 6),
ledger=".local/share/anki_guard/ledger.json",
match=_anki_match,
missing_ledger_is_no=True,
)
# Order is the order of reason strings and of screen-locker's live pass.
EARNERS: Final[tuple[Earner, ...]] = (WORKOUT, LEETCODE, READING)
EARNERS: Final[tuple[Earner, ...]] = (WORKOUT, LEETCODE, READING, ANKI)
def earner(name: str, earners: tuple[Earner, ...] = EARNERS) -> Earner:

View File

@ -9,7 +9,7 @@ from typing import TYPE_CHECKING
import pytest
from earned_time import EARNERS, LEETCODE, READING, WORKOUT, earner
from earned_time import ANKI, EARNERS, LEETCODE, READING, WORKOUT, earner
from earned_time._ledger import today_window
if TYPE_CHECKING:
@ -23,7 +23,7 @@ TODAY = datetime.fromtimestamp(WINDOW[0]).astimezone().date().isoformat()
def test_registry_order_and_names() -> None:
assert [e.name for e in EARNERS] == ["workout", "leetcode", "reading"]
assert [e.name for e in EARNERS] == ["workout", "leetcode", "reading", "anki"]
def test_lookup_by_name() -> None:
@ -97,3 +97,22 @@ def test_reading_unusable_end_is_logged(caplog: pytest.LogCaptureFixture) -> Non
with caplog.at_level(logging.WARNING):
assert not _match(READING, {"detail": {"bonus": "1"}, "entry_id": "r"})
assert "no usable ended_at" in caplog.text
@pytest.mark.parametrize(
("detail", "expected"),
[
({"anki_day": TODAY}, True),
({"anki_day": "2026-10-03"}, False),
({}, False),
("not a dict", False),
],
)
def test_anki_match(detail: object, *, expected: bool) -> None:
assert _match(ANKI, {"detail": detail}) is expected
def test_anki_penalty_starts_the_day_after_it_shipped() -> None:
# Shipped 2026-10-05: that day is a pure bonus, never an unearnable cut.
assert not ANKI.penalised_on(date(2026, 10, 5))
assert ANKI.penalised_on(date(2026, 10, 6))

View File

@ -73,24 +73,23 @@ def test_term_lookup_unknown_raises() -> None:
def test_new_penalised_earner_keeps_the_best_case() -> None:
anki = Earner(
name="anki",
label="Anki",
# A hypothetical next earner on top of the real registry (reading and
# anki already penalised by 2026-10-11): 5h - 1h - 30m - 30m.
piano = Earner(
name="piano",
label="piano",
gaming_minutes=30,
shutdown_minutes=30,
penalty_from=date(2026, 10, 10),
)
from earned_time import EARNERS
earners = (*EARNERS, anki)
earners = (*EARNERS, piano)
later = date(2026, 10, 11)
assert base_for(later, earners).gaming_minutes == 210
assert base_for(later, earners).shutdown_minutes == 18 * 60 + 30
skipped = resolve(
{"workout": 0, "leetcode": 0, "reading": 0, "anki": 0}, later, earners
)
done = resolve(
{"workout": 0, "leetcode": 0, "reading": 0, "anki": 1}, later, earners
)
assert base_for(later, earners).gaming_minutes == 180
assert base_for(later, earners).shutdown_minutes == 18 * 60
others = {"workout": 0, "leetcode": 0, "reading": 0, "anki": 0}
skipped = resolve({**others, "piano": 0}, later, earners)
done = resolve({**others, "piano": 1}, later, earners)
assert done.gaming_minutes - skipped.gaming_minutes == 30
assert done.shutdown_minutes == 19 * 60
assert done.shutdown_minutes == 18 * 60 + 30

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "earned-time"
version = "0.1.0"
version = "0.2.0"
description = "Penalty-then-reward registry: what every gate app earns in gaming time and shutdown time"
requires-python = ">=3.14"
dependencies = []