Something went wrong. Try again.
A functional toolkit for authoring resource-leveling algorithms — compose constraint and scoring blocks, enumerate feasible schedules
Something went wrong. Try again.
1.4 kB · 41 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142// Bridge for the no-search-yet case. Reads pre-existing dates from// `resolved.source` into a Schedule shape so round-trip identity holds for// projects that already have task dates pinned, and so partial pipelines// can hand a Schedule to materialize() without going through Search.
import { dateToDay, endOfLocalDayExclusive, resolveWorkingCalendar, startOfLocalDay,} from "./calendarDays.ts";import type { ResolvedProject, Schedule, ScheduledTask } from "./types.ts";
export function currentSchedule(resolved: ResolvedProject): Schedule { const tasks: ScheduledTask[] = []; let makespan = 0; const taskById = new Map(resolved.tasks.map((t) => [t.uniqueId, t])); for (const sourceTask of resolved.source.tasks) { if (sourceTask.uniqueId === null) continue; if (!sourceTask.start || !sourceTask.finish) continue; const cal = resolveWorkingCalendar( resolved, taskById.get(sourceTask.uniqueId)?.calendarUniqueId ?? null, ); const startDay = dateToDay(cal, startOfLocalDay(sourceTask.start)); const finishDay = dateToDay(cal, endOfLocalDayExclusive(sourceTask.finish)); tasks.push({ uniqueId: sourceTask.uniqueId, startDay, finishDay, modeId: null, }); if (finishDay > makespan) makespan = finishDay; } return { resolved, tasks, makespan, annotations: new Map(), };}