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:
@@ -99,6 +99,17 @@ public sealed class LimitInstanceTests
|
||||
AssertNoOverlap(result);
|
||||
}
|
||||
|
||||
[Fact] public void AdjacentInferredWeeksAssignTheBoundaryHourOnlyToTheStartingWeek()
|
||||
{
|
||||
var start = Day.AddMinutes(13);
|
||||
var current = Window(start, TimeSpan.FromDays(7), start.AddHours(2), 20);
|
||||
var result = Analyze(current, [], [Token(Day, 100), Token(Day.AddDays(-7), 100)], current.SampleTime);
|
||||
var past = Assert.Single(result.Past);
|
||||
Assert.Equal(start.AddDays(-7), past.Start); Assert.Equal(20, past.Peak);
|
||||
Assert.DoesNotContain(result.Past, p => p.Start == start.AddDays(-14));
|
||||
AssertNoOverlap(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5)]
|
||||
[InlineData(24)]
|
||||
|
||||
@@ -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)" };
|
||||
|
||||
Reference in New Issue
Block a user