MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / formatMetric

Function formatMetric

apps/web/src/components/usage-analytics/format.ts:5–32  ·  view source on GitHub ↗
(metric: MetricKey, value: number)

Source from the content-addressed store, hash-verified

3import type { MetricKey } from './types';
4
5export function formatMetric(metric: MetricKey, value: number): string {
6 switch (metric) {
7 case 'cost':
8 return formatDollars(fromMicrodollars(value));
9 case 'requests':
10 return formatLargeNumber(value);
11 case 'tokens':
12 case 'inputTokens':
13 case 'outputTokens':
14 return formatLargeNumber(value);
15 case 'errorRate':
16 case 'cacheHitRatio':
17 return `${(value * 100).toFixed(1)}%`;
18 case 'avgLatencyMs':
19 case 'avgGenerationTimeMs': {
20 if (value >= 1000) {
21 return `${(value / 1000).toFixed(2)}s`;
22 }
23 return `${Math.round(value)}ms`;
24 }
25 case 'costPerRequest':
26 return formatMicrodollars(value, 4);
27 case 'tokensPerRequest':
28 return Math.round(value).toLocaleString();
29 case 'outputInputRatio':
30 return `${value.toFixed(2)}x`;
31 }
32}
33
34export function formatBytes(n: number): string {
35 return formatLargeNumber(n);

Callers 3

yFormatterFunction · 0.90
formatBarValueFunction · 0.90
SummarySectionFunction · 0.90

Calls 4

formatDollarsFunction · 0.90
fromMicrodollarsFunction · 0.90
formatLargeNumberFunction · 0.90
formatMicrodollarsFunction · 0.90

Tested by

no test coverage detected