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:
@@ -5,6 +5,7 @@ namespace FinalToken.Core;
|
||||
|
||||
public sealed record TokenBucket(Provider Provider, DateTimeOffset Hour, string? Model, string? Project, TokenCounts Counts);
|
||||
public sealed record TokenPoint(DateTimeOffset Time, TokenCounts Counts);
|
||||
public sealed record ModelTokenPoint(DateTimeOffset Time, string? Model, TokenCounts Counts);
|
||||
public sealed record TokenBreakdown(string? Name, TokenCounts Counts);
|
||||
public enum SeriesInterval { Hour, Day }
|
||||
|
||||
@@ -185,10 +186,10 @@ public sealed class HistoryStore
|
||||
if (GetPartition(later).NextLimit(window) is { } found) { chronologicalNext = found; break; }
|
||||
}
|
||||
if (chronologicalPrevious is not null && window.UsedPercent == chronologicalPrevious.UsedPercent &&
|
||||
window.ResetsAt == chronologicalPrevious.ResetsAt &&
|
||||
LimitAnalysis.SameInstance(window, chronologicalPrevious) &&
|
||||
window.SampleTime - chronologicalPrevious.SampleTime < TimeSpan.FromHours(1)) continue;
|
||||
if (chronologicalNext is not null && window.UsedPercent == chronologicalNext.UsedPercent &&
|
||||
window.ResetsAt == chronologicalNext.ResetsAt &&
|
||||
LimitAnalysis.SameInstance(window, chronologicalNext) &&
|
||||
chronologicalNext.SampleTime - window.SampleTime < TimeSpan.FromHours(1)) continue;
|
||||
if (previous is null || window.SampleTime >= previous.SampleTime)
|
||||
state.LastSamples[key] = pending.LastSamples[key] = window;
|
||||
@@ -198,6 +199,7 @@ public sealed class HistoryStore
|
||||
foreach (var provider in changedSets) pending.LatestWindows[provider] = state.LatestWindows[provider];
|
||||
}
|
||||
}
|
||||
// D5: retain exact probe metadata; D7 tolerance applies only to instance identity and sampling.
|
||||
private static (string, string, double, DateTimeOffset?, TimeSpan?, string) WindowValue(LimitWindow window) =>
|
||||
(window.Id, window.Label, window.UsedPercent, window.ResetsAt, window.Length, window.Source);
|
||||
public IReadOnlyList<LimitWindow> LatestLimits(Provider provider)
|
||||
@@ -227,6 +229,14 @@ public sealed class HistoryStore
|
||||
}
|
||||
}
|
||||
public IReadOnlyList<TokenBreakdown> ByModel(Provider provider, DateTimeOffset from, DateTimeOffset to) => Breakdown(provider, from, to, true);
|
||||
public IReadOnlyList<ModelTokenPoint> TokenSeriesByModel(Provider provider, DateTimeOffset from, DateTimeOffset to,
|
||||
SeriesInterval interval, TimeZoneInfo? zone = null)
|
||||
{
|
||||
lock (gate) return Range(provider, from, to)
|
||||
.GroupBy(b => (Time: interval == SeriesInterval.Hour ? b.Hour : CalendarDays.Start(b.Hour, zone), b.Model))
|
||||
.OrderBy(g => g.Key.Time).ThenBy(g => g.Key.Model, StringComparer.Ordinal)
|
||||
.Select(g => new ModelTokenPoint(g.Key.Time, g.Key.Model, Sum(g.Select(b => b.Counts)))).ToArray();
|
||||
}
|
||||
public IReadOnlyList<TokenBreakdown> ByProject(Provider provider, DateTimeOffset from, DateTimeOffset to) => Breakdown(provider, from, to, false);
|
||||
private IReadOnlyList<TokenBreakdown> Breakdown(Provider provider, DateTimeOffset from, DateTimeOffset to, bool model)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user