steam-backlog-enforcer/web/src/format.ts
Krzysztof kuhy Rudnicki 41deb90324 feat: add interactive web UI for backlog completion planning
Adds a React/TypeScript frontend (web/) with a Python stdlib HTTP server
backend.  The UI mirrors the CLI `stats` command in the browser, with
real-time sliders for ProtonDB rating, HLTB confidence thresholds, daily
play time, per-game time cap, playtime mode, no-HLTB-data fallback, and a
target-date planner.  A parity badge confirms the client-side totals
reproduce the CLI defaults exactly (786 / 67031.1h / 143017.2h / 238447.9h).

Python side:
- `_web_dataset.py`: offline projection of HLTB/ProtonDB/snapshot caches
  into a compact, secret-free JSON payload; 100% branch coverage
- `_web_server.py`: zero-dependency stdlib HTTP server serving the built
  Vite bundle and the /api/dataset endpoint; 100% branch coverage
- `main.py`: new `serve` command wiring

Frontend (Vitest + RTL, 100% branch coverage enforced):
- TypeScript port of ProtonDB compound rating rule with full parity
- Pure client-side filtering via estimate.ts (no server round-trips)
- SVG completion timeline chart, sortable/searchable game table
- Steam dark theme; responsive layout

Pre-commit: adds `vitest-coverage` hook at pre-push stage requiring 100%
branch coverage on the React codebase.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 18:35:45 +02:00

45 lines
1.6 KiB
TypeScript

// Small display-formatting helpers shared across components.
/** Format an hour count with thousands separators, e.g. 67031.1 → "67,031 h". */
export function fmtHours(hours: number): string {
if (hours <= 0) return '—'
return `${Math.round(hours).toLocaleString('en-US')} h`
}
/** Format a possibly-missing per-game hour value, e.g. 44.3 → "44.3". */
export function fmtHoursPrecise(hours: number): string {
if (hours <= 0) return '—'
return hours.toFixed(1)
}
/** Format playtime minutes as hours, e.g. 320 → "5.3 h" (0 → "untouched"). */
export function fmtPlaytime(minutes: number): string {
if (minutes <= 0) return 'untouched'
return `${(minutes / 60).toFixed(1)} h`
}
/** Format a day count and its target date, e.g. (866) → "866 days · 2028-10-11". */
export function fmtEta(days: number | null): string {
if (days === null) return 'N/A'
const target = new Date()
target.setDate(target.getDate() + days)
return `${days.toLocaleString('en-US')} days · ${isoDate(target)}`
}
/** Render a Date as YYYY-MM-DD in local time. */
export function isoDate(date: Date): string {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const d = String(date.getDate()).padStart(2, '0')
return `${y}-${m}-${d}`
}
/** Whole days from today (local midnight) until the given ISO date string. */
export function daysUntil(isoDateStr: string): number {
const target = new Date(`${isoDateStr}T00:00:00`)
const today = new Date()
today.setHours(0, 0, 0, 0)
const ms = target.getTime() - today.getTime()
return Math.ceil(ms / (1000 * 60 * 60 * 24))
}