mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-10 19:27:04 +01:00
A Sunday ran past the 6.0h the i3 bar showed: 2h47m of Saturday's leftover was carried into the budget the cutoff used, and the 3-second "Gaming budget" journal line omitted it. Unspent time is now dropped at 06:00 every day; load_state takes a legacy ledger's share back out of today's high-water mark. The budget line logs only on change (was 25k lines/day), fired warnings are logged, and budget.jsonl records carry budget_seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015PrwCnQouKTF4EUMENMxnG
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""Read-side compatibility for the removed Friday-Monday carry-over.
|
|
|
|
Exists only to read ``playtime_state.json`` records written before carry-over
|
|
was removed on 2026-10-18. Such a record lives at most one gaming day (the
|
|
next ``save_state`` drops the ``carry`` key), so this module can be deleted
|
|
once no such record can remain.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import replace
|
|
import logging
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
# Type-only: _playtime_state imports this module at runtime.
|
|
from steam_backlog_enforcer._playtime_state import PlaytimeState
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def without_legacy_carry(state: PlaytimeState, carry: object) -> PlaytimeState:
|
|
"""Take a removed carry ledger's share for the day out of its high-water.
|
|
|
|
Records written before 2026-10-18 folded the Friday-Monday carry into
|
|
``budget_seconds``, and ``held_today`` would keep paying it out for the
|
|
rest of that day. The key itself is dropped by the next ``save_state``.
|
|
|
|
Args:
|
|
state: The record as loaded.
|
|
carry: The raw ``carry`` value from the file, if any.
|
|
|
|
Returns:
|
|
*state*, its ``budget_seconds`` lowered by the day's carried share.
|
|
"""
|
|
if not isinstance(carry, dict):
|
|
return state
|
|
share = carry.get(state.day_key, 0.0)
|
|
if not isinstance(share, int | float) or share <= 0:
|
|
return state
|
|
logger.warning(
|
|
"Dropping %.0fs of legacy carry-over from %s's budget.", share, state.day_key
|
|
)
|
|
return replace(state, budget_seconds=max(0.0, state.budget_seconds - share))
|