Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: consolidate consecutive fake tracks overtake steps to single stops in stdcm report #10869

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"stopType": {
"driverSwitch": "driver switch",
"passageTime": "passage time",
"overtake": "overtake",
"serviceStop": "service stop"
},
"time": "Time",
Expand Down
1 change: 1 addition & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"stopType": {
"driverSwitch": "relève conducteur",
"passageTime": "passage",
"overtake": "dépassement",
"serviceStop": "arrêt de service"
},
"time": "Heure",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const StcdmResultsTable = ({
({ location }) =>
location && location.name === step.name && location.secondary_code === step.ch
);
const shouldRenderRow = isFirstStep || isRequestedPathStep || isLastStep;
const shouldRenderRow =
isFirstStep || isRequestedPathStep || isLastStep || step.duration;
const isPathStep =
isFirstStep || isLastStep || (isRequestedPathStep && step.duration === 0);
const isNotExtremity = !isFirstStep && !isLastStep;
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export enum StdcmStopTypes {
PASSAGE_TIME = 'passageTime',
DRIVER_SWITCH = 'driverSwitch',
SERVICE_STOP = 'serviceStop',
OVERTAKE = 'overtake',
}

export type StdcmLinkedTrainExtremity = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ export function getStopDurationBetweenTwoPositions(
return null;
}

// TODO : Remove this function as soon as fake takeover tracks cease to be used
// It serves to consolidate steps of the form OVERTAKE_n_A;X, OVERTAKE_n_B;X in a single step X
export function consolidateOvertakesToSingleSteps(
steps: StdcmResultsOperationalPoint[]
): StdcmResultsOperationalPoint[] {
function convertHHMMTimeToSeconds(time: string): number {
const [hours, minutes] = time.split(':').map(Number);
return hours * 3600 + minutes * 60;
}
const consolidatedSteps: StdcmResultsOperationalPoint[] = [];
for (let i = 0; i < steps.length - 1; i += 1) {
const [step, nextStep] = [steps[i], steps[i + 1]];
const overtakenStepMatch = step.name?.match(/^OVERTAKE.*;(.*)$/);
if (overtakenStepMatch) {
const stopDuration =
convertHHMMTimeToSeconds(nextStep.time!) - convertHHMMTimeToSeconds(step.time!);
const consolidatedStep = {
...step,
name: overtakenStepMatch[1],
duration: stopDuration,
stopEndTime: nextStep.time!,
stopType: 'overtake',
stopFor: stopDuration / 60,
};
consolidatedSteps.push(consolidatedStep);
i += 1; // to skip the next step, as we consolidated two overtake steps in one
} else {
consolidatedSteps.push(step);
}
}
consolidatedSteps.push(steps[steps.length - 1]);
return consolidatedSteps;
}

export function getOperationalPointsWithTimes(
operationalPoints: SuggestedOP[],
simulation: Extract<SimulationResponse, { status: 'success' }>,
Expand Down Expand Up @@ -160,5 +194,5 @@ export function getOperationalPointsWithTimes(
};
});

return opResults;
return consolidateOvertakesToSingleSteps(opResults);
}
Loading