app: fix the Resets section after the real-data check
On the developer's data the section counted the running instance as a reset, showed zeros before anything finished, and drew the skipped time of five early resets over almost the whole timeline (D12). The Resets tile now counts finished instances and names the running one. Unused, Gift and the median say when nothing finished or reset early. Skipped time is a thin hatched bar below the plot, one lane per overlap, and the axis no longer runs on to the running instance's reset. Percent and limit values follow the user's culture, and figures in captions do not wrap. The reset tooltip is tall. Where it could not fit above or below the pointer it slid over it, took the hover from the chart and vanished. Tall tooltips now open beside the pointer and use the width DataTooltip asks for. Refs #14
This commit is contained in:
@@ -31,19 +31,80 @@ public sealed class ResetTests
|
||||
Assert.Equal(8, week.Analysis!.Past.Count);
|
||||
}
|
||||
|
||||
[Fact] public void MoneyAndLimitsStayInvariantOnAGermanDesktop()
|
||||
[Theory]
|
||||
[InlineData("de-DE", "≈ 4,5 limits", "≈ 94,1 %")]
|
||||
[InlineData("en-US", "≈ 4.5 limits", "≈ 94.1 %")]
|
||||
public void ResetFiguresFollowTheUsersCultureExceptUsd(string culture, string limits, string percent)
|
||||
{
|
||||
var previous = CultureInfo.CurrentCulture;
|
||||
try
|
||||
{
|
||||
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
|
||||
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);
|
||||
Assert.Equal("≈ $1,234", Display.Money(1234)); Assert.Equal("≈ $99.25", Display.Money(99.25m));
|
||||
Assert.Equal("Unpriced", Display.Money(null)); Assert.Equal("≈ 3.1 limits", Display.Limits(310));
|
||||
Assert.Equal("0 min", Display.ResetDuration(TimeSpan.Zero));
|
||||
Assert.Equal("Unpriced", Display.Money(null)); Assert.Equal(limits, Display.Limits(450));
|
||||
Assert.Equal(percent, Display.ResetPercent(94.1, UseOrigin.Estimated));
|
||||
Assert.Equal(percent[2..], Display.ResetPercent(94.1, UseOrigin.Measured));
|
||||
}
|
||||
finally { CultureInfo.CurrentCulture = previous; }
|
||||
}
|
||||
|
||||
[Fact] public void ResetDurationsCannotWrapInsideTheFigure()
|
||||
{
|
||||
Assert.Equal("0\u00a0min", Display.ResetDuration(TimeSpan.Zero));
|
||||
Assert.Equal("39\u00a0d\u00a00\u00a0h", Display.ResetDuration(TimeSpan.FromDays(39)));
|
||||
Assert.Equal("≈\u00a015,1\u00a0M\u00a0tokens", Display.ResetFigure("≈ 15,1 M tokens"));
|
||||
}
|
||||
|
||||
[Fact] public void OverlappingSkippedSpansGetSeparateLanesInTimeOrder()
|
||||
{
|
||||
var fixture = ResetFixture.Overlapping();
|
||||
var history = fixture.History.Resets[0];
|
||||
var layout = ResetTimeline.CalculateLayout(history, fixture.Now);
|
||||
Assert.Equal(5, history.Totals.Early);
|
||||
Assert.True(history.Instances.Max(r => r.Start) - history.Instances.Min(r => r.Start) < TimeSpan.FromDays(10));
|
||||
Assert.Equal(5, layout.LaneCount);
|
||||
Assert.Equal([0, 1, 2, 3, 4], layout.Skipped.Select(s => s.Lane));
|
||||
Assert.Equal(history.Instances.Where(r => r.Early).OrderBy(r => r.End), layout.Skipped.Select(s => s.Instance));
|
||||
}
|
||||
|
||||
[Fact] public void SkippedSpansReuseTheFirstLaneAsSoonAsItIsFree()
|
||||
{
|
||||
var fixture = ResetFixture.Create();
|
||||
var layout = ResetTimeline.CalculateLayout(fixture.History.Resets[0], fixture.Now);
|
||||
Assert.Equal(4, layout.LaneCount);
|
||||
Assert.Equal([0, 1, 0, 1, 2, 3, 0], layout.Skipped.Select(s => s.Lane));
|
||||
Assert.Equal(layout.Skipped[2].Instance.Reset, layout.Skipped[^1].Instance.End);
|
||||
foreach (var lane in layout.Skipped.GroupBy(s => s.Lane))
|
||||
{
|
||||
var rows = lane.Select(s => s.Instance).ToArray();
|
||||
for (var i = 1; i < rows.Length; i++) Assert.True(rows[i - 1].Reset <= rows[i].End);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact] public void TimelineEndsAtNowOrTheLastEarlyNominalResetAndExcludesTheRunningReset()
|
||||
{
|
||||
var running = ResetFixture.RunningOnly();
|
||||
var history = running.History.Resets[0];
|
||||
var layout = ResetTimeline.CalculateLayout(history, running.Now);
|
||||
Assert.Equal(history.Instances[0].Start, layout.From);
|
||||
Assert.Equal(running.Now, layout.To); Assert.Empty(layout.Skipped);
|
||||
Assert.True(layout.To < history.Instances[0].Reset);
|
||||
|
||||
var early = ResetFixture.Overlapping();
|
||||
history = early.History.Resets[0];
|
||||
layout = ResetTimeline.CalculateLayout(history, early.Now);
|
||||
Assert.Equal(history.Instances.Min(r => r.Start), layout.From);
|
||||
Assert.Equal(history.Instances.Where(r => r.Early).Max(r => r.Reset), layout.To);
|
||||
Assert.True(layout.To > early.Now); Assert.True(layout.To < history.Instances[0].Reset);
|
||||
var later = early.Now.AddDays(30);
|
||||
Assert.Equal(later, ResetTimeline.CalculateLayout(history, later).To);
|
||||
|
||||
var onTime = ResetFixture.OnTimeOnly();
|
||||
history = onTime.History.Resets[0];
|
||||
history = history with { Instances = history.Instances.Where(r => !r.Running).ToArray() };
|
||||
Assert.Equal(onTime.Now, ResetTimeline.CalculateLayout(history, onTime.Now).To);
|
||||
}
|
||||
|
||||
[Fact] public void EveryInstanceColumnSortsByItsUnderlyingValue()
|
||||
{
|
||||
var fixture = ResetFixture.Create();
|
||||
@@ -63,9 +124,13 @@ public sealed class ResetTests
|
||||
internal sealed record ResetFixture(HistoryStore Store, Snapshot Snapshot, DateTimeOffset Now, HistoryView History)
|
||||
{
|
||||
public static ResetFixture Create()
|
||||
=> Create([7, 1, 2, 7, 1, 2, 1, 1, 2]);
|
||||
public static ResetFixture RunningOnly() => Create([]);
|
||||
public static ResetFixture OnTimeOnly() => Create([7, 7]);
|
||||
public static ResetFixture Overlapping() => Create([1, 1, 1, 1, 1]);
|
||||
private static ResetFixture Create(int[] durations)
|
||||
{
|
||||
var start = new DateTimeOffset(2026, 9, 12, 6, 0, 0, TimeSpan.Zero);
|
||||
int[] durations = [7, 1, 2, 7, 1, 2, 1, 1, 2];
|
||||
var now = start.AddDays(durations.Sum()).AddHours(12);
|
||||
var store = new HistoryStore(Path.Combine(Path.GetTempPath(), "finaltoken-resets", Guid.NewGuid().ToString("N")), new(), new FixedClock(now));
|
||||
var currentStart = start; LimitWindow current = null!;
|
||||
|
||||
@@ -14,6 +14,7 @@ internal static class ResetViews
|
||||
{
|
||||
public static void Verify(Action<Window, string> save)
|
||||
{
|
||||
VerifyScenarios(save);
|
||||
var fixture = ResetFixture.Create();
|
||||
var clock = new FixedClock(fixture.Now);
|
||||
var model = new PanelViewModel { Snapshot = fixture.Snapshot, History = fixture.History, Range = HistoryRange.All };
|
||||
@@ -104,4 +105,74 @@ internal static class ResetViews
|
||||
Ui.Theme(window); window.Show(); save(window, $"resets-tooltip-{theme}.png"); window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void VerifyScenarios(Action<Window, string> save)
|
||||
{
|
||||
foreach (var (name, fixture) in new[] { ("running-only", ResetFixture.RunningOnly()),
|
||||
("on-time", ResetFixture.OnTimeOnly()), ("overlapping", ResetFixture.Overlapping()) })
|
||||
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
|
||||
{
|
||||
var history = fixture.History.Resets[0];
|
||||
var card = new ResetCard(history, new(ResetColumn.Start), new FixedClock(fixture.Now));
|
||||
var window = new Window { Width = 1280, Height = 950, RequestedThemeVariant = theme,
|
||||
Content = new Border { Padding = new Thickness(24), Child = Ui.Card(Ui.Stack(Ui.Text("Codex · Week", 15), card)) } };
|
||||
Ui.Theme(window); window.Show(); Dispatcher.UIThread.RunJobs();
|
||||
using (window.CaptureRenderedFrame()) { }
|
||||
save(window, $"resets-{name}-{theme}.png");
|
||||
TextBlock[] TileBlocks(string label) => card.GetVisualDescendants().OfType<StackPanel>()
|
||||
.Select(s => s.Children.OfType<TextBlock>().ToArray())
|
||||
.Single(blocks => blocks.Length == 3 && blocks[0].Text == label);
|
||||
string[] Tile(string label) => TileBlocks(label).Select(t => t.Text!).ToArray();
|
||||
Assert.Equal(history.Totals.Finished.ToString(), Tile("Resets")[1]);
|
||||
var caption = history.Totals.Finished == 0 ? "none yet" : history.Totals.Early + "\u00a0early";
|
||||
Assert.Equal(caption + " · 1\u00a0running", Tile("Resets")[2]);
|
||||
var texts = card.GetVisualDescendants().OfType<TextBlock>().Select(t => t.Text).ToArray();
|
||||
Assert.Contains("early resets " + history.Totals.Early + " of " + history.Totals.Finished,
|
||||
texts.Single(t => t?.StartsWith("Median instance ", StringComparison.Ordinal) == true || t?.StartsWith("No finished instance yet", StringComparison.Ordinal) == true));
|
||||
if (history.Totals.Finished == 0)
|
||||
{
|
||||
Assert.Equal(["Unused", "—", "no finished instance"], Tile("Unused"));
|
||||
Assert.Equal(Ui.Colour("Muted", theme == ThemeVariant.Dark).ToString(), TileBlocks("Unused")[1].Foreground?.ToString());
|
||||
Assert.Contains(texts, text => text?.StartsWith("No finished instance yet", StringComparison.Ordinal) == true);
|
||||
}
|
||||
if (history.Totals.Early == 0)
|
||||
{
|
||||
Assert.Equal(["Gift", "—", "no early reset"], Tile("Gift"));
|
||||
Assert.Equal(Ui.Colour("Muted", theme == ThemeVariant.Dark).ToString(), TileBlocks("Gift")[1].Foreground?.ToString());
|
||||
Assert.Contains("No early resets in this range", texts);
|
||||
Assert.Empty(card.GetVisualDescendants().OfType<ResetHistogram>());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(2, card.GetVisualDescendants().OfType<ResetHistogram>().Count());
|
||||
Assert.Contains(Display.ResetDuration(history.Totals.Skipped) + " skipped", Tile("Gift")[2]);
|
||||
Assert.DoesNotContain("≈ ", Tile("Gift")[2]);
|
||||
var timeline = card.GetVisualDescendants().OfType<ResetTimeline>().Single();
|
||||
var layout = ResetTimeline.CalculateLayout(history, fixture.Now);
|
||||
foreach (var skipped in layout.Skipped)
|
||||
{
|
||||
ToolTip.SetIsOpen(timeline, false);
|
||||
window.MouseMove(new Point(4, 4)); Dispatcher.UIThread.RunJobs();
|
||||
var mid = skipped.Instance.End + skipped.Instance.Skipped / 2;
|
||||
var x = 42 + (mid - layout.From).TotalSeconds / (layout.To - layout.From).TotalSeconds * (timeline.Bounds.Width - 58);
|
||||
var pointer = timeline.TranslatePoint(new Point(x, 181 + skipped.Lane * 10), window)!.Value;
|
||||
window.MouseMove(pointer);
|
||||
Assert.True(ToolTip.GetTip(timeline) is DataTooltip, $"{name} {theme}, lane {skipped.Lane}, timeline {timeline.Bounds}");
|
||||
var tooltip = Assert.IsType<DataTooltip>(ToolTip.GetTip(timeline));
|
||||
// The tall tooltip opens beside the pointer; over it, it would take the pointer from the timeline.
|
||||
Assert.True(ToolTip.GetIsOpen(timeline));
|
||||
Assert.True(tooltip.Bounds.Width > 320, $"tooltip width {tooltip.Bounds.Width}");
|
||||
var tipBounds = new PixelRect(tooltip.PointToScreen(default), PixelSize.FromSize(tooltip.Bounds.Size, 1));
|
||||
Assert.False(tipBounds.Contains(window.PointToScreen(pointer)), $"{name} {theme}, lane {skipped.Lane}, tooltip {tipBounds}, pointer {window.PointToScreen(pointer)}, placement {ToolTip.GetPlacement(timeline)}");
|
||||
if (skipped == layout.Skipped[0] || skipped == layout.Skipped[^1]) save(window, $"resets-{name}-hover-lane{skipped.Lane}-{theme}.png");
|
||||
Assert.Contains(tooltip.Rows, r => r.Label == "End" && r.Value == Display.Projection(skipped.Instance.End, new FixedClock(fixture.Now)));
|
||||
}
|
||||
ToolTip.SetIsOpen(timeline, false);
|
||||
window.MouseMove(timeline.TranslatePoint(new Point(timeline.Bounds.Width - 10, 80), window)!.Value);
|
||||
Assert.Null(ToolTip.GetTip(timeline));
|
||||
window.MouseMove(new Point(4, 4));
|
||||
}
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user