@@ -19,10 +19,10 @@ use utoipa::IntoParams;
19
19
use utoipa:: ToSchema ;
20
20
21
21
use crate :: core:: v2:: simulation:: SimulationResponse ;
22
- use crate :: core:: v2:: stdcm:: STDCMRequest ;
23
22
use crate :: core:: v2:: stdcm:: STDCMResponse ;
24
23
use crate :: core:: v2:: stdcm:: TrainRequirement ;
25
24
use crate :: core:: v2:: stdcm:: { STDCMPathItem , STDCMWorkSchedule , UndirectedTrackRange } ;
25
+ use crate :: core:: v2:: stdcm:: { STDCMRequest , STDCMStepTimingData } ;
26
26
use crate :: core:: AsCoreRequest ;
27
27
use crate :: core:: CoreClient ;
28
28
use crate :: error:: Result ;
@@ -76,6 +76,7 @@ pub struct STDCMRequestPayload {
76
76
rolling_stock_id : i64 ,
77
77
comfort : Comfort ,
78
78
/// By how long we can shift the departure time in milliseconds
79
+ /// Deprecated, first step data should be used instead
79
80
#[ serde( default = "default_maximum_departure_delay" ) ]
80
81
#[ schema( default = default_maximum_departure_delay) ]
81
82
maximum_departure_delay : u64 ,
@@ -108,11 +109,17 @@ struct PathfindingItem {
108
109
/// The associated location
109
110
location : PathItemLocation ,
110
111
/// 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 > ,
112
119
/// 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 ,
114
121
/// 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 ,
116
123
}
117
124
118
125
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
261
268
data. start_time . unwrap_or (
262
269
data. steps
263
270
. 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 ) )
265
273
. unwrap_or (
266
274
get_earliest_step_time ( data) - Duration :: milliseconds ( maximum_run_time as i64 ) ,
267
275
) ,
@@ -271,13 +279,12 @@ fn get_earliest_departure_time(data: &STDCMRequestPayload, maximum_run_time: u64
271
279
/// Returns the earliest time that has been set on any step
272
280
fn get_earliest_step_time ( data : & STDCMRequestPayload ) -> DateTime < Utc > {
273
281
// Get the earliest time that has been specified for any step
274
- * data
275
- . start_time
276
- . as_ref ( )
282
+ data. start_time
277
283
. or_else ( || {
278
284
data. steps
279
285
. iter ( )
280
- . flat_map ( |step| step. arrival_time . iter ( ) )
286
+ . flat_map ( |step| step. timing_data . iter ( ) )
287
+ . map ( |data| data. arrival_time )
281
288
. next ( )
282
289
} )
283
290
. expect ( "No time specified for stdcm request" )
@@ -425,9 +432,13 @@ async fn parse_stdcm_steps(
425
432
. map ( |( track_offset, path_item) | STDCMPathItem {
426
433
stop_duration : path_item. duration ,
427
434
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
+ } ) ,
431
442
} )
432
443
. collect ( ) )
433
444
}
0 commit comments