booking operations and trains scheduling also allocations

This commit is contained in:
marshal
2026-06-10 00:48:32 +03:00
parent 675975bc08
commit 5774d7db9d
180 changed files with 13423 additions and 3877 deletions

View File

@@ -0,0 +1,56 @@
export interface WagonSlotForPin {
id: string;
sequenceNo: number;
physicalWagonId?: string | null;
wagonType?: { id: string } | null;
}
export function autoFillWagonAssignments(
slots: WagonSlotForPin[],
wagonOptionsByType: Map<string, Array<{ value: string; label: string }>>,
existingAssignments: Record<string, string> = {},
): Record<string, string> {
const next: Record<string, string> = {};
const assignedWagonIds = new Set<string>();
for (const slot of slots) {
const pinnedId = slot.physicalWagonId ?? existingAssignments[slot.id];
if (pinnedId) {
next[slot.id] = pinnedId;
assignedWagonIds.add(pinnedId);
}
}
for (const slot of slots) {
if (next[slot.id]) continue;
const typeId = slot.wagonType?.id ?? "";
const options = wagonOptionsByType.get(typeId) ?? [];
const availableWagon = options.find((option) => !assignedWagonIds.has(option.value));
if (availableWagon) {
next[slot.id] = availableWagon.value;
assignedWagonIds.add(availableWagon.value);
}
}
return next;
}
export function countFilledSlots(
slots: WagonSlotForPin[],
assignments: Record<string, string>,
): { filled: number; total: number; unfilledSlotNumbers: number[] } {
const unfilledSlotNumbers: number[] = [];
for (const slot of slots) {
if (!assignments[slot.id]) {
unfilledSlotNumbers.push(slot.sequenceNo);
}
}
return {
filled: slots.length - unfilledSlotNumbers.length,
total: slots.length,
unfilledSlotNumbers,
};
}