From 1328511db00b13f7229c4524f202ddcec1ab2300 Mon Sep 17 00:00:00 2001 From: Clara Ni Date: Fri, 8 Nov 2024 10:21:14 +0100 Subject: [PATCH] front: fix stdcm passages Signed-off-by: Clara Ni --- .../stdcm/utils/formatStdcmConf.ts | 29 +++++++++++++------ front/tests/assets/stdcm/stdcmAllStops.json | 8 ++--- front/tests/assets/stdcm/stdcmWithAllVia.json | 8 ++--- .../assets/stdcm/stdcmWithoutAllVia.json | 4 +-- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/front/src/applications/stdcm/utils/formatStdcmConf.ts b/front/src/applications/stdcm/utils/formatStdcmConf.ts index 4fbf6503fb3..38fe95b9b09 100644 --- a/front/src/applications/stdcm/utils/formatStdcmConf.ts +++ b/front/src/applications/stdcm/utils/formatStdcmConf.ts @@ -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; @@ -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, diff --git a/front/tests/assets/stdcm/stdcmAllStops.json b/front/tests/assets/stdcm/stdcmAllStops.json index 9a7e35a1bf6..73af0b57937 100644 --- a/front/tests/assets/stdcm/stdcmAllStops.json +++ b/front/tests/assets/stdcm/stdcmAllStops.json @@ -14,7 +14,7 @@ "operationalPoint": "Mid_West_station", "code": "BV", "endStop": "", - "passageStop": "01:17", + "passageStop": "01:16", "startStop": "", "weight": "=", "refEngine": "=" @@ -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": "=" }, @@ -43,7 +43,7 @@ "index": 5, "operationalPoint": "South_station", "code": "BV", - "endStop": "01:41", + "endStop": "01:40", "passageStop": "", "startStop": "", "weight": "400t", diff --git a/front/tests/assets/stdcm/stdcmWithAllVia.json b/front/tests/assets/stdcm/stdcmWithAllVia.json index 5a39705a532..58fc36edc89 100644 --- a/front/tests/assets/stdcm/stdcmWithAllVia.json +++ b/front/tests/assets/stdcm/stdcmWithAllVia.json @@ -14,7 +14,7 @@ "operationalPoint": "Mid_West_station", "code": "BV", "endStop": "", - "passageStop": "20:42", + "passageStop": "20:41", "startStop": "", "weight": "=", "refEngine": "=" @@ -24,7 +24,7 @@ "operationalPoint": "Mid_East_station", "code": "BV", "endStop": "", - "passageStop": "20:47", + "passageStop": "20:46", "startStop": "", "weight": "=", "refEngine": "=" @@ -34,7 +34,7 @@ "operationalPoint": "North_station", "code": "BV", "endStop": "", - "passageStop": "20:53", + "passageStop": "20:52", "startStop": "", "weight": "=", "refEngine": "=" @@ -43,7 +43,7 @@ "index": 5, "operationalPoint": "South_station", "code": "BV", - "endStop": "20:57", + "endStop": "20:56", "passageStop": "", "startStop": "", "weight": "400t", diff --git a/front/tests/assets/stdcm/stdcmWithoutAllVia.json b/front/tests/assets/stdcm/stdcmWithoutAllVia.json index 6c16b46c3ae..4ecd64c702b 100644 --- a/front/tests/assets/stdcm/stdcmWithoutAllVia.json +++ b/front/tests/assets/stdcm/stdcmWithoutAllVia.json @@ -14,7 +14,7 @@ "operationalPoint": "Mid_West_station", "code": "BV", "endStop": "", - "passageStop": "20:42", + "passageStop": "20:41", "startStop": "", "weight": "=", "refEngine": "=" @@ -23,7 +23,7 @@ "index": 3, "operationalPoint": "South_station", "code": "BV", - "endStop": "20:57", + "endStop": "20:56", "passageStop": "", "startStop": "", "weight": "400t",