fix(web): usage hourly breakdown lists every hour chronologically (#7595)
This commit is contained in:
1 parent
a850895f68
commit
62654d279f
1 file changed
+20
-6
@@ -68,12 +68,15 @@ export function UsagePage() {
|
||||
: enumerateHourStarts(window.sinceTime, window.untilTime),
|
||||
[window.sinceTime, window.untilTime],
|
||||
);
|
||||
// Newest first: the window can run 90 periods, so the interesting end
|
||||
// belongs at the top of the table.
|
||||
const breakdownPeriods = useMemo<readonly (DailyTotals | HourlyTotals)[]>(
|
||||
() => (isPast24Hours ? merged.hourly : merged.daily).toReversed(),
|
||||
[isPast24Hours, merged.daily, merged.hourly],
|
||||
);
|
||||
// The hourly window is small enough to render every period: the table then
|
||||
// reads chronologically like the chart, instead of jumping between the hours
|
||||
// that happened to have activity. Daily windows can run 90 periods, so those
|
||||
// stay newest-first with the interesting end on top.
|
||||
const breakdownPeriods = useMemo<readonly (DailyTotals | HourlyTotals)[]>(() => {
|
||||
if (!isPast24Hours) return merged.daily.toReversed();
|
||||
const byHour = new Map(merged.hourly.map((entry) => [entry.hourStart, entry]));
|
||||
return hours.map((hourStart) => byHour.get(hourStart) ?? zeroHour(hourStart));
|
||||
}, [isPast24Hours, merged.daily, merged.hourly, hours]);
|
||||
|
||||
const selectWindow = (days: number) => {
|
||||
setWindowSelection({
|
||||
@@ -435,6 +438,17 @@ export function UsagePage() {
|
||||
);
|
||||
}
|
||||
|
||||
/** A zero-filled hourly period so the breakdown lists every hour in the window. */
|
||||
function zeroHour(hourStart: string): HourlyTotals {
|
||||
return {
|
||||
day: "",
|
||||
hourStart,
|
||||
costUsd: 0,
|
||||
totalTokens: 0,
|
||||
byProvider: new Map<UsageProviderKind, { costUsd: number; totalTokens: number }>(),
|
||||
};
|
||||
}
|
||||
|
||||
/** Brand mark for the harness a row belongs to. */
|
||||
function ProviderMark({
|
||||
provider,
|
||||
|
||||
Reference in new issue
Block a user