mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 13:05:44 +00:00
enhance shipment form and booking process
This commit is contained in:
@@ -539,15 +539,9 @@ export function validateMixedTrainLimitsPerEdge(
|
||||
stops: string[],
|
||||
): string[] {
|
||||
if (stops.length <= 2) return validateMixedTrainLimits(wagonPlan, wagonTypes, limits);
|
||||
const lastIdx = stops.length - 1;
|
||||
const spans = wagonPlan.map((slot) => {
|
||||
const from = slot.boardYardId ? stops.indexOf(slot.boardYardId) : 0;
|
||||
const to = slot.alightYardId ? stops.indexOf(slot.alightYardId) : lastIdx;
|
||||
// A yard missing from the stop list keeps the slot on the whole route.
|
||||
return { from: from >= 0 ? from : 0, to: to > 0 ? to : lastIdx };
|
||||
});
|
||||
const spans = slotSpans(wagonPlan, stops);
|
||||
const violations = new Set<string>();
|
||||
for (let edge = 0; edge < lastIdx; edge += 1) {
|
||||
for (let edge = 0; edge < stops.length - 1; edge += 1) {
|
||||
const active = wagonPlan.filter(
|
||||
(_, i) => spans[i].from <= edge && edge < spans[i].to,
|
||||
);
|
||||
@@ -559,6 +553,52 @@ export function validateMixedTrainLimitsPerEdge(
|
||||
return [...violations];
|
||||
}
|
||||
|
||||
/** Per-slot stop-index spans; a yard missing from the stop list keeps the slot on the whole route. */
|
||||
function slotSpans(
|
||||
wagonPlan: WagonPlanSlot[],
|
||||
stops: string[],
|
||||
): Array<{ from: number; to: number }> {
|
||||
const lastIdx = stops.length - 1;
|
||||
return wagonPlan.map((slot) => {
|
||||
const from = slot.boardYardId ? stops.indexOf(slot.boardYardId) : 0;
|
||||
const to = slot.alightYardId ? stops.indexOf(slot.alightYardId) : lastIdx;
|
||||
return { from: from >= 0 ? from : 0, to: to > 0 ? to : lastIdx };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The corridor's binding edge: gross tons (tare + assigned cargo) and length
|
||||
* summed over only the slots riding each edge, maxed across edges. This is the
|
||||
* figure a locomotive pull/length limit must be compared against — a train is
|
||||
* never heavier than its heaviest single leg, so summing disjoint legs
|
||||
* (intercity Gelan→Adama + export Adama→Doraleh) over-reports the train.
|
||||
* Two stops or fewer degrade to the whole-train totals.
|
||||
*/
|
||||
export function maxEdgeConsistUsage(
|
||||
wagonPlan: WagonPlanSlot[],
|
||||
stops: string[],
|
||||
): { grossWeightTons: number; lengthMeters: number } {
|
||||
const totals = (slots: WagonPlanSlot[]) => ({
|
||||
grossWeightTons: slots.reduce(
|
||||
(sum, w) =>
|
||||
sum + Number(w.tareWeightTons ?? 0) + Number(w.assignedWeightTons ?? 0),
|
||||
0,
|
||||
),
|
||||
lengthMeters: slots.reduce((sum, w) => sum + Number(w.lengthMeters ?? 0), 0),
|
||||
});
|
||||
if (stops.length <= 2) return totals(wagonPlan);
|
||||
const spans = slotSpans(wagonPlan, stops);
|
||||
const usage = { grossWeightTons: 0, lengthMeters: 0 };
|
||||
for (let edge = 0; edge < stops.length - 1; edge += 1) {
|
||||
const active = totals(
|
||||
wagonPlan.filter((_, i) => spans[i].from <= edge && edge < spans[i].to),
|
||||
);
|
||||
usage.grossWeightTons = Math.max(usage.grossWeightTons, active.grossWeightTons);
|
||||
usage.lengthMeters = Math.max(usage.lengthMeters, active.lengthMeters);
|
||||
}
|
||||
return usage;
|
||||
}
|
||||
|
||||
export function validate20ftContainerRules(
|
||||
units: ContainerUnitRow[],
|
||||
placements: ContainerPlacementInput[],
|
||||
|
||||
Reference in New Issue
Block a user