Skip to content

Commit

Permalink
front: fix stdcm passages
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Nov 22, 2024
1 parent cc744ff commit 28c965c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
29 changes: 20 additions & 9 deletions front/src/applications/stdcm/utils/formatStdcmConf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { kmhToMs, tToKg } from 'utils/physics';
import { ISO8601Duration2sec, sec2ms } from 'utils/timeManipulation';

import createMargin from './createMargin';
import { StdcmStopTypes } from '../types';

type ValidStdcmConfig = {
rollingStockId: number;
Expand Down Expand Up @@ -139,15 +140,25 @@ export const checkStdcmConf = (
const { arrival, tolerances, stopFor, arrivalType } = step;
const location = getStepLocation(step);

const duration = stopFor ? sec2ms(ISO8601Duration2sec(stopFor) || Number(stopFor)) : 0;
const timingData =
arrivalType === 'preciseTime' && arrival
? {
arrival_time: arrival,
arrival_time_tolerance_before: sec2ms(tolerances?.before ?? 0),
arrival_time_tolerance_after: sec2ms(tolerances?.after ?? 0),
}
: undefined;
let timingData: PathfindingItem['timing_data'] | undefined;
let duration: number | undefined;
if (step.isVia) {
if (step.stopType !== StdcmStopTypes.PASSAGE_TIME) {
duration = stopFor ? sec2ms(ISO8601Duration2sec(stopFor) || Number(stopFor)) : 0;
}
} else {
// if the step is either the origin or the destination,
// it must have a duration
duration = 0;
if (arrivalType === 'preciseTime' && arrival) {
timingData = {
arrival_time: arrival,
arrival_time_tolerance_before: sec2ms(tolerances?.before ?? 0),
arrival_time_tolerance_after: sec2ms(tolerances?.after ?? 0),
};
}
}

return {
duration,
location,
Expand Down
8 changes: 4 additions & 4 deletions front/tests/assets/stdcm/stdcmAllStops.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"operationalPoint": "Mid_West_station",
"code": "BV",
"endStop": "",
"passageStop": "01:17",
"passageStop": "01:16",
"startStop": "",
"weight": "=",
"refEngine": "="
Expand All @@ -23,9 +23,9 @@
"index": 3,
"operationalPoint": "Mid_East_station",
"code": "BV",
"endStop": "01:23",
"endStop": "01:22",
"passageStop": "3 min",
"startStop": "01:26",
"startStop": "01:25",
"weight": "=",
"refEngine": "="
},
Expand All @@ -43,7 +43,7 @@
"index": 5,
"operationalPoint": "South_station",
"code": "BV",
"endStop": "01:41",
"endStop": "01:40",
"passageStop": "",
"startStop": "",
"weight": "400t",
Expand Down
8 changes: 4 additions & 4 deletions front/tests/assets/stdcm/stdcmWithAllVia.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"operationalPoint": "Mid_West_station",
"code": "BV",
"endStop": "",
"passageStop": "20:42",
"passageStop": "20:41",
"startStop": "",
"weight": "=",
"refEngine": "="
Expand All @@ -24,7 +24,7 @@
"operationalPoint": "Mid_East_station",
"code": "BV",
"endStop": "",
"passageStop": "20:47",
"passageStop": "20:46",
"startStop": "",
"weight": "=",
"refEngine": "="
Expand All @@ -34,7 +34,7 @@
"operationalPoint": "North_station",
"code": "BV",
"endStop": "",
"passageStop": "20:53",
"passageStop": "20:52",
"startStop": "",
"weight": "=",
"refEngine": "="
Expand All @@ -43,7 +43,7 @@
"index": 5,
"operationalPoint": "South_station",
"code": "BV",
"endStop": "20:57",
"endStop": "20:56",
"passageStop": "",
"startStop": "",
"weight": "400t",
Expand Down
4 changes: 2 additions & 2 deletions front/tests/assets/stdcm/stdcmWithoutAllVia.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"operationalPoint": "Mid_West_station",
"code": "BV",
"endStop": "",
"passageStop": "20:42",
"passageStop": "20:41",
"startStop": "",
"weight": "=",
"refEngine": "="
Expand All @@ -23,7 +23,7 @@
"index": 3,
"operationalPoint": "South_station",
"code": "BV",
"endStop": "20:57",
"endStop": "20:56",
"passageStop": "",
"startStop": "",
"weight": "400t",
Expand Down

0 comments on commit 28c965c

Please sign in to comment.