mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-03-17 03:11:01 +00:00
Docs: Update Gemini benchmark results
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
11
tests/3_lis/outputs_gemini/gemini-3-pro-preview TEMP_0.6.js
Normal file
11
tests/3_lis/outputs_gemini/gemini-3-pro-preview TEMP_0.6.js
Normal 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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
11
tests/3_lis/outputs_gemini/gemini-3-pro-preview TEMP_0.js
Normal file
11
tests/3_lis/outputs_gemini/gemini-3-pro-preview TEMP_0.js
Normal 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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,4 @@
|
||||
const calculateDeterminant = async m =>
|
||||
(await import('https://cdn.jsdelivr.net/npm/mathjs@12/+esm'))
|
||||
.det(m)
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,4 @@
|
||||
const calculateDeterminant = async m =>
|
||||
(await import('https://esm.sh/mathjs'))
|
||||
.det(m)
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,4 @@
|
||||
const calculateDeterminant = async m =>
|
||||
(await import('https://cdn.jsdelivr.net/npm/mathjs/+esm'))
|
||||
.det(m)
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,5 @@
|
||||
const calculateDeterminant = async m => {
|
||||
const { det } = await import('https://esm.sh/mathjs@12')
|
||||
return det(m)
|
||||
}
|
||||
export default calculateDeterminant;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,5 @@
|
||||
const calculateDeterminant = async m => {
|
||||
const { det } = await import('https://esm.sh/mathjs')
|
||||
return det(m)
|
||||
}
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,5 @@
|
||||
const calculateDeterminant = async m => {
|
||||
const { det } = await import('https://esm.sh/mathjs@12')
|
||||
return det(m)
|
||||
}
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,5 @@
|
||||
const calculateDeterminant = async m => {
|
||||
const { det } = await import('https://esm.sh/mathjs@12')
|
||||
return det(m)
|
||||
}
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,5 @@
|
||||
const calculateDeterminant = async m => {
|
||||
const { det } = await import('https://esm.sh/mathjs')
|
||||
return det(m)
|
||||
}
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,4 @@
|
||||
const calculateDeterminant = async m =>
|
||||
(await import('https://cdn.jsdelivr.net/npm/mathjs@12/+esm'))
|
||||
.det(m)
|
||||
export default calculateDeterminant;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,5 @@
|
||||
const parseMarkdown = async t => {
|
||||
const { parse } = await import('https://esm.sh/marked')
|
||||
return parse(t ?? '')
|
||||
}
|
||||
export default parseMarkdown;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,5 @@
|
||||
const parseMarkdown = async m => (
|
||||
(await import('https://esm.sh/marked@12.0.0'))
|
||||
.parse(m)
|
||||
)
|
||||
export default parseMarkdown;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,4 @@
|
||||
const parseMarkdown = async s =>
|
||||
(await import('https://cdn.jsdelivr.net/npm/marked/+esm'))
|
||||
.parse(s)
|
||||
export default parseMarkdown;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,44 @@
|
||||
export const findAvailableSlots = async (calA, calB, { durationMinutes: dur, searchRange, workHours }) => {
|
||||
const { DateTime, Interval } = await import('https://esm.sh/luxon@3.4.4');
|
||||
const utc = (t) => DateTime.fromISO(t, { zone: 'utc' });
|
||||
const bounds = Interval.fromDateTimes(utc(searchRange.start), utc(searchRange.end));
|
||||
|
||||
const busy = [...calA, ...calB]
|
||||
.map(s => Interval.fromDateTimes(utc(s.start), utc(s.end)))
|
||||
.filter(i => i.isValid && i.overlaps(bounds))
|
||||
.sort((a, b) => a.start - b.start)
|
||||
.reduce((acc, cur) => {
|
||||
const last = acc.at(-1);
|
||||
return last && last.end >= cur.start ? [...acc.slice(0, -1), last.union(cur)] : [...acc, cur];
|
||||
}, []);
|
||||
|
||||
const slots = [];
|
||||
let cursor = bounds.start.startOf('day');
|
||||
|
||||
while (cursor <= bounds.end) {
|
||||
const [sH, sM] = workHours.start.split(':');
|
||||
const [eH, eM] = workHours.end.split(':');
|
||||
const workInt = Interval.fromDateTimes(
|
||||
cursor.set({ hour: sH, minute: sM }),
|
||||
cursor.set({ hour: eH, minute: eM })
|
||||
).intersection(bounds);
|
||||
|
||||
if (workInt?.isValid) {
|
||||
let free = [workInt];
|
||||
busy.filter(b => b.overlaps(workInt)).forEach(b => free = free.flatMap(f => f.difference(b)));
|
||||
|
||||
free.forEach(f => {
|
||||
let s = f.start;
|
||||
while (s.plus({ minutes: dur }) <= f.end) {
|
||||
const e = s.plus({ minutes: dur });
|
||||
slots.push({ start: s.toISO(), end: e.toISO() });
|
||||
s = e;
|
||||
}
|
||||
});
|
||||
}
|
||||
cursor = cursor.plus({ days: 1 });
|
||||
}
|
||||
|
||||
return slots;
|
||||
};
|
||||
export default findAvailableSlots;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user