Skip to content

Commit

Permalink
front: enhance lmr report sheet and fix linked paths
Browse files Browse the repository at this point in the history
Signed-off-by: Achraf Mohyeddine <[email protected]>
  • Loading branch information
achrafmohye committed Dec 24, 2024
1 parent b0e4d5c commit 236f1d7
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
3 changes: 2 additions & 1 deletion front/public/locales/en/stdcm-simulation-report-sheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"passageStop": "passage",
"refEngine": "Ref. engine",
"referenceEngine": "reference engine",
"simulationStopType": "Type d'arrêt",
"requestedRoute": "requested route",
"scheduledArrival": "scheduled arrival on {{date}} at {{time}}",
"scheduledDeparture": "scheduled departure on {{date}} at {{time}}",
"serviceStop": "Service stop",
"simulation": "Simulation",
"speedLimitByTag": "speed limit by tag",
"startStop": "start",
"stdcm": "ST DCM",
"stdcm": "LMR",
"stdcmCreation": "short term path creation",
"stopType": "motif",
"towedMaterial": "towed material",
Expand Down
3 changes: 2 additions & 1 deletion front/public/locales/fr/stdcm-simulation-report-sheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"passageStop": "passage",
"refEngine": "Engin de réf.",
"referenceEngine": "engin de référence",
"simulationStopType": "Type d'arrêt",
"requestedRoute": "parcours demandé",
"scheduledArrival": "arrivée prévue le {{date}} à {{time}}",
"scheduledDeparture": "départ prévu le {{date}} à {{time}}",
"serviceStop": "Arrêt de service",
"simulation": "Simulation",
"speedLimitByTag": "code de composition",
"startStop": "départ",
"stdcm": "ST DCM",
"stdcm": "LMR",
"stdcmCreation": "Création de sillon de dernière minute",
"stopType": "motif",
"towedMaterial": "matériel remorqué",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { capitalizeFirstLetter } from 'utils/strings';
import { secToMin } from 'utils/timeManipulation';

import styles from './SimulationReportStyleSheet';
import type { SimulationReportSheetProps } from '../../types';
import type { SimulationReportSheetProps, StdcmResultsOperationalPoint } from '../../types';
import { getStopDurationTime } from '../../utils/formatSimulationReportSheet';

const getSecondaryCode = ({ location }: StdcmPathStep) => location!.secondary_code;
Expand Down Expand Up @@ -52,6 +52,20 @@ const SimulationReportSheet = ({
const convoyLength = consist?.totalLength ?? rollingStock.length;
const convoyMaxSpeed = consist?.maxSpeed ?? msToKmh(rollingStock.max_speed);

const getStopTypeLabel = (
isFirstStep: boolean,
isLastStep: boolean,
step: StdcmResultsOperationalPoint
) => {
if (isFirstStep || isLastStep) {
return t('serviceStop');
}
if (step?.stopType) {
return capitalizeFirstLetter(t(`stdcm:trainPath.stopType.${step.stopType}`));
}
return '';
};

return (
<Document>
<Page wrap={false} style={styles.main.page} size={[1344]}>
Expand Down Expand Up @@ -291,6 +305,9 @@ const SimulationReportSheet = ({
<View style={styles.simulation.refEngineWidth}>
<TD>{t('referenceEngine')}</TD>
</View>
<View style={styles.simulation.refEngineWidth}>
<TD>{t('simulationStopType')}</TD>
</View>
</TH>
{operationalPointsList.map((step, index) => {
const isFirstStep = index === 0;
Expand Down Expand Up @@ -399,6 +416,11 @@ const SimulationReportSheet = ({
{!isFirstStep ? '=' : rollingStock.metadata?.reference}
</TD>
</View>
<View style={styles.simulation.refEngineWidth}>
<TD style={tdPassageStopStyle}>
{getStopTypeLabel(isFirstStep, isLastStep, step)}
</TD>
</View>
</TR>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const StcdmResults = ({
return getOperationalPointsWithTimes(
outputs.pathProperties?.suggestedOperationalPoints || [],
outputs.results.simulation,
outputs.results.simulationPathSteps,
outputs.results.departure_time
);
}, [outputs]);
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 @@ -70,6 +70,7 @@ export type StdcmResultsOperationalPoint = {
duration: number;
stopEndTime: string;
trackName?: string;
stopType?: string;
};

export type StdcmResults = {
Expand Down
13 changes: 13 additions & 0 deletions front/src/applications/stdcm/utils/formatSimulationReportSheet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SimulationResponse } from 'common/api/osrdEditoastApi';
import { matchPathStepAndOp } from 'modules/pathfinding/utils';
import { interpolateValue } from 'modules/simulationResult/SimulationResultExport/utils';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { StdcmPathStep } from 'reducers/osrdconf/types';

import type { StdcmResultsOperationalPoint } from '../types';

Expand Down Expand Up @@ -106,6 +108,7 @@ export function getStopDurationBetweenTwoPositions(
export function getOperationalPointsWithTimes(
operationalPoints: SuggestedOP[],
simulation: Extract<SimulationResponse, { status: 'success' }>,
pathSteps: StdcmPathStep[],
departureTime: string
): StdcmResultsOperationalPoint[] {
const { positions, times } = simulation.final_output;
Expand All @@ -129,6 +132,15 @@ export function getOperationalPointsWithTimes(
const durationToString = secondsToTimeString(durationInSeconds);
const stopEndTime = computeStopDepartureTime(formattedTime, durationToString);

// Find the corresponding stopType from pathSteps
const correspondingStep = pathSteps.find(
(step) => step.location && matchPathStepAndOp(step.location, op)
);
let stopType;
if (correspondingStep) {
stopType = !correspondingStep.isVia ? 'serviceStop' : correspondingStep.stopType;
}

return {
opId: op.opId!,
positionOnPath: op.positionOnPath,
Expand All @@ -138,6 +150,7 @@ export function getOperationalPointsWithTimes(
duration: durationInSeconds,
stopEndTime,
trackName: op.metadata?.trackName,
stopType,
};
});

Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/pathfinding/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const formatSuggestedOperationalPoints = (
}));

export const matchPathStepAndOp = (
step: PathStep,
step: PathItemLocation,
op: Pick<SuggestedOP, 'opId' | 'uic' | 'ch' | 'trigram' | 'track' | 'offsetOnTrack'>
) => {
if ('operational_point' in step) {
Expand Down
13 changes: 13 additions & 0 deletions front/src/reducers/osrdconf/stdcmConf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const stdcmConfSlice = createSlice({
state.totalMass = stdcmConfInitialState.totalMass;
state.maxSpeed = stdcmConfInitialState.maxSpeed;
state.speedLimitByTag = stdcmConfInitialState.speedLimitByTag;
state.linkedTrains = stdcmConfInitialState.linkedTrains;
},
updateTotalMass(
state: Draft<OsrdStdcmConfState>,
Expand Down Expand Up @@ -167,6 +168,18 @@ export const stdcmConfSlice = createSlice({
(pathStep) => pathStep.id !== action.payload
);
},
resetLinkedPathResults(
state: Draft<OsrdStdcmConfState>,
action: PayloadAction<ExtremityPathStepType>
) {
const extremityPathStep = action.payload;

if (extremityPathStep === 'destination') {
state.linkedTrains.anteriorTrain = undefined;
} else {
state.linkedTrains.posteriorTrain = undefined;
}
},
updateLinkedTrainExtremity(
state: Draft<OsrdStdcmConfState>,
action: PayloadAction<{
Expand Down

0 comments on commit 236f1d7

Please sign in to comment.