Docs: Update Gemini benchmark results

This commit is contained in:
github-actions[bot]
2025-11-18 19:30:39 +00:00
parent 51a98c1e1b
commit 76fb066932
133 changed files with 2340 additions and 0 deletions

View File

@@ -76,5 +76,161 @@
"7_scheduler": 68.04158863600017,
"8_json_validator": 19.484740249000023,
"9_stream_visualizer": 28.426358369000255
},
"gemini-3-pro-preview TEMP:1.1": {
"10_scrypt_hash": 19.25561597,
"11_geospatial": 16.537793451,
"1_dijkstra": 19.709102094000002,
"2_convex_hull": 23.759404848,
"3_lis": 23.048148686,
"4_determinant": 20.935209288,
"5_markdown_parser": 34.398462477999985,
"6_csv_processor": 43.183913065,
"7_scheduler": 31.16975645300001,
"8_json_validator": 22.189696912000013,
"9_stream_visualizer": 27.786803166999977
},
"gemini-3-pro-preview TEMP:1": {
"10_scrypt_hash": 16.73660885900003,
"11_geospatial": 27.702141619000002,
"1_dijkstra": 24.343912240999984,
"2_convex_hull": 22.499538950000016,
"3_lis": 23.92277027799998,
"4_determinant": 19.12632760900003,
"5_markdown_parser": 24.235546227000015,
"6_csv_processor": 28.255928477999987,
"7_scheduler": 52.90334799400001,
"8_json_validator": 16.544846496000012,
"9_stream_visualizer": 28.031947036999977
},
"gemini-3-pro-preview TEMP:0.9": {
"10_scrypt_hash": 18.39214110999997,
"11_geospatial": 21.698826697999962,
"1_dijkstra": 31.32494983399997,
"2_convex_hull": 33.63882225600001,
"3_lis": 22.98625518599991,
"4_determinant": 9.706784340000013,
"5_markdown_parser": 25.077740615000017,
"6_csv_processor": 38.424850744000054,
"7_scheduler": 40.46733092999994,
"8_json_validator": 21.866049754999928,
"9_stream_visualizer": 29.938616987999993
},
"gemini-3-pro-preview TEMP:0.8": {
"10_scrypt_hash": 22.864061476000003,
"11_geospatial": 21.802520365000003,
"1_dijkstra": 25.727360443000098,
"2_convex_hull": 20.067116691999953,
"3_lis": 17.514798727000016,
"4_determinant": 26.222232214999966,
"5_markdown_parser": 27.822983316000084,
"6_csv_processor": 31.795846373000067,
"7_scheduler": 45.54547771500005,
"8_json_validator": 20.04490028099995,
"9_stream_visualizer": 31.52293631999986
},
"gemini-3-pro-preview TEMP:0.7": {
"10_scrypt_hash": 23.39639778,
"11_geospatial": 23.114445250999882,
"1_dijkstra": 24.20112610200001,
"2_convex_hull": 29.664885391999967,
"3_lis": 15.16884128500009,
"4_determinant": 36.34684787500021,
"5_markdown_parser": 27.07226724700001,
"6_csv_processor": 36.69383957000007,
"7_scheduler": 41.66182964499993,
"8_json_validator": 24.68038384200004,
"9_stream_visualizer": 32.811990770999806
},
"gemini-3-pro-preview TEMP:0.6": {
"10_scrypt_hash": 20.319240230000112,
"11_geospatial": 14.71396687299991,
"1_dijkstra": 29.94397802599985,
"2_convex_hull": 30.130152880999958,
"3_lis": 22.789678306000074,
"4_determinant": 13.336225186000112,
"5_markdown_parser": 26.61024377000006,
"6_csv_processor": 23.28925823200005,
"7_scheduler": 31.414080646000105,
"8_json_validator": 18.36662647700007,
"9_stream_visualizer": 31.141520149999998
},
"gemini-3-pro-preview TEMP:0.5": {
"10_scrypt_hash": 26.257502701000078,
"11_geospatial": 27.292514397000197,
"1_dijkstra": 26.930725388999797,
"2_convex_hull": 28.365386472000043,
"3_lis": 20.404020288000115,
"4_determinant": 19.956521905999864,
"5_markdown_parser": 41.075851207999975,
"6_csv_processor": 33.550666006000014,
"7_scheduler": 54.52258278499986,
"8_json_validator": 30.504760077999904,
"9_stream_visualizer": 25.344985834000166
},
"gemini-3-pro-preview TEMP:0.4": {
"10_scrypt_hash": 16.79715236100019,
"11_geospatial": 25.48661641700007,
"1_dijkstra": 17.67472643599985,
"2_convex_hull": 34.115073089000305,
"3_lis": 18.289524143000133,
"4_determinant": 22.224696940999944,
"5_markdown_parser": 53.21322759300005,
"6_csv_processor": 39.43421280799993,
"7_scheduler": 30.78163343900023,
"8_json_validator": 26.184069054999853,
"9_stream_visualizer": 21.324422691999935
},
"gemini-3-pro-preview TEMP:0.3": {
"10_scrypt_hash": 22.419933818999677,
"11_geospatial": 14.525312852999662,
"1_dijkstra": 24.24144133199984,
"2_convex_hull": 27.67347379200021,
"3_lis": 13.649138154000044,
"4_determinant": 28.68561609600019,
"5_markdown_parser": 44.175827321999705,
"6_csv_processor": 40.22086091799987,
"7_scheduler": 42.102860941999595,
"8_json_validator": 24.13780150000006,
"9_stream_visualizer": 22.134434574999847
},
"gemini-3-pro-preview TEMP:0.2": {
"10_scrypt_hash": 24.400115432000252,
"11_geospatial": 32.89142006099969,
"1_dijkstra": 36.531734934999605,
"2_convex_hull": 30.47034405499976,
"3_lis": 14.03327947399998,
"4_determinant": 15.886417729000096,
"5_markdown_parser": 43.89735358300013,
"6_csv_processor": 36.24166352199996,
"7_scheduler": 49.958096608999654,
"8_json_validator": 21.518541840999852,
"9_stream_visualizer": 30.054751582999714
},
"gemini-3-pro-preview TEMP:0.1": {
"10_scrypt_hash": 21.251296984999907,
"11_geospatial": 28.01666565400036,
"1_dijkstra": 22.908056412999983,
"2_convex_hull": 31.488867672999856,
"3_lis": 19.367484238999896,
"4_determinant": 16.061534822999967,
"5_markdown_parser": 30.51042381200008,
"6_csv_processor": 20.860845792999957,
"7_scheduler": 34.17653273200011,
"8_json_validator": 14.083612348000054,
"9_stream_visualizer": 19.854906946000177
},
"gemini-3-pro-preview TEMP:0": {
"10_scrypt_hash": 22.467800446999725,
"11_geospatial": 23.184671450000256,
"1_dijkstra": 28.33117579400027,
"2_convex_hull": 26.517016473000403,
"3_lis": 17.292057299999986,
"4_determinant": 22.012527137000113,
"5_markdown_parser": 44.51245308799995,
"6_csv_processor": 35.65954501500027,
"7_scheduler": 31.53722489799978,
"8_json_validator": 21.652465214000085,
"9_stream_visualizer": 28.28463803699985
}
}

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js@3.0.1')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => (b + 256).toString(16).slice(1)).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js');
const e = new TextEncoder();
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32);
return [...k].map(b => b.toString(16).padStart(2, '0')).join('');
};
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return Array.from(k, b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://unpkg.com/scrypt-js?module')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => b.toString(16).padStart(2, 0)).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return Array.from(k, b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (pwd, salt) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const enc = txt => new TextEncoder().encode(txt)
const key = await scrypt(enc(pwd), enc(salt), 1024, 8, 1, 32)
return Array.from(key, b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js@3.0.1')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => (b + 256).toString(16).slice(1)).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,7 @@
const hashPassword = async (p, s) => {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const k = await scrypt(e.encode(p), e.encode(s), 1024, 8, 1, 32)
return [...k].map(b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;

View File

@@ -0,0 +1,10 @@
const analyzeGPS = async (readings, boundary) => {
const T = await import('https://esm.sh/@turf/turf')
const pts = readings
.filter(r => T.booleanPointInPolygon(T.point(r.loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc)
return pts.length < 2 ? 0 : +T.length(T.lineString(pts), { units: 'kilometers' }).toFixed(2)
}
export default analyzeGPS;

View File

@@ -0,0 +1,12 @@
const analyzeGPS = async (readings, boundary) => {
const t = await import('https://cdn.jsdelivr.net/npm/@turf/turf/+esm');
const pts = readings
.filter(({ loc }) => t.booleanPointInPolygon(t.point(loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc);
return pts.length < 2 ? 0 :
Math.round(t.length(t.lineString(pts), { units: 'kilometers' }) * 100) / 100;
};
export default analyzeGPS;

View File

@@ -0,0 +1,14 @@
const analyzeGPS = async (readings, boundary) => {
const T = await import('https://esm.sh/@turf/turf');
const pts = readings
.filter(r => T.booleanPointInPolygon(T.point(r.loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc);
if (pts.length < 2) return 0;
const len = T.length(T.lineString(pts), { units: 'kilometers' });
return Math.round(len * 100) / 100;
};
export default analyzeGPS;

View File

@@ -0,0 +1,12 @@
const analyzeGPS = async (readings, boundary) => {
const t = await import('https://cdn.jsdelivr.net/npm/@turf/turf/+esm');
const pts = readings
.filter(({ loc }) => t.booleanPointInPolygon(t.point(loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc);
return pts.length < 2 ? 0 :
Math.round(t.length(t.lineString(pts), { units: 'kilometers' }) * 100) / 100;
};
export default analyzeGPS;

View File

@@ -0,0 +1,13 @@
const analyzeGPS = async (readings, boundary) => {
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf');
const coords = readings
.filter(({ loc }) => booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc);
return coords.length < 2
? 0
: +length(lineString(coords), { units: 'kilometers' }).toFixed(2);
};
export default analyzeGPS;

View File

@@ -0,0 +1,10 @@
const analyzeGPS = async (readings, boundary) => {
const t = await import('https://esm.sh/@turf/turf');
const pts = readings
.filter(r => t.booleanPointInPolygon(t.point(r.loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc);
return pts.length < 2 ? 0 : +t.length(t.lineString(pts), { units: 'kilometers' }).toFixed(2);
};
export default analyzeGPS;

View File

@@ -0,0 +1,12 @@
const analyzeGPS = async (readings, boundary) => {
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf');
const path = readings
.filter(({ loc }) => booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc);
return path.length < 2 ? 0 :
Math.round(length(lineString(path), { units: 'kilometers' }) * 100) / 100;
};
export default analyzeGPS;

View File

@@ -0,0 +1,10 @@
const analyzeGPS = async (readings, boundary) => {
const T = await import('https://cdn.jsdelivr.net/npm/@turf/turf/+esm')
const pts = readings
.filter(r => T.booleanPointInPolygon(T.point(r.loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc)
return pts.length < 2 ? 0 : +T.length(T.lineString(pts), { units: 'kilometers' }).toFixed(2)
}
export default analyzeGPS;

View File

@@ -0,0 +1,12 @@
const analyzeGPS = async (readings, boundary) => {
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf');
const pts = readings
.filter(r => booleanPointInPolygon(point(r.loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc);
return pts.length < 2 ? 0
: +length(lineString(pts), { units: 'kilometers' }).toFixed(2);
};
export default analyzeGPS;

View File

@@ -0,0 +1,12 @@
const analyzeGPS = async (readings, boundary) => {
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf');
const coords = readings
.filter(({ loc }) => booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc);
return coords.length < 2 ? 0 :
Math.round(length(lineString(coords), { units: 'kilometers' }) * 100) / 100;
};
export default analyzeGPS;

View File

@@ -0,0 +1,14 @@
const analyzeGPS = async (readings, boundary) => {
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf')
const path = readings
.filter(({ loc }) => booleanPointInPolygon(point(loc), boundary))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc)
if (path.length < 2) return 0
const dist = length(lineString(path), { units: 'kilometers' })
return Math.round(dist * 100) / 100
}
export default analyzeGPS;

View File

@@ -0,0 +1,14 @@
const analyzeGPS = async (readings, boundary) => {
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf')
const path = readings
.filter(({ loc }) => booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc)
if (path.length < 2) return 0
const dist = length(lineString(path), { units: 'kilometers' })
return Math.round(dist * 100) / 100
}
export default analyzeGPS;

View File

@@ -0,0 +1,22 @@
const findShortestPath = async (g, s, e) => {
const { default: Q } = await import('https://esm.sh/js-priority-queue')
const q = new Q({ comparator: (a, b) => a.w - b.w })
const d = { [s]: 0 }
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1/0)) continue
for (let v in g[n]) {
let t = w + g[n][v]
if (t < (d[v] ?? 1/0)) {
d[v] = t
q.queue({ n: v, w: t })
}
}
}
return 1/0
}
export default findShortestPath;

View File

@@ -0,0 +1,19 @@
const findShortestPath = async (g, s, e) => {
const { default: P } = await import('https://esm.sh/js-priority-queue');
const q = new P({ comparator: (a, b) => a.w - b.w }), d = { [s]: 0 };
q.queue({ n: s, w: 0 });
while (q.length) {
const { n, w } = q.dequeue();
if (n === e) return w;
if (w > (d[n] ?? 1 / 0)) continue;
for (const k in g[n] || {}) {
const t = w + g[n][k];
if (t < (d[k] ?? 1 / 0)) {
d[k] = t;
q.queue({ n: k, w: t });
}
}
}
return 1 / 0;
};
export default findShortestPath;

View File

@@ -0,0 +1,20 @@
const findShortestPath = async (g, s, e) => {
const { default: P } = await import('https://esm.sh/js-priority-queue')
const q = new P({ comparator: (a, b) => a.w - b.w })
const m = { [s]: 0 }
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (w > (m[n] ?? 1 / 0)) continue
for (const k in g[n] || {}) {
const t = w + g[n][k]
if (t < (m[k] ?? 1 / 0)) {
m[k] = t
q.queue({ n: k, w: t })
}
}
}
return 1 / 0
}
export default findShortestPath;

View File

@@ -0,0 +1,22 @@
const findShortestPath = async (g, s, e) => {
const { default: PQ } = await import('https://esm.sh/js-priority-queue')
const q = new PQ({ comparator: (a, b) => a.w - b.w })
const d = { [s]: 0 }
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1 / 0)) continue
for (const [v, cost] of Object.entries(g[n] || {})) {
const t = w + cost
if (t < (d[v] ?? 1 / 0)) {
d[v] = t
q.queue({ n: v, w: t })
}
}
}
return 1 / 0
}
export default findShortestPath;

View File

@@ -0,0 +1,19 @@
const findShortestPath = async (g, s, e) => {
const { default: Q } = await import('https://esm.sh/js-priority-queue')
const d = { [s]: 0 }, q = new Q({ comparator: (a, b) => a.w - b.w })
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1 / 0)) continue
for (const [v, c] of Object.entries(g[n] || {})) {
const k = w + c
if (k < (d[v] ?? 1 / 0)) {
d[v] = k
q.queue({ n: v, w: k })
}
}
}
return 1 / 0
}
export default findShortestPath;

View File

@@ -0,0 +1,24 @@
const findShortestPath = async (g, s, e) => {
const { default: PQ } = await import('https://esm.sh/js-priority-queue')
const q = new PQ({ comparator: (a, b) => a.w - b.w })
const d = { [s]: 0 }, v = new Set()
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (v.has(n)) continue
v.add(n)
for (const k in g[n]) {
const t = w + g[n][k]
if (t < (d[k] ?? Infinity)) {
d[k] = t
q.queue({ n: k, w: t })
}
}
}
return Infinity
}
export default findShortestPath;

View File

@@ -0,0 +1,25 @@
const findShortestPath = async (g, s, e) => {
const { default: PQ } = await import('https://esm.sh/js-priority-queue');
const q = new PQ({ comparator: (a, b) => a.w - b.w });
const d = { [s]: 0 };
q.queue({ w: 0, n: s });
while (q.length) {
const { w, n } = q.dequeue();
if (n === e) return w;
if (w > (d[n] ?? 1 / 0)) continue;
for (const v in g[n]) {
const k = w + g[n][v];
if (k < (d[v] ?? 1 / 0)) {
d[v] = k;
q.queue({ w: k, n: v });
}
}
}
return 1 / 0;
};
export default findShortestPath;

View File

@@ -0,0 +1,19 @@
const findShortestPath = async (g, s, e) => {
const { default: P } = await import('https://esm.sh/js-priority-queue');
const q = new P({ comparator: (a, b) => a.c - b.c }), d = { [s]: 0 };
q.queue({ n: s, c: 0 });
while (q.length) {
const { n, c } = q.dequeue();
if (n === e) return c;
if (c > (d[n] ?? 1 / 0)) continue;
for (let v in g[n]) {
let k = c + g[n][v];
if (k < (d[v] ?? 1 / 0)) {
d[v] = k;
q.queue({ n: v, c: k });
}
}
}
return 1 / 0;
};
export default findShortestPath;

View File

@@ -0,0 +1,25 @@
const findShortestPath = async (g, s, e) => {
const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm')
const q = new PQ({ comparator: (a, b) => a.w - b.w })
const d = { [s]: 0 }
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1 / 0)) continue
for (const k in g[n] || {}) {
const c = w + g[n][k]
if (c < (d[k] ?? 1 / 0)) {
d[k] = c
q.queue({ n: k, w: c })
}
}
}
return 1 / 0
}
export default findShortestPath;

View File

@@ -0,0 +1,19 @@
const findShortestPath = async (g, s, e) => {
const { default: PQ } = await import('https://esm.sh/js-priority-queue')
const q = new PQ({ comparator: (a, b) => a.w - b.w }), d = { [s]: 0 }
q.queue({ n: s, w: 0 })
while (q.length) {
const { n, w } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1/0)) continue
for (const [v, c] of Object.entries(g[n] || {})) {
const k = w + c
if (k < (d[v] ?? 1/0)) {
d[v] = k
q.queue({ n: v, w: k })
}
}
}
return 1/0
}
export default findShortestPath;

View File

@@ -0,0 +1,25 @@
const findShortestPath = async (graph, start, end) => {
const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue/+esm')
const costs = { [start]: 0 }
const queue = new PQ({ comparator: (a, b) => a.cost - b.cost })
queue.queue({ node: start, cost: 0 })
while (queue.length) {
const { node, cost } = queue.dequeue()
if (node === end) return cost
if (cost > (costs[node] ?? Infinity)) continue
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
const nextCost = cost + weight
if (nextCost < (costs[neighbor] ?? Infinity)) {
costs[neighbor] = nextCost
queue.queue({ node: neighbor, cost: nextCost })
}
}
}
return Infinity
}
export default findShortestPath;

View File

@@ -0,0 +1,24 @@
const findShortestPath = async (graph, start, end) => {
const { default: PQ } = await import('https://cdn.skypack.dev/js-priority-queue');
const queue = new PQ({ comparator: (a, b) => a.d - b.d });
const dists = { [start]: 0 }, visited = new Set();
queue.queue({ n: start, d: 0 });
while (queue.length) {
const { n, d } = queue.dequeue();
if (n === end) return d;
if (visited.has(n)) continue;
visited.add(n);
for (const [neighbor, weight] of Object.entries(graph[n] || {})) {
const newDist = d + weight;
if (newDist < (dists[neighbor] ?? Infinity)) {
dists[neighbor] = newDist;
queue.queue({ n: neighbor, d: newDist });
}
}
}
return Infinity;
};
export default findShortestPath;

View File

@@ -0,0 +1,15 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
if (s.length < 3) return s
const x = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
const m = (l) => l.reduce((h, p) => {
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
h.push(p)
return h
}, [])
const l = m(s)
const u = m([...s].reverse())
return [...l.slice(0, -1), ...u.slice(0, -1)]
}
export default findConvexHull;

View File

@@ -0,0 +1,13 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
if (s.length < 3) return s;
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
const f = (h, p) => {
while (h.length > 1 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
return h;
};
return [...s.reduce(f, []).slice(0, -1), ...s.reduceRight(f, []).slice(0, -1)];
};
export default findConvexHull;

View File

@@ -0,0 +1,27 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
if (!Array.isArray(pts)) throw new Error('Input must be an array');
const u = _.uniqWith(pts, _.isEqual);
if (u.length < 3) return u;
const s = _.sortBy(u, ['x', 'y']);
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
const h = [];
for (const p of s) {
while (h.length >= 2 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
const t = h.length + 1;
for (let i = s.length - 2; i >= 0; i--) {
const p = s[i];
while (h.length >= t && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
h.pop();
return h;
};
export default findConvexHull;

View File

@@ -0,0 +1,24 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
if (s.length < 3) return s
const cross = (a, b, o) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
const build = (list) => {
const h = []
for (const p of list) {
while (h.length >= 2 && cross(h[h.length - 1], p, h[h.length - 2]) <= 0) h.pop()
h.push(p)
}
return h
}
const l = build(s)
const u = build([...s].reverse())
l.pop()
u.pop()
return [...l, ...u]
}
export default findConvexHull;

View File

@@ -0,0 +1,16 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
const u = _.uniqWith(pts, _.isEqual)
if (u.length < 3) return u
const s = _.sortBy(u, ['x', 'y'])
const cp = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
const scan = (lst) => lst.reduce((h, p) => {
while (h.length >= 2 && cp(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
h.push(p)
return h
}, [])
const l = scan(s)
const up = scan([...s].reverse())
return [...l.slice(0, -1), ...up.slice(0, -1)]
}
export default findConvexHull;

View File

@@ -0,0 +1,17 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
if (s.length < 3) return s
const k = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
const m = (v) => {
const h = []
for (const p of v) {
while (h.length >= 2 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
h.push(p)
}
return h
}
const l = m(s), u = m(s.reverse())
return l.slice(0, -1).concat(u.slice(0, -1))
}
export default findConvexHull;

View File

@@ -0,0 +1,22 @@
const findConvexHull = async points => {
const { default: _ } = await import('https://esm.sh/lodash')
const s = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y'])
if (s.length < 3) return s
const h = [], x = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
s.forEach(p => {
while (h.length >= 2 && x(h.at(-2), h.at(-1), p) <= 0) h.pop()
h.push(p)
})
const t = h.length + 1
for (let i = s.length - 2; i >= 0; i--) {
while (h.length >= t && x(h.at(-2), h.at(-1), s[i]) <= 0) h.pop()
h.push(s[i])
}
h.pop()
return h
}
export default findConvexHull;

View File

@@ -0,0 +1,24 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
if (s.length < 3) return s;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const h = [];
for (let i = 0; i < s.length; i++) {
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], s[i]) <= 0) h.pop();
h.push(s[i]);
}
const t = h.length + 1;
for (let i = s.length - 2; i >= 0; i--) {
while (h.length >= t && cross(h[h.length - 2], h[h.length - 1], s[i]) <= 0) h.pop();
h.push(s[i]);
}
h.pop();
return h;
};
export default findConvexHull;

View File

@@ -0,0 +1,23 @@
const findConvexHull = async (pts) => {
if (!pts?.length || pts.length < 3) return pts || [];
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
const scan = (list) => {
const h = [];
for (const p of list) {
while (h.length >= 2 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
return h;
};
const l = scan(s);
const u = scan(s.reverse());
return [...l.slice(0, -1), ...u.slice(0, -1)];
};
export default findConvexHull;

View File

@@ -0,0 +1,19 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://esm.sh/lodash');
const u = _.uniqWith(pts, _.isEqual);
if (u.length < 3) return u;
const s = _.sortBy(u, ['x', 'y']);
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
const f = (l) => {
const h = [];
for (const p of l) {
while (h.length >= 2 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
return h;
};
const l = f(s);
const h = f([...s].reverse());
return [...l.slice(0, -1), ...h.slice(0, -1)];
};
export default findConvexHull;

View File

@@ -0,0 +1,22 @@
const findConvexHull = async (points) => {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
const P = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y'])
if (P.length < 3) return P
const xp = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
const scan = (arr) => {
const h = []
for (const p of arr) {
while (h.length >= 2 && xp(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
h.push(p)
}
return h
}
const l = scan(P)
const u = scan(P.reverse())
return [...l.slice(0, -1), ...u.slice(0, -1)]
}
export default findConvexHull;

View File

@@ -0,0 +1,23 @@
const findConvexHull = async (points) => {
const { default: _ } = await import('https://esm.sh/lodash');
const P = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
if (P.length < 3) return P;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const h = [];
for (const p of P) {
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
const t = h.length + 1;
for (let i = P.length - 2; i >= 0; i--) {
while (h.length >= t && cross(h[h.length - 2], h[h.length - 1], P[i]) <= 0) h.pop();
h.push(P[i]);
}
h.pop();
return h;
};
export default findConvexHull;

View File

@@ -0,0 +1,7 @@
const findLISLength = async nums => {
const { bisectLeft } = await import('https://esm.sh/d3-array')
const tails = []
for (const n of nums) tails[bisectLeft(tails, n)] = n
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async a => {
const { bisectLeft: b } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const t = []
for (const n of a) t[b(t, n)] = n
return t.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async nums => {
const { bisectLeft } = await import('https://esm.sh/d3-array')
const tails = []
for (const n of nums) tails[bisectLeft(tails, n)] = n
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async nums => {
const { bisectLeft } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const tails = []
for (const n of nums) tails[bisectLeft(tails, n)] = n
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async (nums) => {
const { bisectLeft } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const tails = []
for (const x of nums) tails[bisectLeft(tails, x)] = x
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,11 @@
const findLISLength = async (nums) => {
const { bisectLeft } = await import('https://esm.sh/d3-array')
const tails = []
for (const x of nums) {
tails[bisectLeft(tails, x)] = x
}
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,9 @@
const findLISLength = async n => {
const { bisectLeft: b } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const t = []
for (const x of n) {
t[b(t, x)] = x
}
return t.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async nums => {
const { bisectLeft: search } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const tails = []
for (const n of nums) tails[search(tails, n)] = n
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async n => {
const { bisectLeft: b } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const t = []
for (const x of n) t[b(t, x)] = x
return t.length
}
export default findLISLength;

View File

@@ -0,0 +1,11 @@
const findLISLength = async (nums) => {
if (!nums?.length) return 0
const { bisectLeft } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const tails = []
for (const x of nums) {
const i = bisectLeft(tails, x)
i < tails.length ? tails[i] = x : tails.push(x)
}
return tails.length
}
export default findLISLength;

View File

@@ -0,0 +1,7 @@
const findLISLength = async a => {
const { bisectLeft: b } = await import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
const t = []
for (const n of a) t[b(t, n)] = n
return t.length
}
export default findLISLength;

View File

@@ -0,0 +1,9 @@
const findLISLength = async nums => {
const { bisectLeft } = await import('https://esm.sh/d3-array')
const sub = []
for (const n of nums) {
sub[bisectLeft(sub, n)] = n
}
return sub.length
}
export default findLISLength;

View File

@@ -0,0 +1,4 @@
const calculateDeterminant = async m =>
(await import('https://cdn.jsdelivr.net/npm/mathjs@12/+esm'))
.det(m)
export default calculateDeterminant;

View File

@@ -0,0 +1,4 @@
const calculateDeterminant = async m =>
(await import('https://esm.sh/mathjs'))
.det(m)
export default calculateDeterminant;

View File

@@ -0,0 +1,4 @@
const calculateDeterminant = async m =>
(await import('https://cdn.jsdelivr.net/npm/mathjs/+esm'))
.det(m)
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://esm.sh/mathjs@12')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs@12/+esm')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://esm.sh/mathjs')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://esm.sh/mathjs@12')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://esm.sh/mathjs@12')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://esm.sh/mathjs')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,4 @@
const calculateDeterminant = async m =>
(await import('https://cdn.jsdelivr.net/npm/mathjs@12/+esm'))
.det(m)
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://esm.sh/mathjs@13.0.0')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const calculateDeterminant = async m => {
const { det } = await import('https://cdn.jsdelivr.net/npm/mathjs/+esm')
return det(m)
}
export default calculateDeterminant;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async t => {
const { parse } = await import('https://esm.sh/marked')
return parse(t ?? '')
}
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async s => {
const { parse } = await import('https://esm.sh/marked@12.0.1')
return parse(s)
}
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async md => {
const { parse } = await import('https://esm.sh/marked@12.0.1')
return parse(md)
}
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async m => (
(await import('https://esm.sh/marked@12.0.0'))
.parse(m)
)
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async md => {
const { marked } = await import('https://cdn.jsdelivr.net/npm/marked@12.0.1/lib/marked.esm.js')
return marked.parse(md)
}
export default parseMarkdown;

View File

@@ -0,0 +1,7 @@
let parser
const parseMarkdown = async (md) => {
parser ??= (await import('https://cdn.jsdelivr.net/npm/marked/+esm')).parse
return parser(md)
}
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async md => {
const { parse } = await import('https://cdn.jsdelivr.net/npm/marked@12/+esm')
return parse(md)
}
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async s => {
const { parse } = await import('https://esm.sh/marked@12.0.2')
return parse(s + '')
}
export default parseMarkdown;

View File

@@ -0,0 +1,5 @@
const parseMarkdown = async (md) => {
const { parse } = await import('https://cdn.jsdelivr.net/npm/marked@12.0.2/+esm')
return parse(md)
}
export default parseMarkdown;

View File

@@ -0,0 +1,9 @@
const parseMarkdown = async t => {
const u = 'https://esm.sh/',
[{ parse }, { default: d }] = await Promise.all([
import(u + 'marked@12.0.1'),
import(u + 'dompurify@3.0.9')
])
return d(self).sanitize(parse(t ?? ''))
}
export default parseMarkdown;

View File

@@ -0,0 +1,9 @@
const parseMarkdown = async t => {
const { parse: p } = await import('https://esm.sh/marked@12')
return p(t, {
async: false,
breaks: true,
gfm: true
})
}
export default parseMarkdown;

View File

@@ -0,0 +1,4 @@
const parseMarkdown = async s =>
(await import('https://cdn.jsdelivr.net/npm/marked/+esm'))
.parse(s)
export default parseMarkdown;

View File

@@ -0,0 +1,18 @@
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const { parse } = (await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')).default
const { data } = parse(csv, { header: true, skipEmptyLines: true })
return Object.entries(data.reduce((a, r) => {
if (r[fc] == fv) {
const k = r[gb], v = +r[ac] || 0
a[k] ??= { s: 0, c: 0 }
a[k].s += v
a[k].c++
}
return a
}, {})).map(([k, { s, c }]) => ({
[gb]: k,
result: op === 'count' ? c : op === 'avg' ? s / c : s
}))
}
export default processCSV;

View File

@@ -0,0 +1,17 @@
export const processCSV = async (str, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const [{ parse }, { filter, groupBy, map, sum }] = 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 { data } = parse(str, { header: true, skipEmptyLines: true })
const rows = filter(data, r => r[fc] == fv)
return map(groupBy(rows, gb), (group, key) => {
const vals = map(group, r => +r[ac] || 0)
const total = sum(vals)
const res = op === 'count' ? group.length : op === 'sum' ? total : total / group.length
return { [gb]: key, result: res }
})
}
export default processCSV;

View File

@@ -0,0 +1,18 @@
const processCSV = async (csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
const [{ csvParse }, { rollup, sum, mean }] = await Promise.all([
import('https://cdn.jsdelivr.net/npm/d3-dsv@3/+esm'),
import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
]);
const getValue = d => +d[aggregateColumn] || 0;
const data = csvParse(csvString).filter(d => d[filterColumn] == filterValue);
const aggregated = rollup(
data,
g => operation === 'count' ? g.length : (operation === 'sum' ? sum : mean)(g, getValue),
d => d[groupBy]
);
return Array.from(aggregated, ([key, result]) => ({ [groupBy]: key, result }));
};
export default processCSV;

View File

@@ -0,0 +1,22 @@
const processCSV = async (csvString, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')
const { data } = parse(csvString, { header: true, skipEmptyLines: true })
const groups = new Map()
for (const row of data) {
if (row[fc] == fv) {
const key = row[gb]
const val = +row[ac] || 0
const acc = groups.get(key) || { sum: 0, count: 0 }
acc.sum += val
acc.count += 1
groups.set(key, acc)
}
}
return Array.from(groups, ([key, { sum, count }]) => ({
[gb]: key,
result: op === 'count' ? count : op === 'sum' ? sum : sum / count
}))
}
export default processCSV;

View File

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

View File

@@ -0,0 +1,20 @@
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true })
const groups = data.reduce((acc, row) => {
if (row[fc] == fv) {
const k = row[gb], v = +row[ac] || 0
acc[k] = 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;

View File

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

View File

@@ -0,0 +1,21 @@
const processCSV = async (csvString, config) => {
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
const { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op } = config;
const acc = {};
parse(csvString, { header: true, skipEmptyLines: true }).data.forEach(row => {
if (row[fc] == fv) {
const key = row[gb];
const val = +row[ac] || 0;
const entry = acc[key] ??= { sum: 0, count: 0 };
entry.sum += val;
entry.count++;
}
});
return Object.entries(acc).map(([key, { sum, count }]) => ({
[gb]: key,
result: op === 'avg' ? sum / count : op === 'count' ? count : sum
}));
};
export default processCSV;

View File

@@ -0,0 +1,20 @@
const processCSV = async (csvStr, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const { csvParse } = await import('https://esm.sh/d3-dsv@3');
const groups = csvParse(csvStr).reduce((acc, row) => {
if (row[fc] == fv) {
const key = row[gb], val = +row[ac] || 0;
const entry = acc.get(key) || { s: 0, c: 0 };
entry.s += val;
entry.c++;
acc.set(key, entry);
}
return acc;
}, new Map());
return Array.from(groups, ([key, { s, c }]) => ({
[gb]: key,
result: op === 'count' ? c : op === 'sum' ? s : s / c
}));
};
export default processCSV;

View File

@@ -0,0 +1,13 @@
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;

View File

@@ -0,0 +1,21 @@
const processCSV = async (csvString, config) => {
const { csvParse } = await import('https://esm.sh/d3-dsv@3');
const { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op } = config;
const groups = csvParse(csvString).reduce((acc, row) => {
if (row[fc] == fv) {
const key = row[gb];
const val = +row[ac] || 0;
acc[key] = 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 === 'avg' ? sum / count : op === 'count' ? count : sum
}));
};
export default processCSV;

View File

@@ -0,0 +1,21 @@
const processCSV = async (csv, cfg) => {
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
const { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op } = cfg;
const grouped = Papa.parse(csv, { header: true, skipEmptyLines: true }).data.reduce((acc, row) => {
if (row[fc] == fv) {
const key = row[gb];
const val = +row[ac] || 0;
acc[key] = acc[key] || { sum: 0, count: 0 };
acc[key].sum += val;
acc[key].count++;
}
return acc;
}, {});
return Object.entries(grouped).map(([key, { sum, count }]) => ({
[gb]: key,
result: op === 'count' ? count : op === 'avg' ? sum / count : sum
}));
};
export default processCSV;

View File

@@ -0,0 +1,48 @@
const findAvailableSlots = async (calA, calB, { durationMinutes: dur, searchRange: rng, workHours: wh }) => {
const [djs, utc] = await Promise.all([
import('https://esm.sh/dayjs@1.11.10'),
import('https://esm.sh/dayjs@1.11.10/plugin/utc')
]).then(m => m.map(i => i.default));
djs.extend(utc);
const U = (d) => djs(d).utc();
const [wsH, wsM] = wh.start.split(':').map(Number);
const [weH, weM] = wh.end.split(':').map(Number);
const busy = [...calA, ...calB]
.map(s => ({ s: U(s.start), e: U(s.end) }))
.sort((a, b) => a.s - b.s)
.reduce((acc, c) => {
const last = acc[acc.length - 1];
if (last && c.s.diff(last.e) < 0) last.e = c.e.diff(last.e) > 0 ? c.e : last.e;
else acc.push(c);
return acc;
}, []);
const slots = [];
let curDay = U(rng.start).startOf('day');
const limit = U(rng.end);
while (curDay.isBefore(limit)) {
let wStart = curDay.hour(wsH).minute(wsM);
let wEnd = curDay.hour(weH).minute(weM);
if (wStart.isBefore(U(rng.start))) wStart = U(rng.start);
if (wEnd.isAfter(limit)) wEnd = limit;
let ptr = wStart;
while (ptr.add(dur, 'm').diff(wEnd) <= 0) {
const next = ptr.add(dur, 'm');
const clash = busy.find(b => ptr.isBefore(b.e) && next.isAfter(b.s));
if (clash) ptr = clash.e;
else {
slots.push({ start: ptr.format(), end: next.format() });
ptr = next;
}
}
curDay = curDay.add(1, 'day');
}
return slots;
};
export default findAvailableSlots;

View File

@@ -0,0 +1,44 @@
const findAvailableSlots = async (calA, calB, { durationMinutes: dur, searchRange: rng, workHours: wh }) => {
const { DateTime: DT, Interval: IV } = await import('https://cdn.jsdelivr.net/npm/luxon@3.4.4/+esm');
const z = { zone: 'utc' }, parse = s => DT.fromISO(s, z);
const range = IV.fromDateTimes(parse(rng.start), parse(rng.end));
const busy = [...calA, ...calB]
.map(s => IV.fromDateTimes(parse(s.start), parse(s.end)))
.filter(i => i.isValid)
.sort((a, b) => a.start - b.start);
const merged = busy.reduce((acc, curr) => {
const last = acc[acc.length - 1];
if (last && (last.overlaps(curr) || last.abutsStart(curr))) {
acc[acc.length - 1] = last.union(curr);
} else acc.push(curr);
return acc;
}, []);
const slots = [];
let day = range.start.startOf('day');
const [sH, sM] = wh.start.split(':'), [eH, eM] = wh.end.split(':');
while (day < range.end) {
const wStart = day.set({ hour: sH, minute: sM }), wEnd = day.set({ hour: eH, minute: eM });
let work = IV.fromDateTimes(wStart, wEnd).intersection(range);
if (work && work.isValid) {
let cursor = work.start;
while (cursor < work.end) {
const block = merged.find(b => b.end > cursor && b.start < work.end);
const limit = (block && block.start < work.end) ? block.start : work.end;
while (cursor.plus({ minutes: dur }) <= limit) {
slots.push({ start: cursor.toISO(), end: cursor.plus({ minutes: dur }).toISO() });
cursor = cursor.plus({ minutes: dur });
}
cursor = block ? (block.end > cursor ? block.end : cursor) : work.end;
}
}
day = day.plus({ days: 1 });
}
return slots;
};
export default findAvailableSlots;

View File

@@ -0,0 +1,55 @@
export const findAvailableSlots = async (calendarA, calendarB, { durationMinutes, searchRange, workHours }) => {
const { default: dayjs } = await import('https://esm.sh/dayjs');
const { default: utc } = await import('https://esm.sh/dayjs/plugin/utc');
dayjs.extend(utc);
const parse = (d) => dayjs.utc(d);
const msDuration = durationMinutes * 60000;
const rangeStart = parse(searchRange.start);
const rangeEnd = parse(searchRange.end);
let busy = [...calendarA, ...calendarB]
.map(s => ({ s: parse(s.start).valueOf(), e: parse(s.end).valueOf() }))
.sort((a, b) => a.s - b.s)
.reduce((acc, curr) => {
const last = acc[acc.length - 1];
if (last && curr.s < last.e) last.e = Math.max(last.e, curr.e);
else acc.push(curr);
return acc;
}, []);
const slots = [];
let currentDay = rangeStart.startOf('day');
const finalDay = rangeEnd.endOf('day');
while (currentDay.isBefore(finalDay) || currentDay.isSame(finalDay)) {
const dateStr = currentDay.format('YYYY-MM-DD');
let start = parse(`${dateStr}T${workHours.start}`);
let end = parse(`${dateStr}T${workHours.end}`);
if (start.isBefore(rangeStart)) start = rangeStart;
if (end.isAfter(rangeEnd)) end = rangeEnd;
let ptr = start.valueOf();
const limit = end.valueOf();
while (ptr + msDuration <= limit) {
const slotEnd = ptr + msDuration;
const conflict = busy.find(b => b.s < slotEnd && b.e > ptr);
if (conflict) {
ptr = conflict.e;
} else {
slots.push({
start: dayjs(ptr).utc().format(),
end: dayjs(slotEnd).utc().format()
});
ptr += msDuration;
}
}
currentDay = currentDay.add(1, 'day');
}
return slots;
};
export default findAvailableSlots;

Some files were not shown because too many files have changed in this diff Show More