mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-21 19:52:19 +01:00
The budget tab answered "how much did I play" but not "what did I play":
playtime_state.json and playtime_history.json each stored one aggregate
seconds figure per gaming day, so the 14-day chart was a row of featureless
bars. Separately, qualifying_pids had exactly two sources — the SteamAppId
env var and a hardcoded 16-launcher frozenset — so osu!lazer, which sets no
SteamAppId and matches no launcher name, was never billed at all.
qualifying_pids now returns pid -> attribution key instead of a bare pid set.
The app id was already in hand and thrown away on its first line; it now
survives into PlaytimeState.per_game, alongside a user-editable
counted_processes list in config.json seeded with osu!lazer.
Two things the parts/whole relationship forces:
- per_game only ever sums to AT MOST seconds, never equals it. backdate
refunds the idle grace on every engaged-to-paused edge, and
_state_or_recover synthesises a full budget with no breakdown. The
refund is debited from last_credited_key, and the remainder is rendered
as "Unattributed" rather than stored — one path then covers legacy days,
focus-probe failures and drift alike.
- counted_processes is kept apart from LAUNCHER_PROCESS_NAMES. That
frozenset is also the total-block kill list, and it routes through
kill_and_uninstall_launchers, which pacman -R's the owning package.
Counted entries are killed on total block, never uninstalled.
Both storage formats stay at schema 1: load_state already filters to
dataclass fields, so a record without per_game migrates for free, and the
history reader has to accept both a bare float and an object regardless, so
a version bump would distinguish nothing.
Chart segments use the shared design system's categorical ramp (--cat-1..6),
capped at six games plus "Other" because a seventh distinguishable hue does
not exist under simulated CVD. The red over-budget fill is gone: colour now
encodes which game, and the dashed budget line alone says over or under.
Snapshot persistence moves to _snapshot.py to keep config.py under the
250-line cap. Three modules bound config paths at import time, which
bypasses the conftest redirect — they now reach them through the module.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKFzwzwRU1JD7SFLHtQBsz
176 lines
3.9 KiB
TypeScript
176 lines
3.9 KiB
TypeScript
// Shared test factories. Lives under src/test/ which is excluded from the
|
|
// app build and from coverage.
|
|
|
|
import type {
|
|
BudgetRules,
|
|
BudgetSession,
|
|
BudgetSnapshot,
|
|
BudgetToday,
|
|
Filters,
|
|
PaceVsHLTB,
|
|
WebDataset,
|
|
WebGame,
|
|
WebStateInfo,
|
|
} from '../types'
|
|
|
|
export function makeGame(over: Partial<WebGame> = {}): WebGame {
|
|
return {
|
|
app_id: 1,
|
|
name: 'Game',
|
|
completion_pct: 0,
|
|
playtime_minutes: 60,
|
|
rush_hours: 10,
|
|
leisure_hours: 20,
|
|
worst_hours: 25,
|
|
count_comp: 20,
|
|
comp_100_count: 5,
|
|
hltb_game_id: 0,
|
|
protondb_tier: 'gold',
|
|
protondb_trending_tier: 'gold',
|
|
protondb_score: 0.8,
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeFilters(over: Partial<Filters> = {}): Filters {
|
|
return {
|
|
minCountComp: 15,
|
|
minComp100: 3,
|
|
minConfidenceSum: 18,
|
|
protonMode: 'playable',
|
|
protonMinTier: 'gold',
|
|
protonTreatMissingAsPass: true,
|
|
dailyHours: 4,
|
|
basis: 'leisure',
|
|
maxHoursPerGame: 0,
|
|
playtimeMode: 'all',
|
|
includeNoData: false,
|
|
fallbackHours: 20,
|
|
excluded: new Set<number>(),
|
|
search: '',
|
|
targetDate: '',
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeState(over: Partial<WebStateInfo> = {}): WebStateInfo {
|
|
return {
|
|
current_app_id: null,
|
|
current_game_name: '',
|
|
games_done: 0,
|
|
days_elapsed: 0,
|
|
enforcement_started_at: '',
|
|
pace_games_per_day: 0,
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makePaceVsHltb(over: Partial<PaceVsHLTB> = {}): PaceVsHLTB {
|
|
return {
|
|
calibration_count: 10,
|
|
ratio_vs_rush: 1.05,
|
|
ratio_vs_leisure: 0.4,
|
|
interpolation_t: 0.05,
|
|
player_style: 'rush_to_leisure',
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeDataset(
|
|
games: WebGame[] = [makeGame()],
|
|
over: Partial<WebDataset> = {},
|
|
): WebDataset {
|
|
return {
|
|
games,
|
|
state: makeState(),
|
|
defaults: {
|
|
min_comp_100_polls: 3,
|
|
min_count_comp: 15,
|
|
min_confidence_sum: 18,
|
|
min_playable_tier: 'gold',
|
|
hours_per_day_presets: [2, 4, 6, 8],
|
|
},
|
|
default_summary: {
|
|
qualifying: games.length,
|
|
rush_total: 0,
|
|
leisure_total: 0,
|
|
worst_total: 0,
|
|
},
|
|
pace_vs_hltb: null,
|
|
generated_at: '2026-05-29T00:00:00+00:00',
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeBudgetToday(over: Partial<BudgetToday> = {}): BudgetToday {
|
|
return {
|
|
gaming_day: '2026-08-28',
|
|
day_starts_at: '06:00 local',
|
|
seconds_used: 3600,
|
|
budget_seconds: 28800,
|
|
seconds_remaining: 25200,
|
|
fraction_used: 0.125,
|
|
blocked: false,
|
|
blocked_at: 0,
|
|
next_warning_seconds: 3600,
|
|
warned_seconds: [],
|
|
games: [
|
|
{ key: 'app:367520', label: 'Hollow Knight', seconds: 3600, fraction: 1 },
|
|
],
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeBudgetSession(over: Partial<BudgetSession> = {}): BudgetSession {
|
|
return {
|
|
available: true,
|
|
observed_at: new Date().toISOString(),
|
|
state: 'engaged',
|
|
reason: 'engaged',
|
|
causes: [],
|
|
idle_seconds: 2,
|
|
screen_held: false,
|
|
game_name: 'Hollow Knight',
|
|
billing_label: 'Hollow Knight',
|
|
qualifying_count: 3,
|
|
processes: [{ pid: 42, name: 'hollow_knight' }],
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeBudgetRules(over: Partial<BudgetRules> = {}): BudgetRules {
|
|
return {
|
|
budget_seconds: 28800,
|
|
enforcement: true,
|
|
counts_launchers: true,
|
|
engagement_gate: true,
|
|
idle_grace_seconds: 300,
|
|
require_game_focus: true,
|
|
warn_at: [3600, 1800, 600, 300],
|
|
demo: false,
|
|
masked_launchers: [],
|
|
...over,
|
|
}
|
|
}
|
|
|
|
export function makeBudget(over: Partial<BudgetSnapshot> = {}): BudgetSnapshot {
|
|
return {
|
|
ok: true,
|
|
readable: true,
|
|
state_status: 'ok',
|
|
error: null,
|
|
today: makeBudgetToday(),
|
|
session: makeBudgetSession(),
|
|
history: [
|
|
{
|
|
day: '2026-08-28',
|
|
seconds: 3600,
|
|
segments: [{ key: 'app:367520', seconds: 3600 }],
|
|
},
|
|
],
|
|
legend: [{ key: 'app:367520', label: 'Hollow Knight' }],
|
|
rules: makeBudgetRules(),
|
|
...over,
|
|
}
|
|
}
|