mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-08 21:35:23 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
const processCSV = async (csvString, config) => {
|
||||
const { parse } = await import('https://cdn.skypack.dev/papaparse');
|
||||
|
||||
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||
const { data } = parse(csvString, { header: true, skipEmptyLines: true });
|
||||
|
||||
const filtered = data.filter(row => row[filterColumn] == filterValue);
|
||||
const filtered = data.filter(row => row[config.filterColumn] == config.filterValue);
|
||||
|
||||
const grouped = filtered.reduce((acc, row) => {
|
||||
const key = row[groupBy];
|
||||
const key = row[config.groupBy];
|
||||
if (!acc[key]) acc[key] = [];
|
||||
acc[key].push(row);
|
||||
return acc;
|
||||
@@ -14,17 +14,15 @@ const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateCo
|
||||
|
||||
return Object.entries(grouped).map(([key, rows]) => {
|
||||
let result;
|
||||
|
||||
if (operation === 'count') {
|
||||
if (config.operation === 'count') {
|
||||
result = rows.length;
|
||||
} else {
|
||||
const values = rows.map(r => parseFloat(r[aggregateColumn]) || 0);
|
||||
result = operation === 'sum'
|
||||
const values = rows.map(r => parseFloat(r[config.aggregateColumn]) || 0);
|
||||
result = config.operation === 'sum'
|
||||
? values.reduce((a, b) => a + b, 0)
|
||||
: values.reduce((a, b) => a + b, 0) / values.length;
|
||||
}
|
||||
|
||||
return { [groupBy]: key, [operation]: result };
|
||||
return { [config.groupBy]: key, result };
|
||||
});
|
||||
};
|
||||
export default processCSV;
|
||||
Reference in New Issue
Block a user