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:
@@ -1,130 +1,277 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using FinalToken.Core;
|
||||
|
||||
namespace FinalToken.App;
|
||||
|
||||
public static class Ui
|
||||
{
|
||||
public static TextBlock Text(string text, double size = 13) => new() { Text = text, FontSize = size, TextWrapping = TextWrapping.Wrap };
|
||||
public static StackPanel Stack(params Control[] children)
|
||||
{
|
||||
var stack = new StackPanel { Spacing = 10 };
|
||||
foreach (var child in children) stack.Children.Add(child);
|
||||
return stack;
|
||||
}
|
||||
public static Border Card(Control content) => new() { Child = content, Padding = new Thickness(18), CornerRadius = new CornerRadius(9), BorderThickness = new Thickness(1), BorderBrush = Brush.Parse("#558795A5") };
|
||||
public static Button Button(string text, Action action)
|
||||
{
|
||||
var button = new Button { Content = text };
|
||||
button.Click += (_, _) => action();
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PanelWindow : Window
|
||||
{
|
||||
private readonly PanelViewModel model;
|
||||
private readonly StackPanel body = new() { Spacing = 16, Margin = new Thickness(24) };
|
||||
private readonly StackPanel body = new() { Spacing = 24, Margin = new Thickness(24) };
|
||||
private readonly StackPanel statuses = new() { Orientation = Orientation.Horizontal, Spacing = 8 };
|
||||
private readonly TextBlock updated = Ui.Text("", 12, "Muted");
|
||||
private readonly ScrollViewer scroll;
|
||||
private readonly Button refreshButton;
|
||||
private bool queued;
|
||||
private bool wide;
|
||||
private int limitColumns;
|
||||
private readonly Dictionary<Provider, string> selectedDailyWindow = [];
|
||||
private readonly BreakdownState modelBreakdown = new(), projectBreakdown = new();
|
||||
|
||||
public PanelWindow(PanelViewModel model, Action refresh, Action settings, Action quit, Action reload)
|
||||
{
|
||||
this.model = model;
|
||||
Title = $"FinalToken {typeof(Program).Assembly.GetName().Version?.ToString(3)}"; Width = 1160; Height = 920; MinWidth = 720; MinHeight = 500;
|
||||
var header = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 12 };
|
||||
header.Children.Add(Ui.Text("FinalToken", 28));
|
||||
header.Children.Add(Ui.Button("Refresh now", refresh));
|
||||
header.Children.Add(Ui.Button("Settings", settings));
|
||||
header.Children.Add(Ui.Button("Quit", quit));
|
||||
var range = new ComboBox { ItemsSource = new[] { "24 hours", "7 days", "30 days", "90 days", "All history" }, SelectedIndex = (int)model.Range, MinWidth = 150 };
|
||||
range.SelectionChanged += (_, _) => { model.Range = (HistoryRange)range.SelectedIndex; reload(); };
|
||||
var providers = new ComboBox { ItemsSource = new[] { "All providers", "Claude", "Codex" }, SelectedIndex = 0, MinWidth = 150 };
|
||||
providers.SelectionChanged += (_, _) => { model.ProviderFilter = providers.SelectedIndex == 0 ? null : (Provider)(providers.SelectedIndex - 1); reload(); };
|
||||
var filters = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 12 };
|
||||
filters.Children.Add(range); filters.Children.Add(providers);
|
||||
var dock = new DockPanel { Margin = new Thickness(0, 18, 0, 0) };
|
||||
var top = Ui.Stack(header, filters); top.Margin = new Thickness(24, 0, 24, 0);
|
||||
DockPanel.SetDock(top, Dock.Top); dock.Children.Add(top);
|
||||
dock.Children.Add(new ScrollViewer { Content = body }); Content = dock;
|
||||
model.PropertyChanged += (_, _) => RenderModel();
|
||||
Title = $"FinalToken {typeof(Program).Assembly.GetName().Version?.ToString(3)}";
|
||||
Width = 1280; Height = 900; MinWidth = 960; MinHeight = 500; Ui.Theme(this);
|
||||
var brand = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center };
|
||||
brand.Children.Add(Ui.Text("FinalToken", 20));
|
||||
var version = Ui.Text(typeof(Program).Assembly.GetName().Version?.ToString(3) ?? "", 12, "Muted"); version.VerticalAlignment = VerticalAlignment.Center;
|
||||
brand.Children.Add(version);
|
||||
updated.VerticalAlignment = VerticalAlignment.Center; statuses.VerticalAlignment = VerticalAlignment.Center;
|
||||
var left = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 12, VerticalAlignment = VerticalAlignment.Center };
|
||||
left.Children.Add(brand); left.Children.Add(updated); left.Children.Add(statuses);
|
||||
var range = Segments(["24 h", "7 d", "30 d", "90 d", "All"], (int)model.Range, i => { model.Range = (HistoryRange)i; reload(); });
|
||||
var providers = Segments(["All", "Claude", "Codex"], model.ProviderFilter is { } p ? (int)p + 1 : 0,
|
||||
i => { model.ProviderFilter = i == 0 ? null : (Provider)(i - 1); reload(); });
|
||||
refreshButton = Ui.Button("↻", refresh); ToolTip.SetTip(refreshButton, "Refresh local data");
|
||||
var settingsButton = Ui.Button("⚙", settings); ToolTip.SetTip(settingsButton, "Settings");
|
||||
var actions = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center };
|
||||
actions.Children.Add(range); actions.Children.Add(providers); actions.Children.Add(refreshButton); actions.Children.Add(settingsButton);
|
||||
var header = new Grid { Name = "PanelHeader", ColumnDefinitions = new ColumnDefinitions("*,Auto"), Margin = new Thickness(24, 0), Height = 56, ColumnSpacing = 16 };
|
||||
header.Children.Add(left); Grid.SetColumn(actions, 1); header.Children.Add(actions);
|
||||
var dock = new DockPanel(); DockPanel.SetDock(header, Dock.Top); dock.Children.Add(header);
|
||||
scroll = new ScrollViewer { Content = body }; dock.Children.Add(scroll); Content = dock;
|
||||
model.PropertyChanged += (_, _) => QueueRender();
|
||||
SizeChanged += (_, _) => { if (wide != (Bounds.Width - 48 >= 1200) || limitColumns != LimitColumnCount(Bounds.Width - 48)) QueueRender(); };
|
||||
ActualThemeVariantChanged += (_, _) => QueueRender();
|
||||
RenderModel();
|
||||
}
|
||||
public static Control Segments(string[] labels, int selected, Action<int> change)
|
||||
{
|
||||
var panel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 0 };
|
||||
var changing = false;
|
||||
var buttons = labels.Select((label, index) => new ToggleButton { Content = label, IsChecked = index == selected,
|
||||
Padding = new Thickness(8, 6), FontSize = 12 }).ToArray();
|
||||
foreach (var button in buttons) button.Classes.Add("segment");
|
||||
for (var i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
var index = i;
|
||||
buttons[i].IsCheckedChanged += (_, _) =>
|
||||
{
|
||||
if (changing) return;
|
||||
changing = true;
|
||||
foreach (var other in buttons.Where((_, j) => j != index)) other.IsChecked = false;
|
||||
buttons[index].IsChecked = true; changing = false; change(index);
|
||||
};
|
||||
panel.Children.Add(buttons[i]);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
private void QueueRender()
|
||||
{
|
||||
if (queued) return; queued = true;
|
||||
Dispatcher.UIThread.Post(() => { queued = false; RenderModel(); }, DispatcherPriority.Background);
|
||||
}
|
||||
public void RenderModel()
|
||||
{
|
||||
body.Children.Clear();
|
||||
body.Children.Add(Ui.Text(model.Message));
|
||||
var offset = scroll.Offset;
|
||||
wide = (Bounds.Width > 0 ? Bounds.Width : Width) - 48 >= 1200;
|
||||
limitColumns = LimitColumnCount((Bounds.Width > 0 ? Bounds.Width : Width) - 48);
|
||||
var content = new List<Control>();
|
||||
statuses.Children.Clear(); refreshButton.IsEnabled = !model.Refreshing;
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
updated.Text = model.Snapshot is { } s ? "Updated " + (now - s.MadeAt < TimeSpan.FromMinutes(1) ? "just now" : Display.Duration(now - s.MadeAt) + " ago") : model.Message;
|
||||
ToolTip.SetTip(updated, model.Snapshot?.MadeAt.LocalDateTime.ToString("F"));
|
||||
if (model.Snapshot is { } snapshot)
|
||||
{
|
||||
foreach (var provider in snapshot.Providers.Where(p => model.ProviderFilter is null || p.Provider == model.ProviderFilter))
|
||||
foreach (var p in snapshot.Providers)
|
||||
{
|
||||
var card = Ui.Stack(Ui.Text(provider.Provider.ToString(), 22), Ui.Text($"{provider.Status} {provider.Reason}"));
|
||||
foreach (var window in provider.Windows)
|
||||
{
|
||||
var w = window.Window; var pace = window.Pace;
|
||||
var title = Ui.Text($"{w.Label} {w.UsedPercent:0.##}% {Display.State(pace.State)} {(pace.Delta is { } d ? $"{d:+0.0;-0.0;0} points" : "")}", 15);
|
||||
title.Foreground = PaceBar.Colour(pace.State);
|
||||
card.Children.Add(title);
|
||||
card.Children.Add(new PaceBar(window) { Height = 14 });
|
||||
card.Children.Add(Ui.Text($"Reset: {(w.ResetsAt is { } reset ? Display.Duration(reset - DateTimeOffset.UtcNow) + " · " + reset.LocalDateTime.ToString("g") : "unknown")} Sample age: {Display.Duration(DateTimeOffset.UtcNow - w.SampleTime)}" +
|
||||
(pace.Projection is { } projection ? $" Reaches 100%: {Display.Projection(projection)}" : "")));
|
||||
}
|
||||
card.Children.Add(Ui.Text("Tokens · provider totals", 15));
|
||||
card.Children.Add(Ui.Text("Today " + Display.Tokens(provider.Today)));
|
||||
card.Children.Add(Ui.Text("Session " + Display.Tokens(provider.Session)));
|
||||
card.Children.Add(Ui.Text("Week " + Display.Tokens(provider.Week)));
|
||||
card.Children.Add(Ui.Text("Cache read is included in Codex input; reasoning is included in output.", 11));
|
||||
body.Children.Add(Ui.Card(card));
|
||||
var label = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4 };
|
||||
label.Children.Add(Ui.Mark("●", p.Status == ProviderStatus.Available ? Ui.ProviderColour(p.Provider, Ui.Dark(this)) : Ui.Colour("Muted", Ui.Dark(this))));
|
||||
label.Children.Add(Ui.Text(p.Provider.ToString(), 12));
|
||||
var pill = new Border { Child = label, CornerRadius = new CornerRadius(10), Padding = new Thickness(8, 4), BorderThickness = new Thickness(1), BorderBrush = Ui.Colour("Border", Ui.Dark(this)) };
|
||||
ToolTip.SetTip(pill, p.Reason ?? p.Status.ToString()); statuses.Children.Add(pill);
|
||||
}
|
||||
var providers = snapshot.Providers.Where(p => model.ProviderFilter is null || p.Provider == model.ProviderFilter).ToArray();
|
||||
content.Add(Ui.Text("Limits", 20));
|
||||
var tiles = new List<Control>();
|
||||
foreach (var provider in providers)
|
||||
{
|
||||
if (provider.Status != ProviderStatus.Available)
|
||||
tiles.Add(Ui.Card(Ui.Stack(Ui.Text(provider.Provider + " · " + provider.Status, 15), Ui.Text(provider.Reason ?? "Provider disabled", 13, "Secondary"))));
|
||||
else foreach (var window in provider.Windows) tiles.Add(LimitTile(window, now));
|
||||
}
|
||||
content.Add(Ui.Columns(tiles, limitColumns));
|
||||
var longWindows = model.History.Details.Where(d => d.Days is not null && providers.Any(p => p.Provider == d.Provider &&
|
||||
p.Status == ProviderStatus.Available && p.Windows.Any(w => w.Window.Id == d.Id))).ToArray();
|
||||
if (longWindows.Length > 0)
|
||||
{
|
||||
content.Add(Ui.Text("Week use per day", 20));
|
||||
content.Add(Ui.Columns(longWindows.GroupBy(d => d.Provider).Select(group =>
|
||||
{
|
||||
var entries = group.ToArray();
|
||||
var index = Array.FindIndex(entries, d => d.Id == selectedDailyWindow.GetValueOrDefault(group.Key));
|
||||
if (index < 0) index = 0;
|
||||
var labels = entries.Select(d => providers.SelectMany(p => p.Windows).First(w => w.Window.Provider == d.Provider && w.Window.Id == d.Id).Window.Label).ToArray();
|
||||
Control DayView(LimitDetail item) => item.Days!.Current.Any(d => d.Used is not null)
|
||||
? new DailyLimitChart(item.Days, item.Provider)
|
||||
: Ui.Text($"Collecting history since {(item.Since ?? providers.SelectMany(p => p.Windows).First(w => w.Window.Provider == item.Provider && w.Window.Id == item.Id).Window.SampleTime).LocalDateTime:dd.MM. HH:mm}", 12, "Muted");
|
||||
var chart = new Border { Child = DayView(entries[index]) };
|
||||
var title = Ui.Text(group.Key + " · " + labels[index], 15);
|
||||
var stack = Ui.Stack(title);
|
||||
var explanation = Ui.Text("Measured · Estimated from tokens (hatched) · faint: previous window, same day of the window", 12, "Muted");
|
||||
void UpdateExplanation(LimitDetail item) => explanation.IsVisible = item.Days!.Current.Any(d => d.Used is not null);
|
||||
UpdateExplanation(entries[index]);
|
||||
if (entries.Length > 1)
|
||||
{
|
||||
var selector = new WindowSelector { ItemsSource = labels, SelectedIndex = index };
|
||||
selector.SelectionChanged += (_, _) =>
|
||||
{
|
||||
if (selector.SelectedIndex < 0) return;
|
||||
var item = entries[selector.SelectedIndex]; selectedDailyWindow[group.Key] = item.Id;
|
||||
title.Text = group.Key + " · " + labels[selector.SelectedIndex];
|
||||
chart.Child = DayView(item);
|
||||
UpdateExplanation(item);
|
||||
};
|
||||
stack.Children.Add(selector);
|
||||
}
|
||||
stack.Children.Add(explanation);
|
||||
stack.Children.Add(chart); return Ui.Card(stack);
|
||||
}), wide));
|
||||
}
|
||||
var tokenHeader = new DockPanel();
|
||||
var toggle = new NeutralCheckBox { Content = "Include cache reads", IsChecked = model.IncludeCacheReads, HorizontalAlignment = HorizontalAlignment.Right };
|
||||
toggle.IsCheckedChanged += (_, _) => model.IncludeCacheReads = toggle.IsChecked == true;
|
||||
DockPanel.SetDock(toggle, Dock.Right); tokenHeader.Children.Add(toggle);
|
||||
var tokenTitle = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 24, VerticalAlignment = VerticalAlignment.Center };
|
||||
tokenTitle.Children.Add(Ui.Text("Tokens", 20)); tokenTitle.Children.Add(CompositionLegend()); tokenHeader.Children.Add(tokenTitle); content.Add(tokenHeader);
|
||||
var totals = providers.Select(p =>
|
||||
{
|
||||
var row = new WrapPanel();
|
||||
row.Children.Add(TokenTile(p, "Today", p.Today));
|
||||
if (p.Session is { } session && p.Windows.Any(w => w.Window.Length <= TimeSpan.FromDays(1))) row.Children.Add(TokenTile(p, "Current session", session));
|
||||
row.Children.Add(TokenTile(p, "This week", p.Week));
|
||||
return (Control)Ui.Card(Ui.Stack(Ui.Text(p.Provider.ToString(), 15), row));
|
||||
});
|
||||
content.Add(Ui.Columns(totals, wide));
|
||||
}
|
||||
var h = model.History;
|
||||
body.Children.Add(Ui.Card(Ui.Stack(Ui.Text("Tokens per hour", 19), Legend(h.Hourly), new UsageChart { Values = h.Hourly })));
|
||||
body.Children.Add(Ui.Card(Ui.Stack(Ui.Text("Tokens per day", 19), Legend(h.Daily), new UsageChart { Values = h.Daily, Interval = TimeSpan.FromDays(1) })));
|
||||
foreach (var limit in h.Limits)
|
||||
body.Children.Add(Ui.Card(Ui.Stack(Ui.Text(limit.Label, 19), Ui.Text("Blue: used · dashed green: expected pace · gaps: window reset", 11), new UsageChart { Values = limit.Values, Percent = true })));
|
||||
body.Children.Add(Breakdown("By model", h.Models));
|
||||
body.Children.Add(Breakdown("By project", h.Projects));
|
||||
var diagnostics = Ui.Stack(Ui.Text("Recent diagnostics", 19));
|
||||
foreach (var d in model.Diagnostics) diagnostics.Children.Add(Ui.Text($"{d.Time.LocalDateTime:g} · {d.Provider} · {d.Code} · {d.Summary}"));
|
||||
if (model.Diagnostics.Count == 0) diagnostics.Children.Add(Ui.Text("No recent problems."));
|
||||
body.Children.Add(Ui.Card(diagnostics));
|
||||
}
|
||||
private static Control Legend(IReadOnlyList<ChartValue> values)
|
||||
{
|
||||
var legend = new WrapPanel { Orientation = Orientation.Horizontal };
|
||||
var index = 0;
|
||||
foreach (var series in values.Select(v => v.Series).Distinct())
|
||||
var seriesNames = h.Hourly.Concat(h.Daily).Select(v => v.Series).Distinct().Order(StringComparer.Ordinal).ToArray();
|
||||
Control TokenChart(string title, IReadOnlyList<ChartValue> values, bool daily) => Ui.Card(Ui.Stack(Ui.Text(title, 15),
|
||||
Legend(seriesNames), new UsageChart { Values = values.Select(v => v with { Value = Math.Max(0, v.Value - (model.IncludeCacheReads ? 0 : v.CacheRead)) }).ToArray(),
|
||||
SeriesNames = seriesNames, Interval = daily ? TimeSpan.FromDays(1) : TimeSpan.FromHours(1) }));
|
||||
content.Add(Ui.Columns([TokenChart("Tokens per hour", h.Hourly, false), TokenChart("Tokens per day", h.Daily, true)], wide));
|
||||
var windows = h.Limits.Where(l => l.Analysis?.Current.HasData == true).ToArray();
|
||||
if (windows.Length > 0)
|
||||
{
|
||||
var label = Ui.Text("● " + series, 12); label.Foreground = UsageChart.SeriesColour(index++);
|
||||
label.Margin = new Thickness(0, 0, 14, 0); legend.Children.Add(label);
|
||||
content.Add(Ui.Text("Window charts", 20));
|
||||
content.Add(Ui.Columns(windows.Select(limit => Ui.Card(Ui.Stack(Ui.Text(limit.Label, 15),
|
||||
Ui.Text("Measured · dashed: estimated · faint: previous · dotted: forecast", 12, "Muted"), new BurnUpChart(limit),
|
||||
Ui.Text("Past instances · peak use", 12, "Muted"), new InstancePeaks(limit.Analysis!.Past, limit.Provider)))), wide));
|
||||
}
|
||||
content.Add(Ui.Text("Breakdown", 20));
|
||||
content.Add(Ui.Card(new BreakdownTable("By model", h.Models, false, model.ProviderFilter, modelBreakdown)));
|
||||
content.Add(Ui.Card(new BreakdownTable("By project", h.Projects, true, model.ProviderFilter, projectBreakdown)));
|
||||
if (model.Diagnostics.Count > 0)
|
||||
{
|
||||
var lines = Ui.Stack();
|
||||
foreach (var d in model.Diagnostics) lines.Children.Add(Ui.Text($"{d.Time.LocalDateTime:g} · {d.Provider} · {d.Code} · {d.Summary} ({d.Count})", 12, "Secondary"));
|
||||
content.Add(Ui.Card(new Expander { Header = $"Diagnostics ({model.Diagnostics.Count})", Content = lines, IsExpanded = false }));
|
||||
}
|
||||
body.Children.Clear(); foreach (var control in content) body.Children.Add(control);
|
||||
scroll.UpdateLayout(); scroll.Offset = offset;
|
||||
}
|
||||
private Control LimitTile(WindowSnapshot window, DateTimeOffset now)
|
||||
{
|
||||
var w = window.Window; var pace = window.Pace;
|
||||
var detail = model.History.Details.FirstOrDefault(d => d.Provider == w.Provider && d.Id == w.Id);
|
||||
var title = new DockPanel();
|
||||
var chip = new Border { Child = Ui.Mark(Display.State(pace.State), Brush.Parse("#0b0b0b")), Background = PaceBar.Colour(pace.State), CornerRadius = new CornerRadius(6), Padding = new Thickness(8, 4) };
|
||||
DockPanel.SetDock(chip, Dock.Right); title.Children.Add(chip); title.Children.Add(Ui.Text(w.Provider + " · " + w.Label, 15));
|
||||
var card = Ui.Stack(title, Ui.Text($"{w.UsedPercent:0.#} %", 36), Ui.Text("used", 12, "Muted"), new PaceBar(window) { Height = 10 });
|
||||
card.Children.Add(Ui.Text(w.ResetsAt is { } reset ? $"Resets in {Display.Duration(reset - now)} · {Display.Projection(reset)}" : "Reset unknown", 13, "Secondary"));
|
||||
if (pace.Projection is { } projection)
|
||||
{
|
||||
var caption = Display.Forecast(projection, pace.State) + $" ({Display.Duration(w.ResetsAt!.Value - projection)} before reset)";
|
||||
if (pace.State == PaceState.Ahead)
|
||||
{
|
||||
var line = new DockPanel(); var mark = Ui.Mark("⚠ ", Brush.Parse("#d03b3b"), 13);
|
||||
DockPanel.SetDock(mark, Dock.Left); line.Children.Add(mark); line.Children.Add(Ui.Text(caption[2..], 13, "Secondary")); card.Children.Add(line);
|
||||
}
|
||||
else card.Children.Add(Ui.Text(caption, 13, "Secondary"));
|
||||
}
|
||||
else if (LimitAnalysis.AverageUseAtReset(w, now, pace) is { } average)
|
||||
card.Children.Add(Ui.Text($"≈ {average:0.#} % at reset", 13, "Secondary"));
|
||||
else if (Display.ForecastWaiting(window, now) is { } waiting)
|
||||
card.Children.Add(Ui.Text(waiting, 13, "Muted"));
|
||||
if (detail?.Recent is { } recent)
|
||||
{
|
||||
var line = Ui.Text($"Last {Display.Span(recent.Span)}: +{recent.Increase:0.#} %" + (recent.ReachesLimit is { } date ? $" · 100 % on {Display.Projection(date)}" : $" · ≈ {recent.UseAtReset:0.#} % at reset"), 13, "Secondary");
|
||||
ToolTip.SetTip(line, new DataTooltip("Recent rate", new("Rate", $"{recent.PercentPerDay:0.##} %/day"), new("Observed span", Display.Duration(recent.Span)))); card.Children.Add(line);
|
||||
}
|
||||
if (detail?.Days is { } days)
|
||||
{
|
||||
card.Children.Add(Ui.Text(days.Today is { } today ? days.TodayOrigin == UseOrigin.Estimated
|
||||
? $"Today ≈ +{today:0.#} % of the week (estimated)" : $"Today +{today:0.#} % of the week" : "Today · collecting a day baseline", 15));
|
||||
card.Children.Add(Ui.Text($"Even pace {days.EvenPace:0.#} %/day", 13, "Secondary"));
|
||||
if (days.DailyBudget is { } budget) card.Children.Add(Ui.Text($"Budget {budget:0.#} %/day for {Display.Duration(w.ResetsAt!.Value - now)}", 15));
|
||||
}
|
||||
if (now - w.SampleTime > model.ProbeInterval * 2) card.Children.Add(Ui.Text($"⚠ sample {Display.Duration(now - w.SampleTime)} old", 12, "Muted"));
|
||||
var tile = Ui.Card(card); tile.Name = $"LimitTile-{w.Provider}-{w.Id}";
|
||||
ToolTip.SetTip(tile, new DataTooltip(w.Provider + " · " + w.Label, new("Used", $"{w.UsedPercent:0.##} %"), new("Expected", $"{pace.ElapsedFraction * 100:0.##} %"),
|
||||
new("State", Display.State(pace.State)), new("Reset", w.ResetsAt is { } r ? Display.Projection(r) : "Unknown"), new("Sample", w.SampleTime.LocalDateTime.ToString("g")))); return tile;
|
||||
}
|
||||
private Control TokenTile(ProviderSnapshot provider, string label, TokenCounts counts)
|
||||
{
|
||||
var tile = Ui.Stack(Ui.Text(label, 12, "Secondary"), Ui.Text(Display.Compact(Math.Max(0, counts.Total - (model.IncludeCacheReads ? 0 : counts.CacheRead))), 32),
|
||||
new CompositionBar(counts, provider.Provider, model.IncludeCacheReads) { Height = 6 });
|
||||
tile.Width = wide ? 164 : 188; tile.Margin = new Thickness(0, 8, 16, 0);
|
||||
ToolTip.SetTip(tile, DataTooltip.Tokens(provider.Provider + " · " + label, counts)); return tile;
|
||||
}
|
||||
private Control CompositionLegend()
|
||||
{
|
||||
var panel = new WrapPanel { Name = "CompositionLegend", VerticalAlignment = VerticalAlignment.Center }; var colour = model.ProviderFilter is { } provider
|
||||
? Ui.ProviderColour(provider, Ui.Dark(this)) : Ui.Colour("Secondary", Ui.Dark(this));
|
||||
var labels = new[] { "Input", "Output", "Cache write", "Cache read" };
|
||||
for (var i = 0; i < labels.Length; i++)
|
||||
{
|
||||
var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 3, Margin = new Thickness(0, 0, 6, 0) };
|
||||
row.Children.Add(new Border { Background = i == 3 ? Ui.Colour("Cache", Ui.Dark(this)) : colour,
|
||||
Opacity = i == 1 ? .65 : i == 2 ? .4 : 1, Width = 5, Height = 5, CornerRadius = new CornerRadius(2), VerticalAlignment = VerticalAlignment.Center });
|
||||
row.Children.Add(Ui.Text(labels[i], 11, "Muted")); panel.Children.Add(row);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
private Control Legend(string[] names)
|
||||
{
|
||||
var legend = new WrapPanel();
|
||||
foreach (var name in names)
|
||||
{
|
||||
var item = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4 };
|
||||
item.Children.Add(Ui.Mark("●", UsageChart.SeriesColour(name, names, Ui.Dark(this)))); item.Children.Add(Ui.Text(name, 12, "Secondary"));
|
||||
item.Margin = new Thickness(0, 0, 16, 0); legend.Children.Add(item);
|
||||
}
|
||||
return legend;
|
||||
}
|
||||
private static Border Breakdown(string title, IReadOnlyList<BreakdownRow> rows)
|
||||
public static string[] ShortProjectNames(string[] paths)
|
||||
{
|
||||
var table = Ui.Stack(Ui.Text(title, 19));
|
||||
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("3*,1*,1*,1*,1*,1*,1*,1*"), MinWidth = 900 };
|
||||
var headers = new[] { "Name", "Total", "Share", "Input", "Cache read", "Cache write", "Output", "Reasoning" };
|
||||
AddRow(headers, 0);
|
||||
var index = 1;
|
||||
foreach (var row in rows)
|
||||
var parts = paths.Select(p => p.Replace('\\', '/').Split('/', StringSplitOptions.RemoveEmptyEntries)).ToArray();
|
||||
return parts.Select((p, i) =>
|
||||
{
|
||||
var c = row.Counts;
|
||||
AddRow([row.Name, c.Total.ToString("N0"), row.Share.ToString("P1"), c.Input.ToString("N0"), c.CacheRead.ToString("N0"),
|
||||
c.CacheWrite.ToString("N0"), c.Output.ToString("N0"), c.ReasoningOutput.ToString("N0")], index++);
|
||||
}
|
||||
table.Children.Add(new ScrollViewer { Content = grid, HorizontalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Auto,
|
||||
VerticalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled });
|
||||
if (rows.Count == 0) table.Children.Add(Ui.Text("No tokens in this range."));
|
||||
return Ui.Card(table);
|
||||
void AddRow(string[] values, int row)
|
||||
{
|
||||
grid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
|
||||
for (var column = 0; column < values.Length; column++)
|
||||
{
|
||||
var text = Ui.Text(values[column], 11); text.Margin = new Thickness(0, 4, 8, 4);
|
||||
Grid.SetRow(text, row); Grid.SetColumn(text, column); grid.Children.Add(text);
|
||||
}
|
||||
}
|
||||
var depth = Math.Min(2, p.Length);
|
||||
while (depth < p.Length && parts.Where((_, j) => j != i).Any(other => string.Join('/', other.TakeLast(depth)) == string.Join('/', p.TakeLast(depth)))) depth++;
|
||||
return string.Join('/', p.TakeLast(depth));
|
||||
}).ToArray();
|
||||
}
|
||||
// Leave wheel events unhandled so they bubble to the page instead of changing selection.
|
||||
private sealed class WindowSelector : ComboBox
|
||||
{
|
||||
protected override Type StyleKeyOverride => typeof(ComboBox);
|
||||
protected override void OnPointerWheelChanged(Avalonia.Input.PointerWheelEventArgs e) { }
|
||||
}
|
||||
public static int LimitColumnCount(double contentWidth) => contentWidth >= 1400 ? 3 : contentWidth >= 1200 ? 2 : 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user