feat: add combineSeries for GPU combination aggregation

This commit is contained in:
c4ch3c4d3
2026-08-14 12:59:41 -06:00
parent 15627fc494
commit 74d0c10523
2 changed files with 41 additions and 1 deletions
+12
View File
@@ -22,6 +22,18 @@ const AGGREGATE: Record<GpuMetricKind, (values: number[]) => number> = {
fan: avg,
};
export function combineSeries(histories: number[][], kind: GpuMetricKind): { value?: number; history: number[] } {
const n = Math.max(...histories.map((h) => h.length), 0);
if (n === 0) return { value: undefined, history: [] };
const history: number[] = [];
for (let i = 0; i < n; i++) {
const at = histories.map((h) => h[i]).filter((v): v is number => v !== undefined);
if (at.length === 0) continue;
history.push(AGGREGATE[kind](at));
}
return { value: history.length > 0 ? history[history.length - 1] : undefined, history };
}
function key(gpuId: string, kind: GpuMetricKind): string {
return `${gpuId}|${kind}`;
}