Files
lynchmark.com/tests/6_csv_processor/outputs_gemini/gemini-3-pro-preview TEMP_2.js
T

16 lines
593 B
JavaScript

const processCSV = async (csvString, config) => {
const [{ csvParse }, { rollups, sum }] = await Promise.all([
import('https://esm.sh/d3-dsv'),
import('https://esm.sh/d3-array')
]);
const { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op } = config;
const getVal = d => +d[ac] || 0;
return rollups(
csvParse(csvString).filter(d => d[fc] == fv),
g => op === 'count' ? g.length : (op === 'avg' ? sum(g, getVal) / g.length : sum(g, getVal)),
d => d[gb]
).map(([k, v]) => ({ [gb]: k, result: v }));
};
export default processCSV;