Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Make AI cost sparklines more informative

rcourtman0d539ed0a51b
diff --git a/frontend-modern/src/components/AI/AICostDashboard.tsx b/frontend-modern/src/components/AI/AICostDashboard.tsx
index dae6d65c50..26738eb9b2 100644
--- a/frontend-modern/src/components/AI/AICostDashboard.tsx
+++ b/frontend-modern/src/components/AI/AICostDashboard.tsx
@@ -98,8 +98,21 @@ export const AICostDashboard: Component = () => {
return map;
});
- const dailyTokenValues = createMemo(() => (summary()?.daily_totals ?? []).map((d) => d.total_tokens));
- const dailyUSDValues = createMemo(() => (summary()?.daily_totals ?? []).map((d) => d.estimated_usd ?? 0));
+ const dailyTotals = createMemo(() => summary()?.daily_totals ?? []);
+ const dailyTokenValues = createMemo(() => dailyTotals().map((d) => d.total_tokens));
+ const dailyUSDValues = createMemo(() => dailyTotals().map((d) => d.estimated_usd ?? 0));
+
+ const lastDailyTokens = createMemo(() => {
+ const values = dailyTokenValues();
+ if (values.length === 0) return null;
+ return values[values.length - 1];
+ });
+
+ const lastDailyUSD = createMemo(() => {
+ const values = dailyUSDValues();
+ if (values.length === 0) return null;
+ return values[values.length - 1];
+ });
const formatUSD = (usd: number) => usdFormatter.format(usd);
@@ -406,19 +419,37 @@ export const AICostDashboard: Component = () => {
<div class="p-3 rounded-lg bg-gray-50 dark:bg-gray-800/40 border border-gray-200 dark:border-gray-700">
<div class="flex items-center justify-between">
<div class="text-xs text-gray-500 dark:text-gray-400">Daily estimated USD</div>
- <div class="text-xs text-gray-500 dark:text-gray-400">{data().daily_totals.length} points</div>
+ <div class="text-xs text-gray-500 dark:text-gray-400">
+ <Show when={anyPricingKnown() && lastDailyUSD() != null} fallback={<span>—</span>}>
+ {formatUSD(lastDailyUSD() ?? 0)}
+ </Show>
+ </div>
</div>
<div class="mt-2">
- <TinySparkline values={dailyUSDValues()} stroke="#10b981" />
+ <Show
+ when={anyPricingKnown() && dailyUSDValues().length >= 2}
+ fallback={<div class="text-xs text-gray-500 dark:text-gray-400">No daily USD trend yet.</div>}
+ >
+ <TinySparkline values={dailyUSDValues()} stroke="#10b981" />
+ </Show>
</div>
</div>
<div class="p-3 rounded-lg bg-gray-50 dark:bg-gray-800/40 border border-gray-200 dark:border-gray-700">
<div class="flex items-center justify-between">
<div class="text-xs text-gray-500 dark:text-gray-400">Daily total tokens</div>
- <div class="text-xs text-gray-500 dark:text-gray-400">{data().daily_totals.length} points</div>
+ <div class="text-xs text-gray-500 dark:text-gray-400">
+ <Show when={lastDailyTokens() != null} fallback={<span>—</span>}>
+ {formatNumber(lastDailyTokens() ?? 0)}
+ </Show>
+ </div>
</div>
<div class="mt-2">
- <TinySparkline values={dailyTokenValues()} stroke="#3b82f6" />
+ <Show
+ when={dailyTokenValues().length >= 2}
+ fallback={<div class="text-xs text-gray-500 dark:text-gray-400">No daily token trend yet.</div>}
+ >
+ <TinySparkline values={dailyTokenValues()} stroke="#3b82f6" />
+ </Show>
</div>
</div>
</div>