Refactor: Remove stale benchmark outputs

This commit is contained in:
github-actions[bot]
2026-03-05 07:51:26 +00:00
parent 47ccd20b71
commit 35f7fc8803
35 changed files with 0 additions and 882 deletions

View File

@@ -1,20 +0,0 @@
let _scryptMod
let _enc = new TextEncoder
let _getScrypt = () =>
_scryptMod ||= import("https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm")
.then(m => (m.scrypt && m) || m.default || m)
let _toHex = u8 =>
Array.from(u8, b => b.toString(16).padStart(2, "0")).join("")
async function hashPassword(password, salt) {
let { scrypt } = await _getScrypt()
let pw = _enc.encode(password)
let sa = _enc.encode(salt)
let hash = await scrypt(pw, sa, 1024, 8, 1, 32)
return _toHex(hash)
}
export default hashPassword;
// Generation time: 13.034s
// Result: PASS

View File

@@ -1,13 +0,0 @@
async function hashPassword(p, s) {
const e = new TextEncoder(),
pU = e.encode(p),
sU = e.encode(s),
{ scrypt } = await import('https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/dist/scrypt.esm.js');
const dk = await scrypt(pU, sU, 1024, 8, 1, 32);
let h = '';
for (let i = 0; i < dk.length; i++) h += dk[i].toString(16).padStart(2, '0');
return h;
}
export default hashPassword;
// Generation time: 1.126s
// Result: FAIL

View File

@@ -1,9 +0,0 @@
const hashPassword = async (password, salt) => {
const { default: scrypt } = await import('https://esm.sh/scrypt-js');
const encode = s => new TextEncoder().encode(s);
const hash = await scrypt(encode(password), encode(salt), 1024, 8, 1, 32);
return [...hash].map(b => b.toString(16).padStart(2, '0')).join('');
};
export default hashPassword;
// Generation time: 76.203s
// Result: FAIL

View File

@@ -1,20 +0,0 @@
let turf$;
async function analyzeGPS(readings, boundary) {
turf$ ||= import("https://esm.sh/@turf/turf@6.5.0");
const { point, booleanPointInPolygon, lineString, length } = await turf$;
const coords = (readings || [])
.filter(r => r && Array.isArray(r.loc) && r.loc.length === 2 && Number.isFinite(r.ts))
.filter(r => booleanPointInPolygon(point(r.loc), boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc);
if (coords.length < 2) return 0;
const km = length(lineString(coords), { units: "kilometers" });
return +km.toFixed(2);
}
export default analyzeGPS;
// Generation time: 7.395s
// Result: PASS

View File

@@ -1,14 +0,0 @@
async function analyzeGPS(readings, boundary) {
const turf = await import('https://cdn.skypack.dev/@turf/turf');
const inside = readings.filter(r =>
turf.booleanPointInPolygon(turf.point(r.loc), boundary, { ignoreBoundary: true })
);
if (inside.length < 2) return 0;
inside.sort((a, b) => a.ts - b.ts);
const line = turf.lineString(inside.map(r => r.loc));
const km = turf.length(line, { units: 'kilometers' });
return Math.round(km * 100) / 100;
}
export default analyzeGPS;
// Generation time: 1.710s
// Result: PASS

View File

@@ -1,11 +0,0 @@
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))
.sort((a, b) => a.ts - b.ts)
.map(r => r.loc);
return pts.length < 2 ? 0 : Math.round(t.length(t.lineString(pts)) * 100) / 100;
};
export default analyzeGPS;
// Generation time: 93.284s
// Result: PASS

View File

@@ -1,45 +0,0 @@
async function computeMST(tomlStr) {
const [{ parse }, { Heap }, table] = await Promise.all([
import('https://unpkg.com/smol-toml@latest/dist/smol-toml.esm.js'),
import('https://unpkg.com/mnemonist@latest/dist/mnemonist.esm.js'),
import('https://unpkg.com/text-table@latest/index.js')
])
const { edges = [] } = parse(tomlStr)
const heap = new Heap((a, b) => a.weight - b.weight)
const nodes = new Set()
for (const e of edges) {
heap.push(e)
nodes.add(e.from)
nodes.add(e.to)
}
const parent = {}
const rank = {}
for (const n of nodes) {
parent[n] = n
rank[n] = 0
}
const find = x => (parent[x] === x ? x : (parent[x] = find(parent[x])))
const union = (a, b) => {
a = find(a)
b = find(b)
if (a === b) return false
if (rank[a] < rank[b]) [a, b] = [b, a]
parent[b] = a
if (rank[a] === rank[b]) rank[a]++
return true
}
const mst = []
let total = 0
while (mst.length < nodes.size - 1 && heap.size > 0) {
const e = heap.pop()
if (union(e.from, e.to)) {
mst.push([e.from, e.to, String(e.weight)])
total += e.weight
}
}
const tbl = table([['From', 'To', 'Weight'], ...mst])
return { table: tbl, totalWeight: total }
}
export default computeMST;
// Generation time: 1.686s
// Result: FAIL

View File

@@ -1,50 +0,0 @@
async function computeMST(tomlStr) {
const [{ parse }, { Heap }, { default: textTable }] = await Promise.all([
import('https://esm.sh/smol-toml'),
import('https://esm.sh/mnemonist'),
import('https://esm.sh/text-table')
]);
const { edges } = parse(tomlStr);
const nodes = new Set(edges.flatMap(e => [e.from, e.to]));
const parent = {}, rank = {};
for (const n of nodes) {
parent[n] = n;
rank[n] = 0;
}
const find = x => parent[x] === x ? x : (parent[x] = find(parent[x]));
const union = (a, b) => {
const rootA = find(a), rootB = find(b);
if (rootA === rootB) return false;
if (rank[rootA] < rank[rootB]) parent[rootA] = rootB;
else if (rank[rootA] > rank[rootB]) parent[rootB] = rootA;
else { parent[rootB] = rootA; rank[rootA]++; }
return true;
};
const heap = new Heap((a, b) => a.weight - b.weight);
edges.forEach(e => heap.push(e));
const mst = [];
let totalWeight = 0;
while (heap.size) {
const { from, to, weight } = heap.pop();
if (union(from, to)) {
mst.push([from, to, String(weight)]);
totalWeight += weight;
if (mst.length === nodes.size - 1) break;
}
}
return {
table: textTable([['From', 'To', 'Weight'], ...mst]),
totalWeight
};
}
export default computeMST;
// Generation time: 200.325s
// Result: PASS

View File

@@ -1,39 +0,0 @@
export async function findShortestPath(graph, start, end) {
if (start === end) return 0
if (!graph || typeof graph !== "object") return Infinity
const { default: PriorityQueue } = await import(
"https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm"
)
const dist = Object.create(null)
dist[start] = 0
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] })
pq.queue([0, start])
while (pq.length) {
const [d, u] = pq.dequeue()
if (d !== dist[u]) continue
if (u === end) return d
const nbrs = graph[u]
if (!nbrs || typeof nbrs !== "object") continue
for (const v in nbrs) {
const w = +nbrs[v]
if (!Number.isFinite(w) || w < 0) continue
const nd = d + w
const cur = dist[v]
if (cur === undefined || nd < cur) {
dist[v] = nd
pq.queue([nd, v])
}
}
}
return Infinity
}
export default findShortestPath;
// Generation time: 6.889s
// Result: PASS

View File

@@ -1,26 +0,0 @@
async function findShortestPath(g, s, t) {
if (!(s in g) || !(t in g)) return Infinity;
const { PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const d = {}, v = new Set();
for (const n in g) d[n] = Infinity;
d[s] = 0;
const q = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
q.queue([0, s]);
while (q.length) {
const [dist, u] = q.dequeue();
if (v.has(u)) continue;
if (u === t) return dist;
v.add(u);
for (const [nbr, w] of Object.entries(g[u])) {
const nd = dist + w;
if (nd < d[nbr]) {
d[nbr] = nd;
q.queue([nd, nbr]);
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 2.281s
// Result: FAIL

View File

@@ -1,25 +0,0 @@
const findShortestPath = async (graph, start, end) => {
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
const dist = { [start]: 0 };
const pq = new PriorityQueue({ comparator: (a, b) => a.w - b.w });
pq.queue({ v: start, w: 0 });
while (pq.length) {
const { v, w } = pq.dequeue();
if (v === end) return w;
if (w > (dist[v] ?? Infinity)) continue;
const edges = graph[v] || {};
for (const n in edges) {
const nd = w + edges[n];
if (nd < (dist[n] ?? Infinity)) {
dist[n] = nd;
pq.queue({ v: n, w: nd });
}
}
}
return Infinity;
};
export default findShortestPath;
// Generation time: 136.164s
// Result: PASS

View File

@@ -1,30 +0,0 @@
async function findConvexHull(points) {
if (!Array.isArray(points)) throw new TypeError("points must be an array")
const { default: _ } = await import("https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm")
const eq = (a, b) => a.x === b.x && a.y === b.y
const cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
const pts = _.uniqWith(_.sortBy(points, ["x", "y"]), eq)
if (pts.length < 2) return pts.slice()
const lower = []
for (const p of pts) {
while (lower.length > 1 && cross(lower.at(-2), lower.at(-1), p) <= 0) lower.pop()
lower.push(p)
}
const upper = []
for (let i = pts.length; i--;) {
const p = pts[i]
while (upper.length > 1 && cross(upper.at(-2), upper.at(-1), p) <= 0) upper.pop()
upper.push(p)
}
lower.pop()
upper.pop()
return lower.concat(upper)
}
export default findConvexHull;
// Generation time: 15.278s
// Result: PASS

View File

@@ -1,21 +0,0 @@
async function findConvexHull(p){
const _=await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
const s=_.sortBy(_.uniqBy(p,q=>q.x+','+q.y),['x','y']);
const c=(o,a,b)=> (a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
const L=[];
for(const q of s){
while(L.length>1 && c(L[L.length-2],L[L.length-1],q)<=0) L.pop();
L.push(q);
}
const U=[];
for(let i=s.length-1;i>=0;i--){
const q=s[i];
while(U.length>1 && c(U[U.length-2],U[U.length-1],q)<=0) U.pop();
U.push(q);
}
U.pop();L.pop();
return L.concat(U);
}
export default findConvexHull;
// Generation time: 1.623s
// Result: PASS

View File

@@ -1,28 +0,0 @@
const findConvexHull = async points => {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
const pts = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
if (pts.length < 3) return pts;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const lower = [];
for (const p of pts) {
while (lower.length > 1 && cross(lower.at(-2), lower.at(-1), p) <= 0) lower.pop();
lower.push(p);
}
const upper = [];
for (let i = pts.length - 1; i >= 0; i--) {
const p = pts[i];
while (upper.length > 1 && cross(upper.at(-2), upper.at(-1), p) <= 0) upper.pop();
upper.push(p);
}
lower.pop();
upper.pop();
return lower.concat(upper);
};
export default findConvexHull;
// Generation time: 170.869s
// Result: PASS

View File

@@ -1,15 +0,0 @@
let _d3
async function findLISLength(a) {
if (!Array.isArray(a)) throw new TypeError("Expected an array of numbers")
let { bisectLeft: b } = await (_d3 ||= import("https://cdn.jsdelivr.net/npm/d3-array@3/+esm"))
let t = []
for (let x of a) t[b(t, x)] = x
return t.length
}
export default findLISLength;
// Generation time: 9.821s
// Result: PASS

View File

@@ -1,18 +0,0 @@
const findLISLength = async arr => {
if (!Array.isArray(arr)) throw new TypeError('Input must be an array');
const { bisectLeft } = await import(
'https://cdn.jsdelivr.net/npm/d3-array@3.2.4/+esm'
);
const tails = [];
for (const v of arr) {
const i = bisectLeft(tails, v);
if (i === tails.length) tails.push(v);
else tails[i] = v;
}
return tails.length;
};
export default findLISLength;
// Generation time: 0.883s
// Result: PASS

View File

@@ -1,15 +0,0 @@
const findLISLength = async nums => {
const { bisectLeft } = await import('https://esm.sh/d3-array')
const tails = []
for (const n of nums) {
const i = bisectLeft(tails, n)
if (i === tails.length) tails.push(n)
else tails[i] = n
}
return tails.length
}
export default findLISLength;
// Generation time: 197.616s
// Result: PASS

View File

@@ -1,7 +0,0 @@
export async function renderTemplate(t, d = {}) {
let { default: H } = await import("https://esm.sh/handlebars@4.7.8")
return H.compile(String(t))({ ...d })
}
export default renderTemplate;
// Generation time: 2.200s
// Result: PASS

View File

@@ -1,8 +0,0 @@
let hb
async function renderTemplate(t, d) {
hb = hb || (await import('https://cdn.jsdelivr.net/npm/handlebars@4.7.7/dist/handlebars.esm.js')).default
return hb.compile(t)(d)
}
export default renderTemplate;
// Generation time: 1.117s
// Result: FAIL

View File

@@ -1,7 +0,0 @@
const renderTemplate = async (t, d) => {
const { default: h } = await import('https://esm.sh/handlebars');
return h.compile(t)(d);
};
export default renderTemplate;
// Generation time: 110.510s
// Result: PASS

View File

@@ -1,17 +0,0 @@
const _mdLibs=globalThis.__mdLibs||=(()=> {
const md="https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/dist/markdown-it.min.mjs"
const pur="https://cdn.jsdelivr.net/npm/dompurify@3.0.6/dist/purify.es.mjs"
return Promise.all([import(md),import(pur)]).then(([{default:MarkdownIt},{default:DOMPurify}])=>({
md:new MarkdownIt({html:false,linkify:true,breaks:false}),
pur:DOMPurify
}))
})()
async function parseMarkdown(markdown){
const {md,pur}=await _mdLibs
const html=md.render(String(markdown??""))
return pur.sanitize(html,{USE_PROFILES:{html:true}})
}
export default parseMarkdown;
// Generation time: 22.022s
// Result: FAIL

View File

@@ -1,8 +0,0 @@
async function parseMarkdown(s){
const MarkdownIt = (await import('https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.esm.js')).default;
const md = new MarkdownIt({html:false,linkify:true,typographer:true});
return md.render(s);
}
export default parseMarkdown;
// Generation time: 1.373s
// Result: FAIL

View File

@@ -1,7 +0,0 @@
const parseMarkdown = async md => {
const { parse } = await import('https://esm.sh/marked')
return parse(md)
}
export default parseMarkdown;
// Generation time: 137.282s
// Result: PASS

View File

@@ -1,47 +0,0 @@
async function processCSV(csv, cfg) {
cfg ||= {};
let {
filterColumn,
filterValue,
groupBy,
aggregateColumn,
operation
} = cfg;
if (typeof csv != "string" || !groupBy || !operation) return [];
let [{ default: Papa }, { rollups }] = await Promise.all([
import("https://esm.sh/papaparse@5.4.1"),
import("https://esm.sh/d3-array@3.2.4")
]);
let parsed = Papa.parse(csv, { header: true, skipEmptyLines: true });
if (parsed.errors?.length) throw new Error(parsed.errors[0].message || "CSV parse error");
let rows = parsed.data || [];
if (filterColumn != null) rows = rows.filter(r => r?.[filterColumn] == filterValue);
let num = v => {
v = Number(v);
return Number.isFinite(v) ? v : 0;
};
let agg = op => {
if (op === "count") return v => v.length;
let sum = v => {
let s = 0;
for (let i = 0; i < v.length; i++) s += num(v[i]?.[aggregateColumn]);
return s;
};
if (op === "avg") return v => v.length ? sum(v) / v.length : 0;
return v => sum(v);
};
let reduce = agg(operation);
return rollups(rows, reduce, d => d?.[groupBy]).map(([k, result]) => ({ [groupBy]: k, result }));
}
export default processCSV;
// Generation time: 22.087s
// Result: PASS

View File

@@ -1,24 +0,0 @@
async function processCSV(csv, cfg) {
const [{csvParse}] = await Promise.all([
import('https://cdn.skypack.dev/d3-dsv')
]);
const _ = await import('https://cdn.skypack.dev/lodash');
const rows = csvParse(csv);
const filtered = rows.filter(r => r[cfg.filterColumn] == cfg.filterValue);
const groups = _.groupBy(filtered, cfg.groupBy);
return Object.entries(groups).map(([k, g]) => {
let res;
if (cfg.operation === 'count') {
res = g.length;
} else {
const sum = g.reduce((s, r) => s + (Number(r[cfg.aggregateColumn]) || 0), 0);
res = cfg.operation === 'sum' ? sum : sum / g.length;
}
return { [cfg.groupBy]: k, result: res };
});
}
export default processCSV;
// Generation time: 1.891s
// Result: PASS

View File

@@ -1,18 +0,0 @@
const processCSV = async (csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
const { default: Papa } = await import('https://esm.run/papaparse')
const { data } = Papa.parse(csv, { header: true })
const grouped = data.filter(r => r[fc] == fv).reduce((a, r) => {
const k = r[gb], v = +r[ac] || 0
a[k] = a[k] || { s: 0, c: 0 }
a[k].s += v
a[k].c++
return a
}, {})
return Object.entries(grouped).map(([k, { s, c }]) => ({
[gb]: k,
result: op === 'count' ? c : op === 'sum' ? s : s / c
}))
}
export default processCSV;
// Generation time: 257.221s
// Result: PASS

View File

@@ -1,94 +0,0 @@
const _luxon = import("https://cdn.jsdelivr.net/npm/luxon@3.5.0/+esm");
const findAvailableSlots = async (calA = [], calB = [], c = {}) => {
const { DateTime } = await _luxon;
const durMin = c?.durationMinutes;
const sr = c?.searchRange;
const wh = c?.workHours;
if (!Number.isFinite(durMin) || durMin <= 0) throw new TypeError("Invalid durationMinutes");
if (!sr?.start || !sr?.end) throw new TypeError("Invalid searchRange");
if (!wh?.start || !wh?.end) throw new TypeError("Invalid workHours");
const parseHm = s => {
const m = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(s).trim());
if (!m) throw new TypeError("Invalid workHours time");
return { h: +m[1], m: +m[2] };
};
const rs = DateTime.fromISO(sr.start, { zone: "utc" });
const re = DateTime.fromISO(sr.end, { zone: "utc" });
if (!rs.isValid || !re.isValid) throw new TypeError("Invalid searchRange ISO");
const rS = rs.toMillis(), rE = re.toMillis();
if (!(rE > rS)) return [];
const ws = parseHm(wh.start), we = parseHm(wh.end);
if (we.h * 60 + we.m <= ws.h * 60 + ws.m) throw new TypeError("workHours.end must be after workHours.start");
const durMs = Math.round(durMin * 60000);
if (durMs <= 0) throw new TypeError("Invalid durationMinutes");
const norm = x => {
const s = DateTime.fromISO(x.start, { zone: "utc" });
const e = DateTime.fromISO(x.end, { zone: "utc" });
if (!s.isValid || !e.isValid) return null;
let a = s.toMillis(), b = e.toMillis();
if (!(b > a)) return null;
if (b <= rS || a >= rE) return null;
a = Math.max(a, rS);
b = Math.min(b, rE);
return b > a ? [a, b] : null;
};
const mergedBusy = (() => {
const xs = [...calA, ...calB].map(norm).filter(Boolean).sort((p, q) => p[0] - q[0] || p[1] - q[1]);
if (!xs.length) return [];
const out = [];
let [cs, ce] = xs[0];
for (let i = 1; i < xs.length; i++) {
const [s, e] = xs[i];
if (s <= ce) ce = Math.max(ce, e);
else out.push([cs, ce]), (cs = s), (ce = e);
}
out.push([cs, ce]);
return out;
})();
const free = (() => {
const out = [];
let cur = rS;
for (const [s, e] of mergedBusy) {
if (s > cur) out.push([cur, s]);
cur = Math.max(cur, e);
if (cur >= rE) break;
}
if (cur < rE) out.push([cur, rE]);
return out;
})();
const iso = ms => DateTime.fromMillis(ms, { zone: "utc" }).toISO({ suppressMilliseconds: true });
const out = [];
const dayMs = 86400000;
for (const [fs, fe] of free) {
let d0 = DateTime.fromMillis(fs, { zone: "utc" }).startOf("day").toMillis();
const d1 = DateTime.fromMillis(fe - 1, { zone: "utc" }).startOf("day").toMillis();
for (let d = d0; d <= d1; d += dayMs) {
const base = DateTime.fromMillis(d, { zone: "utc" });
const wS = base.set({ hour: ws.h, minute: ws.m, second: 0, millisecond: 0 }).toMillis();
const wE = base.set({ hour: we.h, minute: we.m, second: 0, millisecond: 0 }).toMillis();
const a = Math.max(fs, wS);
const b = Math.min(fe, wE);
for (let t = a; t + durMs <= b; t += durMs) out.push({ start: iso(t), end: iso(t + durMs) });
}
}
return out;
};
export default findAvailableSlots;
// Generation time: 32.586s
// Result: PASS

View File

@@ -1,40 +0,0 @@
async function findAvailableSlots(c1, c2, { durationMinutes: d, searchRange: { start: rs, end: re }, workHours: { start: whs, end: whe } }) {
const dayjs = (await import('https://cdn.skypack.dev/dayjs')).default;
const utc = (await import('https://cdn.skypack.dev/dayjs/plugin/utc')).default;
dayjs.extend(utc);
const to = s => dayjs.utc(s);
const busy = [...c1, ...c2].map(o => ({ s: to(o.start), e: to(o.end) })).sort((a, b) => a.s - b.s);
const merged = [];
for (const b of busy) {
if (!merged.length || b.s.isAfter(merged[merged.length - 1].e)) merged.push(b);
else if (b.e.isAfter(merged[merged.length - 1].e)) merged[merged.length - 1].e = b.e;
}
const sr = to(rs), er = to(re);
const free = [];
let cur = sr;
for (const b of merged) {
if (b.e.isAfter(cur)) {
if (b.s.isAfter(cur)) free.push({ s: cur, e: b.s });
cur = dayjs.max(cur, b.e);
}
}
if (cur.isBefore(er)) free.push({ s: cur, e: er });
const [whsh, whsm] = whs.split(':').map(Number);
const [wheh, whom] = whe.split(':').map(Number);
const slots = [];
for (let day = sr.startOf('day'); day.isBefore(er); day = day.add(1, 'day')) {
const ws = day.set('hour', whsh).set('minute', whsm);
const we = day.set('hour', wheh).set('minute', whom);
for (const f of free) {
const s = dayjs.max(f.s, ws);
const e = dayjs.min(f.e, we);
for (let t = s; !t.add(d, 'minute').isAfter(e); t = t.add(d, 'minute')) {
slots.push({ start: t.toISOString(), end: t.add(d, 'minute').toISOString() });
}
}
}
return slots;
}
export default findAvailableSlots;
// Generation time: 3.739s
// Result: FAIL

View File

@@ -1,46 +0,0 @@
const findAvailableSlots = async (cal1, cal2, { durationMinutes, searchRange, workHours }) => {
const dayjs = (await import('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js')).default;
dayjs.extend((await import('https://cdn.jsdelivr.net/npm/dayjs@1/plugin/utc.js')).default);
const min = s => (s = s.split(':'), +s[0] * 60 + +s[1]);
const ts = s => dayjs.utc(s).valueOf();
const iso = t => new Date(t).toISOString();
const dur = durationMinutes * 60000;
const ws = min(workHours.start), we = min(workHours.end);
const rs = ts(searchRange.start), re = ts(searchRange.end);
const merged = [...cal1, ...cal2]
.map(x => ({ s: ts(x.start), e: ts(x.end) }))
.sort((a, b) => a.s - b.s)
.reduce((a, c) => {
if (a.length && c.s <= a[a.length - 1].e) a[a.length - 1].e = Math.max(a[a.length - 1].e, c.e);
else a.push(c);
return a;
}, []);
const fill = (start, end) => {
let t = start, res = [];
while (t + dur <= end) {
const sod = dayjs.utc(t).startOf('day').valueOf();
const s = sod + ws * 60000, e = sod + we * 60000;
if (t < s) t = s;
if (t >= e) { t = sod + 86400000; continue; }
if (t + dur <= e) {
if (t + dur <= end) res.push({ start: iso(t), end: iso(t + dur) }), t += dur;
else break;
} else t = sod + 86400000;
}
return res;
};
let curr = rs, slots = [];
merged.forEach(b => {
if (b.s > curr) slots.push(...fill(curr, Math.min(b.s, re)));
curr = Math.max(curr, b.e);
});
if (curr < re) slots.push(...fill(curr, re));
return slots;
};
export default findAvailableSlots;
// Generation time: 508.729s
// Result: FAIL

View File

@@ -1,42 +0,0 @@
let _ajvP
const _getAjv = () =>
_ajvP ||= (async () => {
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
import("https://cdn.jsdelivr.net/npm/ajv@8.17.1/dist/ajv.mjs"),
import("https://cdn.jsdelivr.net/npm/ajv-formats@3.0.1/dist/ajv-formats.mjs")
])
const ajv = new Ajv({
allErrors: true,
strict: false,
allowUnionTypes: true,
loadSchema: async u => (await fetch(u, { credentials: "same-origin" })).json()
})
addFormats(ajv)
return ajv
})()
const _fmtErr = e =>
[e.instancePath || "/", e.message, e.params && Object.keys(e.params).length ? JSON.stringify(e.params) : ""]
.filter(Boolean)
.join(" ")
const validateJSON = async (data, schema) => {
const ajv = await _getAjv()
let validate
try {
validate = await ajv.compileAsync(schema)
} catch {
validate = ajv.compile(schema)
}
const valid = !!validate(data)
const errors = valid ? [] : (validate.errors || []).map(_fmtErr)
return { valid, errors }
}
export default validateJSON;
// Generation time: 12.999s
// Result: FAIL

View File

@@ -1,11 +0,0 @@
async function validateJSON(d, s) {
const {default: Ajv} = await import('https://cdn.jsdelivr.net/npm/ajv@8/dist/ajv.esm.js');
const {default: addFormats} = await import('https://cdn.jsdelivr.net/npm/ajv-formats@2/dist/ajv-formats.esm.js');
const v = new Ajv({allErrors: true, strict: false});
addFormats(v);
const ok = v.compile(s)(d);
return {valid: ok, errors: ok ? [] : v.errors.map(e => e.message)};
}
export default validateJSON;
// Generation time: 1.295s
// Result: FAIL

View File

@@ -1,12 +0,0 @@
const validateJSON = async (json, schema) => {
const { default: Ajv } = await import('https://esm.sh/ajv');
const validate = new Ajv().compile(schema);
const valid = validate(json);
return {
valid,
errors: valid ? [] : validate.errors.map(e => `${e.instancePath} ${e.message}`)
};
};
export default validateJSON;
// Generation time: 103.740s
// Result: PASS

View File

@@ -1,48 +0,0 @@
async function createStreamVisualizer(asyncIterable, o = {}) {
let {
maxPoints = 500,
alpha = 0.2,
width = 600,
height = 200,
yDomain = [0, 1]
} = o
alpha = +alpha
if (!(alpha >= 0 && alpha <= 1)) alpha = 0.2
let d3 = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm")
let data = [], ema, seeded = false
for await (let p of asyncIterable) {
let timestamp, value
if (Array.isArray(p)) [timestamp, value] = p
else if (p && typeof p == "object") ({ timestamp, value } = p)
else (timestamp = Date.now()), (value = p)
timestamp = +timestamp
value = +value
if (!seeded) (ema = value), (seeded = true)
else ema = alpha * value + (1 - alpha) * ema
data.push({ timestamp, value, ema })
if (data.length > maxPoints) data.splice(0, data.length - maxPoints)
}
let path = ""
if (data.length) {
let t0 = data[0].timestamp, t1 = data.at(-1).timestamp
if (t0 === t1) t1 = t0 + 1
let x = d3.scaleLinear().domain([t0, t1]).range([0, width])
let y = d3.scaleLinear().domain(yDomain).range([height, 0])
path = d3.line().x(d => x(d.timestamp)).y(d => y(d.ema))(data) || ""
}
return { data, path }
}
export default createStreamVisualizer;
// Generation time: 18.105s
// Result: PASS

View File

@@ -1,17 +0,0 @@
async function createStreamVisualizer(src,{maxPoints=500,alpha=.5,width=800,height=600,yDomain}){
const d3=await import('https://cdn.jsdelivr.net/npm/d3@7')
const d=[];let e
for await(const{timestamp:t,value:v}of src){
e=e===undefined?v:alpha*v+(1-alpha)*e
d.push({timestamp:t,value:v,ema:e})
if(d.length>maxPoints)d.shift()
}
if(!d.length)return{data:[],path:''}
const x=d3.scaleLinear().domain([d[0].timestamp,d.at(-1).timestamp]).range([0,width])
const y=d3.scaleLinear().domain(yDomain||[d3.min(d,d=>d.ema),d3.max(d,d=>d.ema)]).range([height,0])
const p=d3.line().x(v=>x(v.timestamp)).y(v=>y(v.ema)).curve(d3.curveLinear)
return{data:d,path:p(d)}
}
export default createStreamVisualizer;
// Generation time: 1.456s
// Result: FAIL

View File

@@ -1,30 +0,0 @@
const createStreamVisualizer = async (iterable, { maxPoints, alpha, width, height, yDomain }) => {
const d3 = await import('https://esm.sh/d3');
const data = [];
let ema;
for await (const { timestamp, value } of iterable) {
ema = ema == null ? value : alpha * value + (1 - alpha) * ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
}
if (!data.length) return { data, path: '' };
const x = d3.scaleLinear()
.domain([data[0].timestamp, data.at(-1).timestamp])
.range([0, width]);
const y = d3.scaleLinear()
.domain(yDomain)
.range([height, 0]);
const path = d3.line()
.x(d => x(d.timestamp))
.y(d => y(d.ema))
(data);
return { data, path };
};
export default createStreamVisualizer;
// Generation time: 253.115s
// Result: PASS