Compare commits

...

3 Commits

Author SHA1 Message Date
github-actions[bot]
ebeee1ab97 Docs: Update benchmark for google/gemini-3.1-flash-lite 2026-05-18 03:02:46 +00:00
github-actions[bot]
542af993bf Docs: Update benchmark for openai/gpt-5.5 EFF:high 2026-05-18 02:58:30 +00:00
275b423549 Update benchmark models in README 2026-05-17 19:44:22 -07:00
25 changed files with 1065 additions and 6 deletions

8
README
View File

@@ -9,22 +9,18 @@ SHARED_PROMPT: "Provide production-ready and maintainable JavaScript code. Apply
The following models are included in the benchmark run.
<!-- MODELS_START -->
google/gemini-3.1-flash-lite
openai/gpt-5.5 EFF:high
deepseek/deepseek-v4-pro
moonshotai/kimi-k2.6
anthropic/claude-opus-4.7 EFF:medium
z-ai/glm-5.1
x-ai/grok-4.20-beta
openai/gpt-5.4
google/gemini-3.1-flash-lite-preview
openai/gpt-5.3-codex
google/gemini-3.1-pro-preview
anthropic/claude-sonnet-4.6
minimax/minimax-m2.5
z-ai/glm-5
anthropic/claude-opus-4.6
moonshotai/kimi-k2.5
z-ai/glm-4.7
google/gemini-3-flash-preview TEMP:0.35
deepseek/deepseek-v3.2
anthropic/claude-sonnet-4.5 TEMP:0.7
<!-- MODELS_END -->

View File

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

View File

@@ -0,0 +1,24 @@
const SCRYPT_CDN = 'https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm';
async function hashPassword(password, salt) {
if (typeof password !== 'string' || typeof salt !== 'string')
throw new TypeError('password and salt must be strings');
const { scrypt } = await import(SCRYPT_CDN);
const enc = new TextEncoder();
const hash = await scrypt(
enc.encode(password),
enc.encode(salt),
1024,
8,
1,
32
);
return [...hash]
.map(b => b.toString(16).padStart(2, '0'))
.join('');
}
export default hashPassword;
// Generation time: 12.627s
// Result: PASS

View File

@@ -0,0 +1,16 @@
async function analyzeGPS(readings, boundary) {
const { booleanPointInPolygon, lineString, length } = await import('https://cdn.skypack.dev/@turf/turf');
const valid = readings
.filter(r => booleanPointInPolygon(r.loc, boundary))
.sort((a, b) => a.ts - b.ts);
if (valid.length < 2) return 0;
const dist = length(lineString(valid.map(r => r.loc)), { units: 'kilometers' });
return +dist.toFixed(2);
}
export default analyzeGPS;
// Generation time: 1.005s
// Result: PASS

View File

@@ -0,0 +1,19 @@
async function analyzeGPS(readings, boundary) {
const turf = await import("https://esm.sh/@turf/turf@7.2.0");
const valid = readings
.filter(({ loc }) =>
turf.booleanPointInPolygon(turf.point(loc), boundary, { ignoreBoundary: true })
)
.sort((a, b) => a.ts - b.ts);
if (valid.length < 2) return 0;
const line = turf.lineString(valid.map(({ loc }) => loc));
const km = turf.length(line, { units: "kilometers" });
return +km.toFixed(2);
}
export default analyzeGPS;
// Generation time: 13.413s
// Result: PASS

View File

@@ -0,0 +1,49 @@
async function computeMST(tomlStr) {
const [{ parse }, { Heap }, { default: table }] = await Promise.all([
import("https://cdn.skypack.dev/smol-toml"),
import("https://cdn.skypack.dev/mnemonist/heap"),
import("https://cdn.skypack.dev/text-table")
]);
const { edges } = parse(tomlStr), nodes = new Set();
const heap = new Heap((a, b) => a.weight - b.weight);
edges.forEach(e => {
heap.push(e);
nodes.add(e.from);
nodes.add(e.to);
});
const parent = new Map(), rank = new Map();
nodes.forEach(n => parent.set(n, n) || rank.set(n, 0));
const find = i => {
while (parent.get(i) !== i) {
parent.set(i, parent.get(parent.get(i)));
i = parent.get(i);
}
return i;
};
const mst = [['From', 'To', 'Weight']], nCount = nodes.size;
let totalWeight = 0;
while (heap.size() > 0 && mst.length < nCount) {
const { from, to, weight } = heap.pop();
let rootU = find(from), rootV = find(to);
if (rootU !== rootV) {
if (rank.get(rootU) < rank.get(rootV)) [rootU, rootV] = [rootV, rootU];
parent.set(rootV, rootU);
if (rank.get(rootU) === rank.get(rootV)) rank.set(rootU, rank.get(rootU) + 1);
mst.push([from, to, String(weight)]);
totalWeight += weight;
}
}
return { table: table(mst), totalWeight };
}
export default computeMST;
// Generation time: 2.142s
// Result: FAIL

View File

@@ -0,0 +1,85 @@
const mstDeps = () => mstDeps.p ??= Promise.all([
import('https://esm.sh/smol-toml'),
import('https://esm.sh/mnemonist/heap'),
import('https://esm.sh/text-table')
]).then(([toml, heap, text]) => ({
parse: toml.parse ?? toml.default?.parse ?? toml.default,
Heap: heap.default ?? heap.Heap ?? heap,
table: text.default ?? text.table ?? text
}));
class UnionFind {
constructor(nodes) {
this.p = new Map;
this.r = new Map;
for (const n of nodes) {
this.p.set(n, n);
this.r.set(n, 0);
}
}
find(x) {
let p = this.p.get(x);
if (p !== x) this.p.set(x, p = this.find(p));
return p;
}
union(a, b) {
let x = this.find(a), y = this.find(b);
if (x === y) return false;
let rx = this.r.get(x), ry = this.r.get(y);
if (rx < ry) [x, y] = [y, x], [rx, ry] = [ry, rx];
this.p.set(y, x);
if (rx === ry) this.r.set(x, rx + 1);
return true;
}
}
async function computeMST(input) {
if (typeof input !== 'string') throw new TypeError('Expected a TOML string');
const {parse, Heap, table} = await mstDeps();
const {edges: raw} = parse(input);
if (!Array.isArray(raw)) throw new TypeError('Expected TOML to contain an edges array');
const nodes = new Set;
const edges = raw.map((e, i) => {
const from = e?.from, to = e?.to, weight = Number(e?.weight);
if (typeof from !== 'string' || typeof to !== 'string' || !Number.isFinite(weight)) {
throw new TypeError(`Invalid edge at index ${i}`);
}
nodes.add(from);
nodes.add(to);
return {from, to, weight, i};
});
const heap = new Heap((a, b) => a.weight - b.weight || a.i - b.i);
for (const e of edges) heap.push(e);
const uf = new UnionFind(nodes);
const mst = [];
let totalWeight = 0, left = edges.length;
while (mst.length < nodes.size - 1 && left) {
left--;
const e = heap.pop();
if (!uf.union(e.from, e.to)) continue;
mst.push([e.from, e.to, String(e.weight)]);
totalWeight += e.weight;
}
return {
table: table([['From', 'To', 'Weight'], ...mst]),
totalWeight
};
}
export default computeMST;
// Generation time: 47.382s
// Result: PASS

View File

@@ -0,0 +1,29 @@
async function findShortestPath(graph, start, end) {
const { PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
const dist = { [start]: 0 };
const pq = new PriorityQueue({
comparator: (a, b) => a.w - b.w
});
pq.queue({ n: start, w: 0 });
while (pq.length) {
const { n, w } = pq.dequeue();
if (n === end) return w;
if (w > (dist[n] ?? Infinity)) continue;
for (const [neighbor, weight] of Object.entries(graph[n] || {})) {
const newDist = w + weight;
if (newDist < (dist[neighbor] ?? Infinity)) {
dist[neighbor] = newDist;
pq.queue({ n: neighbor, w: newDist });
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 1.539s
// Result: FAIL

View File

@@ -0,0 +1,43 @@
const loadPQ = (() => {
let p;
return () => p ||= import("https://esm.sh/js-priority-queue@0.1.5")
.then(m => m.default?.default ?? m.default ?? m.PriorityQueue);
})();
async function findShortestPath(graph, start, end) {
const PriorityQueue = await loadPQ();
const dist = new Map([[start, 0]]);
const q = new PriorityQueue({
comparator: (a, b) => a.cost - b.cost
});
q.queue({ node: start, cost: 0 });
while (q.length) {
const { node, cost } = q.dequeue();
if (cost > dist.get(node)) continue;
if (node === end) return cost;
for (const [next, rawWeight] of Object.entries(graph?.[node] ?? {})) {
const weight = Number(rawWeight);
if (!Number.isFinite(weight) || weight < 0) {
throw new RangeError("Edge weights must be finite non-negative numbers");
}
const nextCost = cost + weight;
if (nextCost < (dist.get(next) ?? Infinity)) {
dist.set(next, nextCost);
q.queue({ node: next, cost: nextCost });
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 55.807s
// Result: PASS

View File

@@ -0,0 +1,30 @@
async function findConvexHull(pts) {
const { sortBy, uniqWith, isEqual } = await import('https://cdn.skypack.dev/lodash');
const sorted = sortBy(uniqWith(pts, isEqual), ['x', 'y']);
if (sorted.length <= 2) return sorted;
const crossProduct = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
const build = (arr) => {
const hull = [];
for (const p of arr) {
while (hull.length >= 2 && crossProduct(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
return hull;
};
const lower = build(sorted);
const upper = build([...sorted].reverse());
lower.pop();
upper.pop();
return lower.concat(upper);
}
export default findConvexHull;
// Generation time: 1.515s
// Result: PASS

View File

@@ -0,0 +1,34 @@
const findConvexHull = async points => {
const { sortBy, uniqBy } = await import(
"https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js"
)
const pts = uniqBy(
sortBy(points, ["x", "y"]),
p => `${p.x}\u0000${p.y}`
)
if (pts.length < 2) return pts
const cross = (a, b, c) =>
(b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
const half = arr => {
const h = []
for (const p of arr) {
while (h.length > 1 && cross(h.at(-2), h.at(-1), p) <= 0) h.pop()
h.push(p)
}
return h
}
return [
...half(pts).slice(0, -1),
...half([...pts].reverse()).slice(0, -1)
]
}
export default findConvexHull;
// Generation time: 14.673s
// Result: PASS

View File

@@ -0,0 +1,40 @@
async function analyzeSignal(yamlStr) {
const [yaml, math, { default: ndarray }, fft, { sanitize }] = await Promise.all([
import('https://esm.sh/js-yaml'),
import('https://esm.sh/mathjs'),
import('https://esm.sh/ndarray'),
import('https://esm.sh/ndarray-fft'),
import('https://esm.sh/dompurify')
]);
const cfg = yaml.load(yamlStr);
const N = cfg.sampleRate * cfg.duration;
const real = ndarray(new Float64Array(N));
const imag = ndarray(new Float64Array(N));
for (let i = 0; i < N; i++) {
const t = i / cfg.sampleRate;
const v = cfg.components.reduce((acc, c) =>
acc + c.amplitude * math.sin(2 * math.pi * c.frequency * t), 0);
real.set(i, v);
}
fft(1, real, imag);
const peaks = [];
for (let k = 0; k <= N / 2; k++) {
const mag = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2);
if (mag > 0.1) peaks.push({ frequencyHz: Math.round(k * cfg.sampleRate / N), magnitude: +mag.toFixed(2) });
}
peaks.sort((a, b) => b.magnitude - a.magnitude);
let html = '<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>';
peaks.forEach(p => html += `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`);
html += '</table>';
return { peaks, html: sanitize(html), signalLength: N };
}
export default analyzeSignal;
// Generation time: 1.769s
// Result: FAIL

View File

@@ -0,0 +1,76 @@
async function analyzeSignal(yamlString) {
const [
yamlMod,
math,
ndarrayMod,
fftMod,
purifyMod
] = await Promise.all([
import("https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/+esm"),
import("https://cdn.jsdelivr.net/npm/mathjs@13.2.0/+esm"),
import("https://cdn.jsdelivr.net/npm/ndarray@1.0.19/+esm"),
import("https://cdn.jsdelivr.net/npm/ndarray-fft@1.0.3/+esm"),
import("https://cdn.jsdelivr.net/npm/dompurify@3.1.6/+esm")
]);
const yaml = yamlMod.default || yamlMod;
const ndarray = ndarrayMod.default || ndarrayMod;
const fft = fftMod.default || fftMod;
const DOMPurify = purifyMod.default || purifyMod;
const cfg = yaml.load(yamlString);
const sampleRate = Number(cfg.sampleRate);
const duration = Number(cfg.duration);
const components = Array.isArray(cfg.components) ? cfg.components : [];
const N = Math.max(0, Math.floor(sampleRate * duration));
if (!Number.isFinite(sampleRate) || sampleRate <= 0) throw new Error("Invalid sampleRate");
if (!Number.isFinite(duration) || duration <= 0) throw new Error("Invalid duration");
if (!N) throw new Error("Signal length must be greater than zero");
const signal = Float64Array.from({ length: N }, (_, i) => {
const t = i / sampleRate;
return components.reduce((sum, c) => {
const a = Number(c.amplitude);
const f = Number(c.frequency);
return Number.isFinite(a) && Number.isFinite(f)
? sum + a * math.sin(2 * math.pi * f * t)
: sum;
}, 0);
});
const real = ndarray(signal.slice(), [N]);
const imag = ndarray(new Float64Array(N), [N]);
fft(1, real, imag);
const peaks = Array.from({ length: Math.floor(N / 2) + 1 }, (_, k) => {
const re = real.get(k);
const im = imag.get(k);
const magnitude = math.sqrt(re ** 2 + im ** 2) / (N / 2);
return {
frequencyHz: Math.round(k * sampleRate / N),
magnitude: Math.round(magnitude * 100) / 100,
rawMagnitude: magnitude
};
})
.filter(p => p.rawMagnitude > 0.1)
.sort((a, b) => b.rawMagnitude - a.rawMagnitude)
.map(({ frequencyHz, magnitude }) => ({ frequencyHz, magnitude }));
const rows = peaks
.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`)
.join("");
const html = DOMPurify.sanitize(
`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`
);
return { peaks, html, signalLength: N };
}
export default analyzeSignal;
// Generation time: 16.732s
// Result: PASS

View File

@@ -0,0 +1,54 @@
async function hexchain(tomlStr) {
const [
{ parse },
{ default: seedrandom },
{ mean, standardDeviation, median },
{ default: Ajv },
{ default: table },
{ DOMPurify }
] = await Promise.all([
import('https://esm.sh/smol-toml'),
import('https://esm.sh/seedrandom'),
import('https://esm.sh/simple-statistics'),
import('https://esm.sh/ajv'),
import('https://esm.sh/text-table'),
import('https://esm.sh/dompurify')
]);
const config = parse(tomlStr);
const ajv = new Ajv();
const validate = ajv.compile({
type: 'object',
required: ['seed', 'count', 'label'],
properties: {
seed: { type: 'string' },
count: { type: 'integer', minimum: 1, maximum: 10000 },
label: { type: 'string', minLength: 1 }
}
});
if (!validate(config)) return { valid: false, errors: ajv.errorsText(validate.errors) };
const rng = new seedrandom(config.seed);
const nums = Array.from({ length: config.count }, rng);
const round = n => +(n.toFixed(6));
const stats = { mean: round(mean(nums)), stddev: round(standardDeviation(nums)), median: round(median(nums)) };
const tbl = table([
['Stat', 'Value'],
['mean', String(stats.mean)],
['stddev', String(stats.stddev)],
['median', String(stats.median)]
]);
return {
valid: true,
label: config.label,
stats,
table: DOMPurify.sanitize(`<pre class="stats">${tbl}</pre>`),
count: config.count
};
}
export default hexchain;
// Generation time: 1.959s
// Result: FAIL

View File

@@ -0,0 +1,70 @@
const hexchainUrls = [
'https://esm.sh/smol-toml?bundle',
'https://esm.sh/seedrandom?bundle',
'https://esm.sh/simple-statistics?bundle',
'https://esm.sh/ajv?bundle',
'https://esm.sh/text-table?bundle',
'https://esm.sh/dompurify?bundle'
];
const hexchainSchema = {
type: 'object',
required: ['seed', 'count', 'label'],
properties: {
seed: { type: 'string' },
count: { type: 'integer', minimum: 1, maximum: 10000 },
label: { type: 'string', minLength: 1 }
}
};
let hexchainModules;
async function hexchain(tomlString) {
const [
toml,
seedMod,
ssMod,
ajvMod,
tableMod,
purifyMod
] = await (hexchainModules ||= Promise.all(hexchainUrls.map(u => import(u))));
const parse = toml.parse ?? toml.default?.parse ?? toml.default;
const seedrandom = seedMod.default ?? seedMod;
const ss = ssMod.mean ? ssMod : ssMod.default;
const Ajv = ajvMod.default ?? ajvMod.Ajv;
const textTable = tableMod.default ?? tableMod;
const purify = purifyMod.default ?? purifyMod;
const DOMPurify = purify.sanitize ? purify : purify(globalThis);
const config = parse(tomlString);
const ajv = new Ajv();
if (!ajv.validate(hexchainSchema, config))
return { valid: false, errors: ajv.errorsText() };
const rng = new seedrandom(config.seed);
const nums = Array.from({ length: config.count }, () => rng());
const round = n => Math.round((n + Number.EPSILON) * 1e6) / 1e6;
const mean = round(ss.mean(nums));
const stddev = round(ss.standardDeviation(nums));
const median = round(ss.median(nums));
const tableString = textTable([
['Stat', 'Value'],
['mean', String(mean)],
['stddev', String(stddev)],
['median', String(median)]
]);
return {
valid: true,
label: config.label,
stats: { mean, stddev, median },
table: DOMPurify.sanitize('<pre class="stats">' + tableString + '</pre>'),
count: config.count
};
}
globalThis.hexchain = hexchain;
export default hexchain;
// Generation time: 137.860s
// Result: PASS

View File

@@ -0,0 +1,13 @@
async function parseMarkdown(md) {
const { marked } = await import("https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js");
marked.setOptions({
gfm: true,
breaks: true
});
return marked.parse(md);
}
export default parseMarkdown;
// Generation time: 0.838s
// Result: PASS

View File

@@ -0,0 +1,25 @@
const parseMarkdown = (() => {
let libs;
return async markdown => {
libs ||= Promise.all([
import("https://cdn.jsdelivr.net/npm/marked@13/+esm"),
import("https://cdn.jsdelivr.net/npm/dompurify@3/+esm")
]);
const [{ marked }, { default: DOMPurify }] = await libs;
marked.use({
gfm: true,
breaks: false,
async: false
});
return DOMPurify.sanitize(
marked.parse(String(markdown ?? ""))
);
};
})();
export default parseMarkdown;
// Generation time: 13.490s
// Result: PASS

View File

@@ -0,0 +1,24 @@
async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
const { parse } = await import('https://cdn.skypack.dev/papaparse');
const { data } = parse(csv, { header: true, dynamicTyping: true });
const groups = data
.filter(r => r[filterColumn] == filterValue)
.reduce((acc, r) => {
const key = r[groupBy];
const val = Number(r[aggregateColumn]) || 0;
acc[key] ??= { sum: 0, count: 0 };
acc[key].sum += val;
acc[key].count += 1;
return acc;
}, {});
return Object.entries(groups).map(([k, v]) => ({
[groupBy]: k,
result: operation === 'sum' ? v.sum :
operation === 'avg' ? v.sum / v.count : v.count
}));
}
export default processCSV;
// Generation time: 1.360s
// Result: PASS

View File

@@ -0,0 +1,34 @@
const csvDeps = Promise.all([
import("https://cdn.jsdelivr.net/npm/d3-dsv@3/+esm"),
import("https://cdn.jsdelivr.net/npm/d3-array@3/+esm")
]);
async function processCSV(csv, config = {}) {
const [{ csvParse }, { rollups }] = await csvDeps;
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config;
const ops = new Set(["sum", "avg", "count"]);
if (!ops.has(operation)) throw new TypeError("Invalid operation");
const num = r => {
const n = Number(r[aggregateColumn]);
return Number.isFinite(n) ? n : 0;
};
const rows = csvParse(String(csv ?? ""))
.filter(r => r[filterColumn] == filterValue);
return rollups(
rows,
rs => {
if (operation === "count") return rs.length;
const sum = rs.reduce((a, r) => a + num(r), 0);
return operation === "avg" ? sum / rs.length : sum;
},
r => r[groupBy]
).map(([k, result]) => ({ [groupBy]: k, result }));
}
export default processCSV;
// Generation time: 26.121s
// Result: PASS

View File

@@ -0,0 +1,41 @@
async function findAvailableSlots(cal1, cal2, { durationMinutes, searchRange, workHours }) {
const { DateTime, Interval } = await import('https://cdn.skypack.dev/luxon');
const toUTC = (iso) => DateTime.fromISO(iso, { zone: 'utc' });
const parseTime = (t, d) => DateTime.fromISO(`${d.toISODate()}T${t}:00Z`, { zone: 'utc' });
const busy = [...cal1, ...cal2].map(s => Interval.fromDateTimes(toUTC(s.start), toUTC(s.end)));
const merged = Interval.merge(busy);
const start = toUTC(searchRange.start);
const end = toUTC(searchRange.end);
const slots = [];
let current = start;
while (current < end) {
let day = current.startOf('day');
let workStart = parseTime(workHours.start, day);
let workEnd = parseTime(workHours.end, day);
let windowStart = current > workStart ? current : workStart;
let windowEnd = workEnd;
for (let s = windowStart; s.plus({ minutes: durationMinutes }) <= windowEnd; ) {
let slotEnd = s.plus({ minutes: durationMinutes });
let interval = Interval.fromDateTimes(s, slotEnd);
if (!merged.some(b => b.overlaps(interval))) {
slots.push({ start: s.toISO(), end: slotEnd.toISO() });
s = slotEnd;
} else {
s = s.plus({ minutes: 1 });
}
}
current = day.plus({ days: 1 });
}
return slots;
}
export default findAvailableSlots;
// Generation time: 2.010s
// Result: PASS

View File

@@ -0,0 +1,127 @@
let luxonPromise;
async function findAvailableSlots(calendarA = [], calendarB = [], constraints = {}) {
const { DateTime } = await (luxonPromise ||= import("https://esm.sh/luxon@3.5.0?bundle"));
const M = 6e4, D = 864e5;
const err = (E, m) => { throw new E(m); };
const toMs = v => {
if (typeof v !== "string") err(TypeError, `Invalid ISO date: ${v}`);
const d = DateTime.fromISO(v, { zone: "utc" });
if (!d.isValid) err(TypeError, `Invalid ISO date: ${v}`);
return d.toUTC().toMillis();
};
const toMinutes = v => {
if (typeof v !== "string") err(TypeError, `Invalid UTC time: ${v}`);
const m = /^(\d{2}):(\d{2})$/.exec(v);
if (!m) err(TypeError, `Invalid UTC time: ${v}`);
const h = +m[1], n = +m[2];
if (h > 24 || n > 59 || h === 24 && n)
err(RangeError, `Invalid UTC time: ${v}`);
return h * 60 + n;
};
if (!Array.isArray(calendarA) || !Array.isArray(calendarB))
err(TypeError, "Calendars must be arrays");
if (!constraints || typeof constraints !== "object" || Array.isArray(constraints))
err(TypeError, "Constraints must be an object");
if (typeof constraints.durationMinutes !== "number")
err(TypeError, "durationMinutes must be a number");
const duration = constraints.durationMinutes * M;
if (!Number.isFinite(duration) || duration <= 0 || !Number.isInteger(duration))
err(RangeError, "durationMinutes must resolve to a positive whole millisecond value");
const rangeStart = toMs(constraints.searchRange?.start);
const rangeEnd = toMs(constraints.searchRange?.end);
if (rangeEnd <= rangeStart)
err(RangeError, "searchRange.end must be after searchRange.start");
const workStart = toMinutes(constraints.workHours?.start);
const workEnd = toMinutes(constraints.workHours?.end);
if (workStart === 1440)
err(RangeError, "workHours.start must be before 24:00");
const midnight = ms => DateTime.fromMillis(ms, { zone: "utc" }).startOf("day").toMillis();
const overnight = workEnd <= workStart;
const work = [];
const addWork = (s, e) => {
const a = Math.max(s, rangeStart), b = Math.min(e, rangeEnd);
if (a >= b) return;
const l = work[work.length - 1];
if (l && a <= l[1]) l[1] = Math.max(l[1], b);
else work.push([a, b]);
};
for (
let d = midnight(rangeStart) - (overnight ? D : 0), end = midnight(rangeEnd);
d <= end;
d += D
)
addWork(d + workStart * M, d + workEnd * M + (overnight ? D : 0));
const busy = calendarA.concat(calendarB)
.map(slot => {
if (!slot || typeof slot !== "object")
err(TypeError, "Busy slots must be objects");
const s = toMs(slot.start), e = toMs(slot.end);
if (e <= s) err(RangeError, "Busy slot end must be after start");
return [Math.max(s, rangeStart), Math.min(e, rangeEnd)];
})
.filter(([s, e]) => s < e)
.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
const merged = [];
for (const [s, e] of busy) {
const l = merged[merged.length - 1];
if (l && s <= l[1]) l[1] = Math.max(l[1], e);
else merged.push([s, e]);
}
const slots = [];
const addSlots = (s, e) => {
for (; s + duration <= e; s += duration)
slots.push([s, s + duration]);
};
let i = 0;
for (const [ws, we] of work) {
while (merged[i]?.[1] <= ws) i++;
let p = ws;
for (let j = i; merged[j]?.[0] < we; j++) {
const [bs, be] = merged[j];
if (bs > p) addSlots(p, Math.min(bs, we));
p = Math.max(p, Math.min(be, we));
if (p >= we) break;
}
if (p < we) addSlots(p, we);
}
const iso = ms => DateTime.fromMillis(ms, { zone: "utc" }).toISO();
return slots.map(([start, end]) => ({
start: iso(start),
end: iso(end)
}));
}
export default findAvailableSlots;
// Generation time: 263.158s
// Result: PASS

View File

@@ -0,0 +1,18 @@
async function validateJSON(data, schema) {
const { default: Ajv } = await import('https://esm.sh/ajv@8.12.0');
const { default: addFormats } = await import('https://esm.sh/ajv-formats@2.1.1');
const ajv = new (Ajv)({ allErrors: true });
addFormats(ajv);
const validate = ajv.compile(schema);
const valid = validate(data);
return {
valid,
errors: valid ? [] : validate.errors.map(e => `${e.instancePath} ${e.message}`)
};
}
export default validateJSON;
// Generation time: 1.038s
// Result: PASS

View File

@@ -0,0 +1,101 @@
const _jsonSchema = (() => {
const ajvs = new Map();
const vals = new WeakMap();
const opts = {
allErrors: true,
strict: false,
allowUnionTypes: true,
addUsedSchema: false,
validateFormats: true
};
const ver = s => {
s = `${s && typeof s == "object" && s.$schema || ""}`;
return s.includes("2020-12") ? "2020" : s.includes("2019-09") ? "2019" : "7";
};
const url = v => `https://esm.sh/ajv@8.17.1${v == "7" ? "" : `/dist/${v}`}?bundle`;
const load = v => {
let p = ajvs.get(v);
if (p) return p;
p = Promise.all([
import(url(v)),
import("https://esm.sh/ajv-formats@3.0.1?bundle&deps=ajv@8.17.1")
]).then(([a, f]) => {
const Ajv = a.default || a.Ajv || a;
const addFormats = f.default || f.addFormats || f;
const ajv = new Ajv({ ...opts });
addFormats(ajv);
return ajv;
}).catch(e => {
ajvs.delete(v);
throw e;
});
ajvs.set(v, p);
return p;
};
const part = s => /^(0|[1-9]\d*)$/.test(s)
? `[${s}]`
: /^[A-Za-z_$][\w$]*$/.test(s)
? `.${s}`
: `[${JSON.stringify(s)}]`;
const loc = p => p
? `$${p.split("/").slice(1).map(s => part(s.replace(/~1/g, "/").replace(/~0/g, "~"))).join("")}`
: "$";
const msg = e => {
const x = e.params || {};
const extra = e.keyword == "additionalProperties"
? `: ${x.additionalProperty}`
: e.keyword == "required"
? `: ${x.missingProperty}`
: "";
return `${loc(e.instancePath)} ${e.message || "is invalid"}${extra}`;
};
return { load, vals, ver, msg };
})();
async function validateJSON(data, schema) {
const isSchema = typeof schema == "boolean" ||
schema && typeof schema == "object" && !Array.isArray(schema);
if (!isSchema) {
return {
valid: false,
errors: ["Schema must be a JSON Schema object or boolean"]
};
}
try {
const cacheable = schema && typeof schema == "object";
let validate = cacheable && _jsonSchema.vals.get(schema);
if (!validate) {
const ajv = await _jsonSchema.load(_jsonSchema.ver(schema));
validate = ajv.compile(schema);
if (cacheable) _jsonSchema.vals.set(schema, validate);
}
const valid = validate(data);
return {
valid,
errors: valid ? [] : (validate.errors || []).map(_jsonSchema.msg)
};
} catch (e) {
return {
valid: false,
errors: [e?.message || String(e)]
};
}
}
export default validateJSON;
// Generation time: 143.247s
// Result: PASS

View File

@@ -0,0 +1,20 @@
async function createStreamVisualizer(it, { maxPoints, alpha, width, height, yDomain }) {
const [{ scaleLinear, line, extent }] = await Promise.all([import('https://cdn.skypack.dev/d3')]);
const data = [];
let prevEma;
for await (const { timestamp, value } of it) {
prevEma = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
data.push({ timestamp, value, ema: prevEma });
if (data.length > maxPoints) data.shift();
}
const x = scaleLinear().domain(extent(data, d => d.timestamp)).range([0, width]);
const y = scaleLinear().domain(yDomain).range([height, 0]);
const path = line().x(d => x(d.timestamp)).y(d => y(d.ema))(data);
return { data, path };
}
export default createStreamVisualizer;
// Generation time: 1.461s
// Result: PASS

View File

@@ -0,0 +1,76 @@
const d3$ = import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
async function createStreamVisualizer(asyncIterable, options = {}) {
const {
maxPoints,
alpha,
width,
height,
yDomain
} = options;
if (!asyncIterable?.[Symbol.asyncIterator])
throw new TypeError("asyncIterable must be an async iterable");
if (!Number.isInteger(maxPoints) || maxPoints < 1)
throw new RangeError("maxPoints must be a positive integer");
if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1)
throw new RangeError("alpha must be between 0 and 1");
if (!Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0)
throw new RangeError("width and height must be positive numbers");
if (!Array.isArray(yDomain) || yDomain.length !== 2)
throw new TypeError("yDomain must be [min, max]");
const [yMin, yMax] = yDomain.map(Number);
if (!Number.isFinite(yMin) || !Number.isFinite(yMax) || yMin === yMax)
throw new RangeError("yDomain values must be finite and distinct");
const d3 = await d3$;
const data = [];
let ema;
for await (const item of asyncIterable) {
const source = Array.isArray(item)
? { timestamp: item[0], value: item[1] }
: item;
const timestamp = +source?.timestamp;
const value = +source?.value;
if (!Number.isFinite(timestamp) || !Number.isFinite(value))
throw new TypeError("stream items must include finite timestamp and value");
ema = ema === undefined
? value
: alpha * value + (1 - alpha) * ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints)
data.splice(0, data.length - maxPoints);
}
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([yMin, yMax])
.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: 27.168s
// Result: PASS