Skip to content

Commit 29d5e78

Browse files
younesschrifitheocrsb
authored andcommitted
editoast: replace exception_key with excpetion_id
Signed-off-by: Youness CHRIFI ALAOUI <youness.chrifi@gmail.com>
1 parent 20bce0e commit 29d5e78

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

editoast/src/views/timetable/paced_train.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub(in crate::views) struct TrainScheduleSummaryResponse {
262262
#[derive(Debug, Clone)]
263263
struct SimulationContext {
264264
paced_train_id: i64,
265-
exception_key: Option<String>,
265+
exception_id: Option<i64>,
266266
train_schedule: schemas::TrainOccurrence,
267267
}
268268

@@ -340,18 +340,16 @@ pub(in crate::views) async fn simulation_summary(
340340
let ts_exceptions = exceptions.remove(&paced_train.id).unwrap_or_default();
341341
std::iter::once(SimulationContext {
342342
paced_train_id: paced_train.id,
343-
exception_key: None,
343+
exception_id: None,
344344
train_schedule: paced_train.clone().into_train_occurrence(),
345345
})
346346
.chain(
347347
ts_exceptions
348348
.into_iter()
349-
.map(|exception| {
350-
SimulationContext {
351-
paced_train_id: paced_train.id,
352-
exception_key: exception.key.clone(), // TODO use exception.id
353-
train_schedule: paced_train.apply_train_schedule_exception(&exception),
354-
}
349+
.map(|exception| SimulationContext {
350+
paced_train_id: paced_train.id,
351+
exception_id: Some(exception.id),
352+
train_schedule: paced_train.apply_train_schedule_exception(&exception),
355353
})
356354
.collect::<Vec<_>>(),
357355
)
@@ -379,7 +377,7 @@ pub(in crate::views) async fn simulation_summary(
379377
let results = simulation_contexts.into_iter().zip(simulations).fold(
380378
HashMap::<i64, TrainScheduleSummaryResponse>::new(),
381379
|mut map, (simulation_context, (simulation, _path))| {
382-
if let Some(exception_key) = &simulation_context.exception_key {
380+
if let Some(exception_key) = &simulation_context.exception_id {
383381
if !Arc::ptr_eq(&base_simulation, &simulation) {
384382
map.entry(simulation_context.paced_train_id)
385383
.and_modify(|summary| {
@@ -843,15 +841,13 @@ pub(in crate::views) async fn project_path(
843841
let ts_exceptions = exceptions.remove(&train_schedule.id).unwrap_or_default();
844842
std::iter::once(SimulationContext {
845843
paced_train_id: train_schedule.id,
846-
exception_key: None,
844+
exception_id: None,
847845
train_schedule: train_schedule.clone().into_train_occurrence(),
848846
})
849-
.chain(ts_exceptions.iter().map(|exception| {
850-
SimulationContext {
851-
paced_train_id: train_schedule.id,
852-
exception_key: exception.key.clone(), // TODO use exception.id instead of key
853-
train_schedule: train_schedule.apply_train_schedule_exception(exception),
854-
}
847+
.chain(ts_exceptions.iter().map(|exception| SimulationContext {
848+
paced_train_id: train_schedule.id,
849+
exception_id: Some(exception.id),
850+
train_schedule: train_schedule.apply_train_schedule_exception(exception),
855851
}))
856852
.collect::<Vec<_>>()
857853
})
@@ -879,14 +875,14 @@ pub(in crate::views) async fn project_path(
879875
let results = simulation_contexts.into_iter().enumerate().fold(
880876
HashMap::<i64, ProjectPathTrainScheduleResult>::new(),
881877
|mut results, (index, simulation_context)| {
882-
if let Some(exception_key) = simulation_context.exception_key {
878+
if let Some(exception_key) = simulation_context.exception_id {
883879
if !Arc::ptr_eq(&base_project_path, &project_path_result[index]) {
884880
results
885881
.get_mut(&simulation_context.paced_train_id)
886882
.expect("paced_train_id should exist")
887883
.exceptions
888884
.insert(
889-
exception_key,
885+
exception_key.to_string(),
890886
Arc::unwrap_or_clone(project_path_result[index].clone()),
891887
);
892888
}
@@ -1172,19 +1168,16 @@ pub(in crate::views) async fn occupancy_blocks(
11721168
let ts_exceptions = exceptions.remove(&train_schedule.id).unwrap_or_default();
11731169
std::iter::once(SimulationContext {
11741170
paced_train_id: train_schedule.id,
1175-
exception_key: None,
1171+
exception_id: None,
11761172
train_schedule: train_schedule.clone().into_train_occurrence(),
11771173
})
11781174
.chain(
11791175
ts_exceptions
11801176
.iter()
1181-
.map(|exception| {
1182-
SimulationContext {
1183-
paced_train_id: train_schedule.id,
1184-
exception_key: exception.key.clone(), // TODO use exception.id
1185-
train_schedule: train_schedule
1186-
.apply_train_schedule_exception(exception),
1187-
}
1177+
.map(|exception| SimulationContext {
1178+
paced_train_id: train_schedule.id,
1179+
exception_id: Some(exception.id),
1180+
train_schedule: train_schedule.apply_train_schedule_exception(exception),
11881181
})
11891182
.collect::<Vec<_>>(),
11901183
)
@@ -1212,14 +1205,14 @@ pub(in crate::views) async fn occupancy_blocks(
12121205
let mut results = HashMap::<i64, OccupancyBlocksTrainScheduleResult>::new();
12131206

12141207
for (index, simulation_context) in simulation_contexts.into_iter().enumerate() {
1215-
if let Some(exception_key) = simulation_context.exception_key {
1208+
if let Some(exception_key) = simulation_context.exception_id {
12161209
if !Arc::ptr_eq(&base_occupancy_blocks, &occupancy_blocks_result[index]) {
12171210
results
12181211
.get_mut(&simulation_context.paced_train_id)
12191212
.expect("paced_train_id should exist")
12201213
.exceptions
12211214
.insert(
1222-
exception_key,
1215+
exception_key.to_string(),
12231216
Arc::unwrap_or_clone(occupancy_blocks_result[index].clone()),
12241217
);
12251218
}
@@ -2364,7 +2357,7 @@ mod tests {
23642357
path_item_respect_margins: vec![true, true, true, true],
23652358
},
23662359
exceptions: [(
2367-
"change_initial_speed".to_string(),
2360+
_change_train_name_exception.id.to_string(),
23682361
// Simulation of the exception is the same than base
23692362
// because all simulation results from core are identical stubs
23702363
SummaryResponse::Success {

0 commit comments

Comments
 (0)