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

18 lines
645 B
JavaScript

export const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const [{ parse }, { groupBy, map }] = await Promise.all([
import('https://esm.sh/papaparse@5.4.1'),
import('https://esm.sh/lodash-es@4.17.21')
]);
return map(groupBy(
parse(csv, { header: true, skipEmptyLines: true }).data.filter(r => r[fc] == fv),
gb
), (rows, key) => {
const sum = rows.reduce((a, r) => a + (+r[ac] || 0), 0);
return {
[gb]: key,
result: op === 'count' ? rows.length : op === 'avg' ? sum / rows.length : sum
};
});
};
export default processCSV;