core: give a boundary hour to the next instance, real or inferred

TokenEnd only saw the real spans, so an instance kept the boundary hour
that its inferred successor also counted. Two adjacent inferred weeks then
both showed the same tokens, which made false past peaks (D7).

One backward walk now yields every instance with the start of the instance
that follows it. Analyze takes its first eight past instances from it and
the reset history uses it for its real instances, so the window charts and
the reset list agree. An instance that resets before a gap keeps its end
hour, as before.

Refs #14
This commit is contained in:
Florian Schmidt
2026-10-18 11:04:57 +02:00
parent 1723c21bd5
commit 5da543eba8
5 changed files with 79 additions and 20 deletions
@@ -141,6 +141,40 @@ public sealed class ResetHistoryTests
Assert.Equal(old.SampleTime, measured.ReachedLimit); Assert.Equal(UseOrigin.Measured, measured.BurnUp.ReachedOrigin);
}
[Theory]
[InlineData(0, false)]
[InlineData(20, false)]
[InlineData(50, true)]
public void RealWeekKeepsItsEndHourOnlyWhenTheInferredSuccessorStartsInALaterHour(int gapMinutes, bool ownsEndHour)
{
var start = Day.AddMinutes(13);
var previous = Window(start);
var currentStart = start + Week * 2 + TimeSpan.FromMinutes(gapMinutes);
var current = Window(currentStart, 20, 2);
ModelTokenPoint[] tokens = [Token(Day, 100), Token(Day + Week, 50), Token(currentStart.AddMinutes(-currentStart.Minute), 100)];
var analysis = LimitAnalysis.Analyze(current, [previous], tokens, current.SampleTime, TimeZoneInfo.Utc)!;
var past = Assert.Single(analysis.Past, p => p.Start == start);
Assert.Equal(ownsEndHour ? 75 : 50, past.Points[^1].Used);
var history = History(current, [previous], tokens);
var row = Assert.Single(history.Instances, r => r.Start == start);
Assert.Equal(past.Points, row.BurnUp.Points);
Assert.Equal(ownsEndHour ? 150 : 100, row.Tokens.Total);
Assert.Equal(row.Tokens, Assert.Single(row.Models).Tokens);
Assert.Equal(previous.ResetsAt, row.End); Assert.False(row.Early);
Assert.Equal(2, history.Instances.Count);
}
[Fact] public void ResetHistoryUsesInferredSuccessorsBeyondTheEightPastChartInstances()
{
var start = Day.AddMinutes(13);
var previous = Window(start);
var current = Window(start + Week * 11, 20, 2);
ModelTokenPoint[] tokens = [Token(Day, 100), Token(Day + Week, 50), Token(Day + Week * 11, 100)];
var row = Assert.Single(History(current, [previous], tokens).Instances, r => r.Start == start);
Assert.Equal(100, row.Tokens.Total); Assert.Equal(50, row.Final.Used);
Assert.Equal(2, History(current, [previous], tokens).Instances.Count);
}
[Fact] public void FamilyFilterAndUnpricedModelsAreExplicit()
{
var current = Window(Day, 20) with { Provider = Provider.Claude, Id = "fable", Label = "Week (Fable)" };