app: redesign the panel and add limit forecasts and daily week use (#6)

Redesign the stats panel after the developer's feedback on v1 and add
limit forecasts, daily week use and token-based estimates (D7, D8).

- Panel: a fixed header with range and provider controls, limit tiles
  with pace chips, meters and forecasts, week use per day, token KPIs
  and charts, one burn-up chart per limit window with past instances,
  and a sortable breakdown whose "Other" row expands. One tooltip
  component for every chart, tile and table.
- Core (D7): average and recent-rate forecasts, the reach date whenever
  use is over pace, days of a long window with even pace and daily
  budget, window instances derived from resets with a 15-minute
  tolerance, and estimates from price-weighted tokens where samples are
  missing. Forecasts start at 10 % of a window, or as soon as it is
  ahead, so a Codex week far ahead right after its reset warns too.
- Settings, popups and the version (1.1.0) follow the new design.

Closes #5
Closes #7
This commit was merged in pull request #6.
This commit is contained in:
2026-10-15 19:06:04 +02:00
parent f8afd11679
commit adb8f5b88d
31 changed files with 2461 additions and 246 deletions
+14 -1
View File
@@ -2,6 +2,19 @@ namespace FinalToken.Core;
public static class Pace
{
// D7: use ticks at the boundary so exactly 10% is eligible despite floating-point rounding.
public static DateTimeOffset? ForecastStartsAt(LimitWindow window) =>
window.Length is { Ticks: > 0 } length && window.ResetsAt is { } reset
? reset - TimeSpan.FromTicks(length.Ticks - length.Ticks / 10) : null;
public static bool CanForecast(LimitWindow window, DateTimeOffset now, double threshold = 10) =>
CanForecast(window, now, Calculate(window, now, threshold));
// Reuse the configured pace, so every forecast agrees with the chip's Ahead state.
public static bool CanForecast(LimitWindow window, DateTimeOffset now, PaceResult pace) =>
pace.State != PaceState.Unknown && pace.ElapsedFraction is > 0 &&
ForecastStartsAt(window) is { } start && (now >= start || pace.State == PaceState.Ahead);
// D7. A reset in the past clamps elapsed to one; it never has a future projection.
public static PaceResult Calculate(LimitWindow window, DateTimeOffset now, double threshold = 10)
{
@@ -14,7 +27,7 @@ public static class Pace
var state = delta >= threshold ? PaceState.Ahead :
delta <= -threshold && elapsed >= 0.5 ? PaceState.Behind : PaceState.OnTrack;
DateTimeOffset? projection = null;
if (state == PaceState.Ahead && window.UsedPercent > 0 && elapsed > 0)
if (delta > 0 && window.UsedPercent > 0 && CanForecast(window, now, new PaceResult(state, elapsed, delta)))
{
var seconds = (100 - window.UsedPercent) * elapsed * length.TotalSeconds / window.UsedPercent;
if (seconds >= 0 && seconds < (reset - now).TotalSeconds) projection = now.AddSeconds(seconds);