mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
Delete tests/6_csv_processor/outputs_gemini directory
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
const processCSV = async (csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { csvParse, rollup, sum, mean } = await import('https://esm.sh/d3@7');
|
||||
|
||||
const toNum = d => +d[aggregateColumn] || 0;
|
||||
|
||||
const aggregators = {
|
||||
sum: g => sum(g, toNum),
|
||||
avg: g => mean(g, toNum),
|
||||
count: g => g.length
|
||||
};
|
||||
|
||||
const data = csvParse(csvString).filter(row => row[filterColumn] == filterValue);
|
||||
const grouped = rollup(data, aggregators[operation], d => d[groupBy]);
|
||||
|
||||
return Array.from(grouped, ([key, val]) => ({
|
||||
[groupBy]: key,
|
||||
result: val
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,24 +0,0 @@
|
||||
const processCSV = async (csvString, config) => {
|
||||
const { default: Papa } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op } = config;
|
||||
|
||||
const { data } = Papa.parse(csvString, { header: true, skipEmptyLines: true });
|
||||
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[fc] == fv) {
|
||||
const key = row[gb];
|
||||
const val = +row[ac] || 0;
|
||||
|
||||
acc[key] ??= { sum: 0, count: 0 };
|
||||
acc[key].sum += val;
|
||||
acc[key].count++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'count' ? count : op === 'sum' ? sum : sum / count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,25 +0,0 @@
|
||||
const processCSV = async (csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const [{ default: { parse } }, { rollup, sum, mean }] = await Promise.all([
|
||||
import('https://esm.sh/papaparse@5.4.1'),
|
||||
import('https://esm.sh/d3-array@3.2.4')
|
||||
]);
|
||||
|
||||
const getNum = row => {
|
||||
const val = parseFloat(row[aggregateColumn]);
|
||||
return isNaN(val) ? 0 : val;
|
||||
};
|
||||
|
||||
const rows = parse(csvString, { header: true, skipEmptyLines: true }).data
|
||||
.filter(row => row[filterColumn] == filterValue);
|
||||
|
||||
const grouped = rollup(
|
||||
rows,
|
||||
group => operation === 'count' ? group.length :
|
||||
operation === 'sum' ? sum(group, getNum) :
|
||||
mean(group, getNum),
|
||||
row => row[groupBy]
|
||||
);
|
||||
|
||||
return Array.from(grouped, ([key, result]) => ({ [groupBy]: key, result }));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,19 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { csvParse } = await import('https://esm.run/d3-dsv')
|
||||
const groups = new Map()
|
||||
|
||||
csvParse(csv).forEach(row => {
|
||||
if (row[fc] == fv) {
|
||||
const key = row[gb]
|
||||
const val = +row[ac] || 0
|
||||
const curr = groups.get(key) || { s: 0, n: 0 }
|
||||
groups.set(key, { s: curr.s + val, n: curr.n + 1 })
|
||||
}
|
||||
})
|
||||
|
||||
return [...groups].map(([key, { s, n }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'count' ? n : op === 'sum' ? s : s / n
|
||||
}))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,21 +0,0 @@
|
||||
const processCSV = async (csvStr, { filterColumn: fCol, filterValue: fVal, groupBy: gBy, aggregateColumn: aggCol, operation: op }) => {
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')
|
||||
const { data } = Papa.parse(csvStr, { header: true, skipEmptyLines: true })
|
||||
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[fCol] == fVal) {
|
||||
const key = row[gBy]
|
||||
const val = +row[aggCol] || 0
|
||||
acc[key] = acc[key] || { s: 0, c: 0 }
|
||||
acc[key].s += val
|
||||
acc[key].c++
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return Object.entries(groups).map(([key, { s, c }]) => ({
|
||||
[gBy]: key,
|
||||
result: op === 'count' ? c : op === 'avg' ? s / c : s
|
||||
}))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,19 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const [{ csvParse }, { rollup, sum, mean }] = await Promise.all([
|
||||
import('https://esm.sh/d3-dsv@3'),
|
||||
import('https://esm.sh/d3-array@3')
|
||||
]);
|
||||
|
||||
return Array.from(
|
||||
rollup(
|
||||
csvParse(csv).filter(d => d[fc] == fv),
|
||||
g => {
|
||||
const v = g.map(d => +d[ac] || 0);
|
||||
return op === 'count' ? v.length : op === 'sum' ? sum(v) : mean(v);
|
||||
},
|
||||
d => d[gb]
|
||||
),
|
||||
([k, v]) => ({ [gb]: k, result: v })
|
||||
);
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,21 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true });
|
||||
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[filterColumn] == filterValue) {
|
||||
const key = row[groupBy];
|
||||
const val = +row[aggregateColumn] || 0;
|
||||
acc[key] ||= { sum: 0, count: 0 };
|
||||
acc[key].sum += val;
|
||||
acc[key].count++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'count' ? count : operation === 'sum' ? sum : sum / count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,21 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { default: Papa } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[fc] == fv) {
|
||||
const key = row[gb];
|
||||
const val = +row[ac] || 0;
|
||||
acc[key] = acc[key] || { s: 0, c: 0 };
|
||||
acc[key].s += val;
|
||||
acc[key].c++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(groups).map(([key, { s, c }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'count' ? c : op === 'sum' ? s : s / c
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,20 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
const groups = {};
|
||||
|
||||
parse(csv, { header: true, skipEmptyLines: true }).data.forEach(row => {
|
||||
if (row[filterColumn] == filterValue) {
|
||||
const key = row[groupBy];
|
||||
const val = +row[aggregateColumn] || 0;
|
||||
const acc = groups[key] ??= { sum: 0, count: 0 };
|
||||
acc.sum += val;
|
||||
acc.count++;
|
||||
}
|
||||
});
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'count' ? count : operation === 'avg' ? sum / count : sum
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,13 +0,0 @@
|
||||
export const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { csvParse, rollups, sum } = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
|
||||
|
||||
return rollups(
|
||||
csvParse(csv).filter(d => d[fc] == fv),
|
||||
g => {
|
||||
const s = sum(g, d => +d[ac] || 0)
|
||||
return op === 'count' ? g.length : op === 'sum' ? s : s / g.length
|
||||
},
|
||||
d => d[gb]
|
||||
).map(([k, v]) => ({ [gb]: k, result: v }))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,17 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fCol, filterValue: fVal, groupBy: gBy, aggregateColumn: aCol, operation: op }) => {
|
||||
const { csvParse, rollup, sum } = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
|
||||
|
||||
return Array.from(
|
||||
rollup(
|
||||
csvParse(csv).filter(r => r[fCol] == fVal),
|
||||
g => {
|
||||
if (op === 'count') return g.length
|
||||
const nums = g.map(r => +r[aCol] || 0), total = sum(nums)
|
||||
return op === 'sum' ? total : total / nums.length
|
||||
},
|
||||
d => d[gBy]
|
||||
),
|
||||
([k, v]) => ({ [gBy]: k, result: v })
|
||||
)
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,20 +0,0 @@
|
||||
const processCSV = async (csvData, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { parse } = await import('https://esm.sh/papaparse');
|
||||
const groups = {};
|
||||
|
||||
parse(csvData, { header: true, skipEmptyLines: true }).data.forEach(row => {
|
||||
if (row[filterColumn] == filterValue) {
|
||||
const key = row[groupBy];
|
||||
const val = +row[aggregateColumn] || 0;
|
||||
const rec = groups[key] ||= { sum: 0, count: 0 };
|
||||
rec.sum += val;
|
||||
rec.count++;
|
||||
}
|
||||
});
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'count' ? count : operation === 'sum' ? sum : sum / count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,23 +0,0 @@
|
||||
export const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const [{ parse }, { default: _ }] = await Promise.all([
|
||||
import('https://esm.sh/papaparse@5.4.1'),
|
||||
import('https://esm.sh/lodash@4.17.21')
|
||||
]);
|
||||
|
||||
const rows = _.filter(parse(csv, { header: true, skipEmptyLines: true }).data, r => r[filterColumn] == filterValue);
|
||||
|
||||
return _.map(_.groupBy(rows, groupBy), (group, key) => {
|
||||
const nums = _.map(group, r => {
|
||||
const n = parseFloat(r[aggregateColumn]);
|
||||
return isNaN(n) ? 0 : n;
|
||||
});
|
||||
|
||||
const sum = _.sum(nums);
|
||||
const result = operation === 'count' ? group.length :
|
||||
operation === 'sum' ? sum :
|
||||
(sum / (nums.length || 1));
|
||||
|
||||
return { [groupBy]: key, result };
|
||||
});
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,17 +0,0 @@
|
||||
export const processCSV = async (str, {
|
||||
filterColumn: fc,
|
||||
filterValue: fv,
|
||||
groupBy: gb,
|
||||
aggregateColumn: ac,
|
||||
operation: op
|
||||
}) => {
|
||||
const { csvParse, rollups, sum, mean } = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm')
|
||||
const val = d => +d[ac] || 0
|
||||
|
||||
return rollups(
|
||||
csvParse(str).filter(d => d[fc] == fv),
|
||||
g => op === 'count' ? g.length : op === 'sum' ? sum(g, val) : mean(g, val) || 0,
|
||||
d => d[gb]
|
||||
).map(([k, r]) => ({ [gb]: k, result: r }))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,19 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { csvParse } = await import('https://esm.sh/d3-dsv@3');
|
||||
|
||||
const groups = csvParse(csv).reduce((acc, row) => {
|
||||
if (row[fc] == fv) {
|
||||
const k = row[gb], v = +row[ac] || 0;
|
||||
acc[k] ??= { s: 0, c: 0 };
|
||||
acc[k].s += v;
|
||||
acc[k].c++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(groups).map(([k, { s, c }]) => ({
|
||||
[gb]: k,
|
||||
result: op === 'count' ? c : op === 'avg' ? s / c : s
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,19 +0,0 @@
|
||||
const processCSV = async (csvStr, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { parse } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const acc = {};
|
||||
|
||||
parse(csvStr, { header: true, skipEmptyLines: true }).data.forEach(row => {
|
||||
if (row[fc] == fv) {
|
||||
const k = row[gb], v = +row[ac] || 0;
|
||||
const curr = acc[k] ||= { s: 0, c: 0 };
|
||||
curr.s += v;
|
||||
curr.c++;
|
||||
}
|
||||
});
|
||||
|
||||
return Object.entries(acc).map(([key, { s, c }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'count' ? c : op === 'avg' ? s / c : s
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,18 +0,0 @@
|
||||
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;
|
||||
@@ -1,22 +0,0 @@
|
||||
const processCSV = async (csvString, config) => {
|
||||
const { filterColumn: key, filterValue: val, groupBy: group, aggregateColumn: target, operation: op } = config
|
||||
|
||||
const [dsv, d3] = await Promise.all([
|
||||
import('https://esm.sh/d3-dsv'),
|
||||
import('https://esm.sh/d3-array')
|
||||
])
|
||||
|
||||
const getVal = d => +d[target] || 0
|
||||
const rows = dsv.csvParse(csvString).filter(r => r[key] == val)
|
||||
|
||||
const aggs = d3.rollup(
|
||||
rows,
|
||||
v => op === 'count' ? v.length :
|
||||
op === 'sum' ? d3.sum(v, getVal) :
|
||||
d3.mean(v, getVal),
|
||||
d => d[group]
|
||||
)
|
||||
|
||||
return Array.from(aggs, ([gVal, result]) => ({ [group]: gVal, result }))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,18 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fCol, filterValue: fVal, groupBy: gBy, aggregateColumn: aggCol, operation: op }) => {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')
|
||||
const groups = new Map()
|
||||
|
||||
parse(csv, { header: true, skipEmptyLines: true }).data.forEach(row => {
|
||||
if (row[fCol] == fVal) {
|
||||
const key = row[gBy], val = +row[aggCol] || 0
|
||||
const cur = groups.get(key) || { sum: 0, count: 0 }
|
||||
groups.set(key, { sum: cur.sum + val, count: cur.count + 1 })
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(groups, ([key, { sum, count }]) => ({
|
||||
[gBy]: key,
|
||||
result: op === 'avg' ? sum / count : op === 'count' ? count : sum
|
||||
}))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,22 +0,0 @@
|
||||
export const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { parse } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true });
|
||||
const acc = new Map();
|
||||
|
||||
for (const row of data) {
|
||||
if (row[fc] == fv) {
|
||||
const key = row[gb];
|
||||
const val = +row[ac] || 0;
|
||||
const rec = acc.get(key) || { sum: 0, count: 0 };
|
||||
rec.sum += val;
|
||||
rec.count += 1;
|
||||
acc.set(key, rec);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(acc, ([key, { sum, count }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'count' ? count : op === 'sum' ? sum : sum / count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,16 +0,0 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user