Files
gabrielvidalandClaude Opus 5.5 8d1a46de83 feat(usage): a week target on the home week gauge, and a push when behind
The personal Max is meant to be maxed out every week. Its account declares
`weekTarget: {goal: 100, behindAlert: 20}`: a straight line from 0 % when the
week opens to 100 % at its reset (usage/target.py, mirrored by
lib/weekTarget.ts).

- /api/usage/limits carries the account's `weekTarget`.
- The home usage strip's week gauge gets a tick at the target (ArcGauge
  `target`) and a "target N%" line under the reset countdown, re-read
  every minute.
- The poller pushes "🎯 Personal week behind its target" once each time the
  week falls more than 20 points under the line (crossing between two
  stored points, so a restart never re-pushes; catching up re-arms it),
  with how many nonstop Opus runs would use the rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 19:11:25 +01:00

43 lines
1.6 KiB
Python

"""The week target: how much of a weekly window should be used by now to
reach its goal at the reset.
An account that declares ``weekTarget`` (``accounts.ACCOUNTS`` — the
personal Max: ``{"goal": 100, "behindAlert": 20}``) wants its week maxed
out. The target is a straight line, 0 % when the window opens (7 days
before its ``resets_at``) to ``goal`` % at the reset; the home page's week
gauge draws it as a tick (``frontend/src/lib/weekTarget.ts`` mirrors
``linear``), and the poller pushes once each time the week falls more than
``behindAlert`` points under it (``UsagePoller._check_behind`` →
``service.behind_alert``).
"""
from __future__ import annotations
WEEK_S = 7 * 86400
def linear(resets_at, t: float, goal: float = 100.0, span: float = WEEK_S) -> float | None:
"""The % the window should be at by ``t``, or None when there's no
current window (no reset time, or it already passed)."""
try:
end = float(resets_at)
except (TypeError, ValueError):
return None
if not end or t >= end:
return None
frac = (t - (end - span)) / span
return goal * min(1.0, max(0.0, frac))
def gap(pct: float, resets_at, t: float, goal: float = 100.0) -> float | None:
"""Points the window is under its target at ``t`` (negative = ahead)."""
tgt = linear(resets_at, t, goal)
return None if tgt is None else tgt - pct
def of(account: str) -> dict | None:
"""The account's ``weekTarget`` declaration, or None."""
import accounts as accounts_mod
wt = (accounts_mod.get(account) or {}).get("weekTarget")
return wt if isinstance(wt, dict) and wt.get("goal") else None