mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-16 08:57:52 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export const processCSV=async(csv,cfg)=>{
|
||||
const [{parse},{groupBy,sumBy}]=await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||
]);
|
||||
const {filterColumn:fc,filterValue:fv,groupBy:gb,aggregateColumn:ac,operation:op}=cfg;
|
||||
const rows=parse(csv,{header:!0,skipEmptyLines:!0}).data.filter(r=>r[fc]==fv);
|
||||
const grouped=groupBy(rows,r=>r[gb]);
|
||||
const agg=v=>{
|
||||
if(op=='count')return v.length;
|
||||
const total=sumBy(v,x=>+x[ac]||0);
|
||||
return op=='avg'&&v.length?total/v.length:total;
|
||||
};
|
||||
return Object.entries(grouped).map(([k,v])=>({[gb]:k,result:agg(v)}));
|
||||
};
|
||||
export default processCSV;
|
||||
Reference in New Issue
Block a user