steam-backlog-enforcer/steam_backlog_enforcer/_shadow_view.py
Krzysztof kuhy Rudnicki 7721b8716e Group playtime shadow and budget breakdown fields
PlaytimeState keeps its shadow_* keys on disk through a ShadowLedger
group (flat, prefix shadow_); PlaytimeRules carries the per-earner split
in a BudgetBreakdown. The golden round-trip test still passes.

Todo: 9b9342ba

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 08:36:21 +01:00

34 lines
1.1 KiB
Python

"""The shadow leisure block (contract C4) for ``/api/budget`` and MCP.
Read-only and display-only: what the leisure budget *would* say, beside the
enforced gaming numbers it never changes.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from steam_backlog_enforcer._playtime_state import PlaytimeState
def shadow_view(state: PlaytimeState) -> dict[str, Any]:
"""Compose the shadow block from stored state.
Args:
state: Loaded accounting state.
Returns:
Used/budget/remaining seconds, whether the leisure budget would block
now, paused seconds, and the per-source split.
"""
remaining = max(0.0, state.shadow.budget_seconds - state.shadow.seconds)
return {
"seconds_used": round(state.shadow.seconds, 1),
"budget_seconds": state.shadow.budget_seconds,
"seconds_remaining": round(remaining, 1),
"would_block": remaining <= 0.0,
"paused_seconds": round(state.shadow.paused_seconds, 1),
"per_source": {k: round(v, 1) for k, v in state.shadow.per_source.items()},
}