Skip to content

Commit 24176d7

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

File tree

4 files changed

+51
-38
lines changed

4 files changed

+51
-38
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

+10-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
@@ -12451,7 +12440,9 @@ paths:
1245112440
type: string
1245212441
maximum_departure_delay:
1245312442
default: 432000
12454-
description: By how long we can shift the departure time in milliseconds
12443+
description: |-
12444+
By how long we can shift the departure time in milliseconds
12445+
Deprecated, first step data should be used instead
1245512446
format: int64
1245612447
minimum: 0
1245712448
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

+23-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;
@@ -76,6 +76,7 @@ pub struct STDCMRequestPayload {
7676
rolling_stock_id: i64,
7777
comfort: Comfort,
7878
/// By how long we can shift the departure time in milliseconds
79+
/// Deprecated, first step data should be used instead
7980
#[serde(default = "default_maximum_departure_delay")]
8081
#[schema(default = default_maximum_departure_delay)]
8182
maximum_departure_delay: u64,
@@ -108,11 +109,17 @@ struct PathfindingItem {
108109
/// The associated location
109110
location: PathItemLocation,
110111
/// Time at which the train should arrive at the location, if specified
111-
arrival_time: Option<DateTime<Utc>>,
112+
timing_data: Option<StepTimingData>,
113+
}
114+
115+
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, ToSchema)]
116+
struct StepTimingData {
117+
/// Time at which the train should arrive at the location
118+
arrival_time: DateTime<Utc>,
112119
/// The train may arrive up to this duration before the expected arrival time
113-
arrival_time_tolerance_before: Option<u64>,
120+
arrival_time_tolerance_before: u64,
114121
/// The train may arrive up to this duration after the expected arrival time
115-
arrival_time_tolerance_after: Option<u64>,
122+
arrival_time_tolerance_after: u64,
116123
}
117124

118125
const TWO_HOURS_IN_MILLISECONDS: u64 = 2 * 60 * 60 * 60;
@@ -261,7 +268,8 @@ fn get_earliest_departure_time(data: &STDCMRequestPayload, maximum_run_time: u64
261268
data.start_time.unwrap_or(
262269
data.steps
263270
.first()
264-
.and_then(|step| step.arrival_time)
271+
.and_then(|step| step.timing_data.clone())
272+
.and_then(|data| Option::from(data.arrival_time))
265273
.unwrap_or(
266274
get_earliest_step_time(data) - Duration::milliseconds(maximum_run_time as i64),
267275
),
@@ -271,13 +279,12 @@ fn get_earliest_departure_time(data: &STDCMRequestPayload, maximum_run_time: u64
271279
/// Returns the earliest time that has been set on any step
272280
fn get_earliest_step_time(data: &STDCMRequestPayload) -> DateTime<Utc> {
273281
// Get the earliest time that has been specified for any step
274-
*data
275-
.start_time
276-
.as_ref()
282+
data.start_time
277283
.or_else(|| {
278284
data.steps
279285
.iter()
280-
.flat_map(|step| step.arrival_time.iter())
286+
.flat_map(|step| step.timing_data.iter())
287+
.map(|data| data.arrival_time)
281288
.next()
282289
})
283290
.expect("No time specified for stdcm request")
@@ -425,9 +432,13 @@ async fn parse_stdcm_steps(
425432
.map(|(track_offset, path_item)| STDCMPathItem {
426433
stop_duration: path_item.duration,
427434
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,
435+
step_timing_data: path_item.timing_data.as_ref().map(|timing_data| {
436+
STDCMStepTimingData {
437+
arrival_time: timing_data.arrival_time,
438+
arrival_time_tolerance_before: timing_data.arrival_time_tolerance_before,
439+
arrival_time_tolerance_after: timing_data.arrival_time_tolerance_after,
440+
}
441+
}),
431442
})
432443
.collect())
433444
}

0 commit comments

Comments
 (0)