mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-19 18:24:50 +00:00
Docs: Update Gemini benchmark results
This commit is contained in:
@@ -1,50 +1,59 @@
|
||||
const findAvailableSlots = async (calA, calB, constraints) => {
|
||||
const { DateTime: D } = await import('https://cdn.jsdelivr.net/npm/luxon@3.4.4/+esm');
|
||||
const { durationMinutes: dur, searchRange: rng, workHours: wh } = constraints;
|
||||
|
||||
const utc = { zone: 'utc' };
|
||||
const parse = s => D.fromISO(s, utc);
|
||||
const durMs = dur * 60000;
|
||||
|
||||
const busy = [...calA, ...calB]
|
||||
.map(x => ({ s: parse(x.start).valueOf(), e: parse(x.end).valueOf() }))
|
||||
.sort((a, b) => a.s - b.s)
|
||||
.reduce((acc, cur) => {
|
||||
const last = acc.at(-1);
|
||||
if (last && cur.s <= last.e) last.e = Math.max(last.e, cur.e);
|
||||
else acc.push(cur);
|
||||
return acc;
|
||||
}, []);
|
||||
export const findAvailableSlots = async (calA, calB, { durationMinutes: dur, searchRange: range, workHours: wh }) => {
|
||||
const { default: d } = await import('https://esm.sh/dayjs@1.11.10');
|
||||
const { default: u } = await import('https://esm.sh/dayjs@1.11.10/plugin/utc');
|
||||
d.extend(u);
|
||||
|
||||
const slots = [];
|
||||
const rangeStart = parse(rng.start).valueOf();
|
||||
const rangeEnd = parse(rng.end).valueOf();
|
||||
const [wsH, wsM] = wh.start.split(':').map(Number);
|
||||
const [weH, weM] = wh.end.split(':').map(Number);
|
||||
const D = t => d.utc(t);
|
||||
const rS = D(range.start), rE = D(range.end);
|
||||
const setT = (dt, t) => {
|
||||
const [h, m] = t.split(':');
|
||||
return dt.hour(h).minute(m).second(0).millisecond(0);
|
||||
};
|
||||
|
||||
let currDay = parse(rng.start).startOf('day');
|
||||
// 1. Merge and Sort Busy Slots
|
||||
let busy = [...calA, ...calB]
|
||||
.map(x => ({ s: D(x.start), e: D(x.end) }))
|
||||
.filter(x => x.e > rS && x.s < rE)
|
||||
.sort((a, b) => a.s - b.s);
|
||||
|
||||
while (currDay.valueOf() < rangeEnd) {
|
||||
const wStart = Math.max(currDay.set({ hour: wsH, minute: wsM }).valueOf(), rangeStart);
|
||||
const wEnd = Math.min(currDay.set({ hour: weH, minute: weM }).valueOf(), rangeEnd);
|
||||
let merged = [], curr = busy[0];
|
||||
if (curr) {
|
||||
for (let i = 1; i < busy.length; i++) {
|
||||
if (busy[i].s < curr.e) curr.e = busy[i].e > curr.e ? busy[i].e : curr.e;
|
||||
else { merged.push(curr); curr = busy[i]; }
|
||||
}
|
||||
merged.push(curr);
|
||||
}
|
||||
|
||||
if (wStart < wEnd) {
|
||||
let ptr = wStart;
|
||||
for (const b of busy) {
|
||||
if (b.e <= ptr) continue;
|
||||
if (b.s >= wEnd) break;
|
||||
while (ptr + durMs <= b.s) {
|
||||
slots.push({ start: D.fromMillis(ptr, utc).toISO(), end: D.fromMillis(ptr + durMs, utc).toISO() });
|
||||
ptr += durMs;
|
||||
// 2. Identify Free Gaps within Search Range
|
||||
let gaps = [], ptr = rS;
|
||||
for (const b of merged) {
|
||||
if (b.s > ptr) gaps.push({ s: ptr, e: b.s });
|
||||
ptr = b.e > ptr ? b.e : ptr;
|
||||
}
|
||||
if (ptr < rE) gaps.push({ s: ptr, e: rE });
|
||||
|
||||
// 3. Generate Slots intersecting Work Hours
|
||||
const slots = [];
|
||||
for (const g of gaps) {
|
||||
let day = g.s.clone().startOf('day');
|
||||
const endDay = g.e.clone().endOf('day');
|
||||
|
||||
while (day <= endDay) {
|
||||
const wS = setT(day, wh.start), wE = setT(day, wh.end);
|
||||
// Intersection of Gap and Work Hours
|
||||
const start = g.s > wS ? g.s : wS;
|
||||
const end = g.e < wE ? g.e : wE;
|
||||
|
||||
if (start < end) {
|
||||
let s = start;
|
||||
while (s.add(dur, 'm') <= end) {
|
||||
slots.push({ start: s.toISOString(), end: s.add(dur, 'm').toISOString() });
|
||||
s = s.add(dur, 'm');
|
||||
}
|
||||
ptr = Math.max(ptr, b.e);
|
||||
}
|
||||
while (ptr + durMs <= wEnd) {
|
||||
slots.push({ start: D.fromMillis(ptr, utc).toISO(), end: D.fromMillis(ptr + durMs, utc).toISO() });
|
||||
ptr += durMs;
|
||||
}
|
||||
day = day.add(1, 'd');
|
||||
}
|
||||
currDay = currDay.plus({ days: 1 });
|
||||
}
|
||||
|
||||
return slots;
|
||||
|
||||
Reference in New Issue
Block a user