@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 33 lines 1.04 KB
Raw
1 import type { UsageProviderKind } from "@t3tools/contracts";
2 import type { DailyTotals } from "@t3tools/shared/usageMerge";
3
4 import { PROVIDER_ORDER } from "./usageProviders";
5
6 export type UsageChartMetric = "cost" | "tokens";
7
8 export interface UsageChartDay {
9 readonly day: string;
10 readonly values: readonly { readonly provider: UsageProviderKind; readonly value: number }[];
11 readonly total: number;
12 }
13
14 export function buildChartDays(
15 days: readonly string[],
16 daily: readonly DailyTotals[],
17 metric: UsageChartMetric,
18 ): readonly UsageChartDay[] {
19 const byDay = new Map(daily.map((totals) => [totals.day, totals]));
20 return days.map((day) => {
21 const totals = byDay.get(day);
22 const values = PROVIDER_ORDER.map((provider) => {
23 const entry = totals?.byProvider.get(provider);
24 const value = entry === undefined ? 0 : metric === "cost" ? entry.costUsd : entry.totalTokens;
25 return { provider, value };
26 });
27 return {
28 day,
29 values,
30 total: values.reduce((sum, entry) => sum + entry.value, 0),
31 };
32 });
33 }