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:
@@ -0,0 +1,81 @@
|
||||
using Xunit;
|
||||
|
||||
namespace FinalToken.Core.Tests;
|
||||
|
||||
public class EarlyForecastTests
|
||||
{
|
||||
private static readonly DateTimeOffset Now = new(2026, 10, 15, 16, 45, 0, TimeSpan.Zero);
|
||||
private static LimitWindow Week(double used = 39) => new(Provider.Codex, "primary", "Week", used,
|
||||
new(2026, 10, 22, 6, 18, 0, TimeSpan.Zero), TimeSpan.FromDays(7), Now, "fixture");
|
||||
|
||||
[Fact] public void AheadCodexWeekProjectsBeforeTenPercent()
|
||||
{
|
||||
var window = Week(); var pace = Pace.Calculate(window, Now);
|
||||
Assert.Equal(PaceState.Ahead, pace.State);
|
||||
Assert.InRange(pace.ElapsedFraction!.Value, .061, .063);
|
||||
Assert.NotNull(pace.Projection);
|
||||
Assert.InRange(pace.Projection.Value, Now, window.ResetsAt!.Value);
|
||||
}
|
||||
|
||||
[Fact] public void AheadCodexWeekHasAverageForecast() => Assert.NotNull(LimitAnalysis.AverageUseAtReset(Week(), Now));
|
||||
|
||||
[Fact] public void AheadCodexWeekHasRecentForecast()
|
||||
{
|
||||
var window = Week();
|
||||
var recent = LimitAnalysis.Recent(window, [window with { SampleTime = Now.AddHours(-4), UsedPercent = 20 }], Now);
|
||||
Assert.NotNull(recent); Assert.NotNull(recent.ReachesLimit);
|
||||
Assert.Equal(TimeSpan.FromHours(4), recent.Span);
|
||||
}
|
||||
|
||||
[Fact] public void AheadCodexPopupIncludesProjection()
|
||||
{
|
||||
var window = Week();
|
||||
var popup = new PopupDecider().Observe(window, Pace.Calculate(window, Now), new Settings());
|
||||
Assert.NotNull(popup); Assert.NotNull(popup.Projection);
|
||||
}
|
||||
|
||||
[Fact] public void OnePercentOneHourIntoWeekDoesNotForecast()
|
||||
{
|
||||
var window = Week(1) with { ResetsAt = Now.AddDays(7).AddHours(-1) };
|
||||
Assert.Equal(PaceState.OnTrack, Pace.Calculate(window, Now).State);
|
||||
Assert.Null(Pace.Calculate(window, Now).Projection);
|
||||
Assert.Null(LimitAnalysis.AverageUseAtReset(window, Now));
|
||||
Assert.Null(LimitAnalysis.Recent(window, [], Now));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(10, true)]
|
||||
[InlineData(40, false)]
|
||||
public void AllForecastsFollowConfiguredThreshold(double threshold, bool eligible)
|
||||
{
|
||||
var window = Week(); var pace = Pace.Calculate(window, Now, threshold);
|
||||
Assert.Equal(eligible, pace.State == PaceState.Ahead);
|
||||
Assert.Equal(eligible, Pace.CanForecast(window, Now, threshold));
|
||||
Assert.Equal(eligible, pace.Projection is not null);
|
||||
Assert.Equal(eligible, LimitAnalysis.AverageUseAtReset(window, Now, pace) is not null);
|
||||
Assert.Equal(eligible, LimitAnalysis.Recent(window,
|
||||
[window with { SampleTime = Now.AddHours(-4), UsedPercent = 20 }], Now, pace) is not null);
|
||||
}
|
||||
|
||||
[Fact] public void ExactlyAheadThresholdEnablesEarlyForecasts()
|
||||
{
|
||||
var window = Week(); var threshold = Pace.Calculate(window, Now).Delta!.Value;
|
||||
var pace = Pace.Calculate(window, Now, threshold);
|
||||
Assert.Equal(PaceState.Ahead, pace.State);
|
||||
Assert.NotNull(pace.Projection);
|
||||
Assert.NotNull(LimitAnalysis.AverageUseAtReset(window, Now, pace));
|
||||
Assert.NotNull(LimitAnalysis.Recent(window, [window with { SampleTime = Now.AddHours(-4), UsedPercent = 20 }], Now, pace));
|
||||
}
|
||||
|
||||
[Fact] public void ForecastStartIsTenPercentIntoWindow()
|
||||
{
|
||||
var window = Week(1);
|
||||
Assert.Equal(window.ResetsAt - TimeSpan.FromDays(6.3), Pace.ForecastStartsAt(window));
|
||||
Assert.Null(Pace.ForecastStartsAt(window with { Length = null }));
|
||||
Assert.Null(Pace.ForecastStartsAt(window with { ResetsAt = null }));
|
||||
Assert.Null(Pace.ForecastStartsAt(window with { Length = TimeSpan.Zero }));
|
||||
var start = Pace.ForecastStartsAt(window)!.Value;
|
||||
Assert.False(Pace.CanForecast(window, start.AddTicks(-1), 40));
|
||||
Assert.True(Pace.CanForecast(window, start, 40));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user