Skip to content

Commit 6d39b82

Browse files
committed
fixup! editoast: stdcm: add arrival time parameters
1 parent a3ce630 commit 6d39b82

File tree

5 files changed

+83
-44
lines changed

5 files changed

+83
-44
lines changed

core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ class STDCMRequestV2(
6060
class STDCMPathItem(
6161
val locations: List<TrackLocation>,
6262
@Json(name = "stop_duration") val stopDuration: Duration?,
63-
@Json(name = "arrival_time") val arrivalTime: ZonedDateTime?,
64-
@Json(name = "arrival_time_tolerance_before") val arrivalTimeToleranceBefore: Duration?,
65-
@Json(name = "arrival_time_tolerance_after") val arrivalTimeToleranceAfter: Duration?,
63+
@Json(name = "step_timing_data") val stepTimingData: StepTimingData?,
64+
)
65+
66+
data class StepTimingData(
67+
@Json(name = "arrival_time") val arrivalTime: ZonedDateTime,
68+
@Json(name = "arrival_time_tolerance_before") val arrivalTimeToleranceBefore: Duration,
69+
@Json(name = "arrival_time_tolerance_after") val arrivalTimeToleranceAfter: Duration,
6670
)
6771

6872
class TrackOffset(val track: String, val offset: Offset<TrackSection>)

editoast/openapi.yaml

+31-19
Original file line numberDiff line numberDiff line change
@@ -5202,23 +5202,6 @@ components:
52025202
type: object
52035203
PathfindingItem:
52045204
properties:
5205-
arrival_time:
5206-
description: Time at which the train should arrive at the location, if specified
5207-
format: date-time
5208-
nullable: true
5209-
type: string
5210-
arrival_time_tolerance_after:
5211-
description: The train may arrive up to this duration after the expected arrival time
5212-
format: int64
5213-
minimum: 0
5214-
nullable: true
5215-
type: integer
5216-
arrival_time_tolerance_before:
5217-
description: The train may arrive up to this duration before the expected arrival time
5218-
format: int64
5219-
minimum: 0
5220-
nullable: true
5221-
type: integer
52225205
duration:
52235206
description: The stop duration in milliseconds, None if the train does not stop.
52245207
format: int64
@@ -5227,6 +5210,10 @@ components:
52275210
type: integer
52285211
location:
52295212
$ref: '#/components/schemas/PathItemLocation'
5213+
timing_data:
5214+
allOf:
5215+
- $ref: '#/components/schemas/StepTimingData'
5216+
nullable: true
52305217
required:
52315218
- location
52325219
type: object
@@ -6893,7 +6880,9 @@ components:
68936880
type: string
68946881
maximum_departure_delay:
68956882
default: 432000
6896-
description: By how long we can shift the departure time in milliseconds
6883+
description: |-
6884+
By how long we can shift the departure time in milliseconds
6885+
Deprecated, first step data should be used instead
68976886
format: int64
68986887
minimum: 0
68996888
type: integer
@@ -8193,6 +8182,27 @@ components:
81938182
- ranges
81948183
- distribution
81958184
type: object
8185+
StepTimingData:
8186+
properties:
8187+
arrival_time:
8188+
description: Time at which the train should arrive at the location
8189+
format: date-time
8190+
type: string
8191+
arrival_time_tolerance_after:
8192+
description: The train may arrive up to this duration after the expected arrival time
8193+
format: int64
8194+
minimum: 0
8195+
type: integer
8196+
arrival_time_tolerance_before:
8197+
description: The train may arrive up to this duration before the expected arrival time
8198+
format: int64
8199+
minimum: 0
8200+
type: integer
8201+
required:
8202+
- arrival_time
8203+
- arrival_time_tolerance_before
8204+
- arrival_time_tolerance_after
8205+
type: object
81968206
Study:
81978207
properties:
81988208
actual_end_date:
@@ -12451,7 +12461,9 @@ paths:
1245112461
type: string
1245212462
maximum_departure_delay:
1245312463
default: 432000
12454-
description: By how long we can shift the departure time in milliseconds
12464+
description: |-
12465+
By how long we can shift the departure time in milliseconds
12466+
Deprecated, first step data should be used instead
1245512467
format: int64
1245612468
minimum: 0
1245712469
type: integer

editoast/src/core/v2/stdcm.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,19 @@ pub struct STDCMPathItem {
6464
pub locations: Vec<TrackOffset>,
6565
/// Stop duration in milliseconds. None if the train does not stop at this path item.
6666
pub stop_duration: Option<u64>,
67-
/// Time the train should arrive at this point, if specified
68-
pub arrival_time: Option<DateTime<Utc>>,
67+
/// If specified, describes when the train may arrive at the location
68+
pub step_timing_data: Option<STDCMStepTimingData>,
69+
}
70+
71+
/// Contains the data of a step timing, when it is specified
72+
#[derive(Debug, Serialize)]
73+
pub struct STDCMStepTimingData {
74+
/// Time the train should arrive at this point
75+
pub arrival_time: DateTime<Utc>,
6976
/// Tolerance for the arrival time, when it arrives before the expected time, in ms
70-
pub arrival_time_tolerance_before: Option<u64>,
77+
pub arrival_time_tolerance_before: u64,
7178
/// Tolerance for the arrival time, when it arrives after the expected time, in ms
72-
pub arrival_time_tolerance_after: Option<u64>,
79+
pub arrival_time_tolerance_after: u64,
7380
}
7481

7582
/// Lighter description of a work schedule, only contains what's relevant

editoast/src/views/v2/timetable/stdcm.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use utoipa::IntoParams;
1919
use utoipa::ToSchema;
2020

2121
use crate::core::v2::simulation::SimulationResponse;
22-
use crate::core::v2::stdcm::STDCMRequest;
2322
use crate::core::v2::stdcm::STDCMResponse;
2423
use crate::core::v2::stdcm::TrainRequirement;
2524
use crate::core::v2::stdcm::{STDCMPathItem, STDCMWorkSchedule, UndirectedTrackRange};
25+
use crate::core::v2::stdcm::{STDCMRequest, STDCMStepTimingData};
2626
use crate::core::AsCoreRequest;
2727
use crate::core::CoreClient;
2828
use crate::error::Result;
@@ -48,6 +48,7 @@ crate::routes! {
4848
editoast_common::schemas! {
4949
STDCMRequestPayload,
5050
PathfindingItem,
51+
StepTimingData,
5152
}
5253

5354
#[derive(Debug, Error, EditoastError, Serialize)]
@@ -76,6 +77,7 @@ pub struct STDCMRequestPayload {
7677
rolling_stock_id: i64,
7778
comfort: Comfort,
7879
/// By how long we can shift the departure time in milliseconds
80+
/// Deprecated, first step data should be used instead
7981
#[serde(default = "default_maximum_departure_delay")]
8082
#[schema(default = default_maximum_departure_delay)]
8183
maximum_departure_delay: u64,
@@ -108,11 +110,17 @@ struct PathfindingItem {
108110
/// The associated location
109111
location: PathItemLocation,
110112
/// Time at which the train should arrive at the location, if specified
111-
arrival_time: Option<DateTime<Utc>>,
113+
timing_data: Option<StepTimingData>,
114+
}
115+
116+
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, ToSchema)]
117+
struct StepTimingData {
118+
/// Time at which the train should arrive at the location
119+
arrival_time: DateTime<Utc>,
112120
/// The train may arrive up to this duration before the expected arrival time
113-
arrival_time_tolerance_before: Option<u64>,
121+
arrival_time_tolerance_before: u64,
114122
/// The train may arrive up to this duration after the expected arrival time
115-
arrival_time_tolerance_after: Option<u64>,
123+
arrival_time_tolerance_after: u64,
116124
}
117125

118126
const TWO_HOURS_IN_MILLISECONDS: u64 = 2 * 60 * 60 * 60;
@@ -261,7 +269,8 @@ fn get_earliest_departure_time(data: &STDCMRequestPayload, maximum_run_time: u64
261269
data.start_time.unwrap_or(
262270
data.steps
263271
.first()
264-
.and_then(|step| step.arrival_time)
272+
.and_then(|step| step.timing_data.clone())
273+
.and_then(|data| Option::from(data.arrival_time))
265274
.unwrap_or(
266275
get_earliest_step_time(data) - Duration::milliseconds(maximum_run_time as i64),
267276
),
@@ -271,13 +280,12 @@ fn get_earliest_departure_time(data: &STDCMRequestPayload, maximum_run_time: u64
271280
/// Returns the earliest time that has been set on any step
272281
fn get_earliest_step_time(data: &STDCMRequestPayload) -> DateTime<Utc> {
273282
// Get the earliest time that has been specified for any step
274-
*data
275-
.start_time
276-
.as_ref()
283+
data.start_time
277284
.or_else(|| {
278285
data.steps
279286
.iter()
280-
.flat_map(|step| step.arrival_time.iter())
287+
.flat_map(|step| step.timing_data.iter())
288+
.map(|data| data.arrival_time)
281289
.next()
282290
})
283291
.expect("No time specified for stdcm request")
@@ -425,9 +433,13 @@ async fn parse_stdcm_steps(
425433
.map(|(track_offset, path_item)| STDCMPathItem {
426434
stop_duration: path_item.duration,
427435
locations: track_offset.to_vec(),
428-
arrival_time: path_item.arrival_time,
429-
arrival_time_tolerance_before: path_item.arrival_time_tolerance_before,
430-
arrival_time_tolerance_after: path_item.arrival_time_tolerance_after,
436+
step_timing_data: path_item.timing_data.as_ref().map(|timing_data| {
437+
STDCMStepTimingData {
438+
arrival_time: timing_data.arrival_time,
439+
arrival_time_tolerance_before: timing_data.arrival_time_tolerance_before,
440+
arrival_time_tolerance_after: timing_data.arrival_time_tolerance_after,
441+
}
442+
}),
431443
})
432444
.collect())
433445
}

front/src/common/api/generatedEditoastApi.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ export type PostV2TimetableByIdStdcmApiArg = {
17531753
comfort: Comfort;
17541754
/** Can be a percentage `X%`, a time in minutes per 100 kilometer `Xmin/100km` or `None` */
17551755
margin?: string | null;
1756-
/** By how long we can shift the departure time in milliseconds */
1756+
/** By how long we can shift the departure time in milliseconds
1757+
Deprecated, first step data should be used instead */
17571758
maximum_departure_delay?: number;
17581759
/** Specifies how long the total run time can be in milliseconds */
17591760
maximum_run_time?: number | null;
@@ -3709,16 +3710,19 @@ export type PathItemLocation =
37093710
/** The [UIC](https://en.wikipedia.org/wiki/List_of_UIC_country_codes) code of an operational point */
37103711
uic: number;
37113712
};
3712-
export type PathfindingItem = {
3713-
/** Time at which the train should arrive at the location, if specified */
3714-
arrival_time?: string | null;
3713+
export type StepTimingData = {
3714+
/** Time at which the train should arrive at the location */
3715+
arrival_time: string;
37153716
/** The train may arrive up to this duration after the expected arrival time */
3716-
arrival_time_tolerance_after?: number | null;
3717+
arrival_time_tolerance_after: number;
37173718
/** The train may arrive up to this duration before the expected arrival time */
3718-
arrival_time_tolerance_before?: number | null;
3719+
arrival_time_tolerance_before: number;
3720+
};
3721+
export type PathfindingItem = {
37193722
/** The stop duration in milliseconds, None if the train does not stop. */
37203723
duration?: number | null;
37213724
location: PathItemLocation;
3725+
timing_data?: StepTimingData | null;
37223726
};
37233727
export type Distribution = 'STANDARD' | 'MARECO';
37243728
export type TrainScheduleBase = {

0 commit comments

Comments
 (0)