fix: keep real window instances across gaps and early resets (D7)
agent-review agent review: pass

The agent review of ab8d245 found that a gap between two instances,
normal for 5 h sessions, made the analysis infer a previous instance
up to the current start and drop the real one with its samples, and
that an early reset gave the old window tokens from before the new
window's first sample. Instance boundaries now come from resets; real
instances are kept with their own scale, gaps stay unassigned, and
inferred instances exist only for long windows without samples and
never overlap a real one. The dead top-8 breakdown builder is removed
and the day chart legend names the day-of-window pairing.

Refs #5
This commit is contained in:
Florian Schmidt
2026-10-15 09:59:27 +02:00
parent 15145f1cdc
commit 07a645657d
6 changed files with 152 additions and 40 deletions
+5 -4
View File
@@ -110,14 +110,14 @@ public sealed class ViewModelTests
}
[Fact] public void DesktopEntryQuotesExecutableAndEscapesFieldCodes()
{ var text = OsStartup.DesktopEntry("/opt/Final Token/100%/app"); Assert.Contains("Exec=\"/opt/Final Token/100%%/app\"", text); Assert.Contains("Terminal=false", text); }
[Fact] public void BreakdownKeepsTopEightAndOtherWithoutLosingCounts()
[Fact] public void BreakdownQueryReturnsEveryRowAndItsShareWithoutPrebuildingOther()
{
var now = new DateTimeOffset(2026, 10, 14, 12, 0, 0, TimeSpan.Zero);
var store = new HistoryStore(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")), new DiagnosticLog());
for (var i = 0; i < 110; i++) store.Add(new(Provider.Claude, now.AddHours(-1), "model", $"project-{i}", new(Total: i + 1), $"{i}"));
var view = PanelViewModel.QueryHistory(store, FakeData.Snapshot(now), HistoryRange.Days7, null, now);
Assert.Equal(9, view.Projects.Count); Assert.Equal("project-109", view.Projects[0].Name);
Assert.Equal("Other (102)", view.Projects[^1].Name); Assert.Equal(6105, view.Projects.Sum(r => r.Counts.Total));
Assert.Equal(110, view.Projects.Count); Assert.Equal("project-109", view.Projects[0].Name);
Assert.Equal("project-0", view.Projects[^1].Name); Assert.Equal(6105, view.Projects.Sum(r => r.Counts.Total));
Assert.Equal(1, view.Projects.Sum(r => r.Share), 8);
}
[Fact] public void FilteredModelSeriesUseSixAlphabeticSlotsAndOther()
@@ -203,8 +203,9 @@ internal static class FakeData
var w = ws.Window; var start = w.ResetsAt!.Value - w.Length!.Value;
for (var i = provider.Provider == Provider.Claude && w.Length > TimeSpan.FromDays(1) ? (int)(now - start).TotalHours - 24 : 0; i <= (int)(now - start).TotalHours; i += w.Length > TimeSpan.FromDays(1) ? 3 : 1)
store.AddLimits([w with { SampleTime = start.AddHours(i), UsedPercent = w.UsedPercent * i / (now - start).TotalHours }]);
var previousReset = start - (w.Length > TimeSpan.FromDays(1) ? TimeSpan.Zero : TimeSpan.FromHours(6));
for (var i = 0; i < (int)w.Length!.Value.TotalHours; i += w.Length > TimeSpan.FromDays(1) ? 6 : 1)
store.AddLimits([w with { ResetsAt = w.ResetsAt.Value - w.Length.Value, SampleTime = start - w.Length.Value + TimeSpan.FromHours(i), UsedPercent = 100.0 * i / w.Length.Value.TotalHours }]);
store.AddLimits([w with { ResetsAt = previousReset, SampleTime = previousReset - w.Length.Value + TimeSpan.FromHours(i), UsedPercent = 100.0 * i / w.Length.Value.TotalHours }]);
}
}
return new() { Snapshot = snapshot, Message = "Updated just now", History = PanelViewModel.QueryHistory(store, snapshot, HistoryRange.Days7, null, now) };