MCPcopy Create free account
hub / github.com/pollinations/pollinations / normalize

Function normalize

apps/operation/finance/lib/normalize.mjs:17–48  ·  view source on GitHub ↗
(rawRows, vendorsMap)

Source from the content-addressed store, hash-verified

15 * user and re-running normalize with an updated map).
16 */
17export function normalize(rawRows, vendorsMap) {
18 const canonical = [];
19 const unknownSet = new Set();
20 const stats = new Map();
21 for (const r of rawRows) {
22 const key = r.counterparty;
23 const entry = vendorsMap[key];
24 if (!entry) {
25 unknownSet.add(key);
26 const s = stats.get(key) ?? { count: 0, sumEur: 0 };
27 s.count += 1;
28 s.sumEur += r.amount_eur ?? 0;
29 stats.set(key, s);
30 continue;
31 }
32 canonical.push({
33 date: r.date,
34 month: r.date.slice(0, 7),
35 vendor: entry.canonical,
36 category: entry.category,
37 amount: r.amount_eur,
38 });
39 }
40 const unknownStats = [...stats.entries()]
41 .map(([counterparty, s]) => ({
42 counterparty,
43 count: s.count,
44 sumEur: Number(s.sumEur.toFixed(2)),
45 }))
46 .sort((a, b) => Math.abs(b.sumEur) - Math.abs(a.sumEur));
47 return { canonical, unknown: [...unknownSet], unknownStats };
48}

Callers 2

normalize.test.mjsFile · 0.90

Calls 5

addMethod · 0.80
pushMethod · 0.80
sliceMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected