ai-heatmap 1.17.8 → 1.17.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/generate.mjs +23 -4
package/package.json
CHANGED
package/scripts/generate.mjs
CHANGED
|
@@ -75,11 +75,30 @@ if (!mergeOnly) {
|
|
|
75
75
|
}
|
|
76
76
|
const { daily } = JSON.parse(raw);
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
const
|
|
78
|
+
// Build a map of existing data, merging duplicate dates by summing
|
|
79
|
+
const dataMap = new Map();
|
|
80
|
+
for (const d of daily) {
|
|
81
|
+
if (!dataMap.has(d.date)) {
|
|
82
|
+
dataMap.set(d.date, { ...d });
|
|
83
|
+
} else {
|
|
84
|
+
const existing = dataMap.get(d.date);
|
|
85
|
+
existing.totalCost = (existing.totalCost ?? 0) + (d.totalCost ?? 0);
|
|
86
|
+
existing.inputTokens = (existing.inputTokens ?? 0) + (d.inputTokens ?? 0);
|
|
87
|
+
existing.outputTokens = (existing.outputTokens ?? 0) + (d.outputTokens ?? 0);
|
|
88
|
+
existing.totalTokens = (existing.totalTokens ?? 0) + (d.totalTokens ?? 0);
|
|
89
|
+
existing.cacheReadTokens = (existing.cacheReadTokens ?? 0) + (d.cacheReadTokens ?? 0);
|
|
90
|
+
existing.cacheCreationTokens = (existing.cacheCreationTokens ?? 0) + (d.cacheCreationTokens ?? 0);
|
|
91
|
+
existing.modelsUsed = [...new Set([...(existing.modelsUsed ?? []), ...(d.modelsUsed ?? [])])];
|
|
92
|
+
const bdMap = new Map((existing.modelBreakdowns ?? []).map((m) => [m.modelName, m.cost ?? 0]));
|
|
93
|
+
for (const mb of (d.modelBreakdowns ?? [])) {
|
|
94
|
+
bdMap.set(mb.modelName, (bdMap.get(mb.modelName) ?? 0) + (mb.cost ?? 0));
|
|
95
|
+
}
|
|
96
|
+
existing.modelBreakdowns = [...bdMap.entries()].map(([modelName, cost]) => ({ modelName, cost }));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
80
99
|
|
|
81
|
-
|
|
82
|
-
const
|
|
100
|
+
const costs = [...dataMap.values()].map((d) => d.totalCost);
|
|
101
|
+
const maxCost = Math.max(...costs);
|
|
83
102
|
|
|
84
103
|
// Fill 365 days (from today back 364 days)
|
|
85
104
|
const today = new Date();
|