Skip to content

Commit c5fe5cc

Browse files
woshilapinyounesschrifi
authored andcommitted
editoast: move 'simulation_response' one module up
Signed-off-by: Jean SIMARD <[email protected]> Signed-off-by: Youness CHRIFI ALAOUI <[email protected]>
1 parent 014c70f commit c5fe5cc

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
lines changed

editoast/src/views/mod.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use crate::client::get_app_version;
7777
use crate::core::mq_client;
7878
use crate::core::pathfinding::PathfindingInputError;
7979
use crate::core::pathfinding::PathfindingNotFound;
80+
use crate::core::simulation::SimulationResponse;
8081
use crate::core::version::CoreVersionRequest;
8182
use crate::core::AsCoreRequest;
8283
use crate::core::CoreClient;
@@ -93,6 +94,7 @@ use crate::map::MapLayers;
9394
use crate::models;
9495
use crate::models::auth::PgAuthDriver;
9596
use crate::valkey_utils::ValkeyConfig;
97+
use crate::views::path::pathfinding::PathfindingFailure;
9698
use crate::ValkeyClient;
9799

98100
crate::routes! {
@@ -172,7 +174,7 @@ pub struct InfraIdQueryParam {
172174

173175
#[derive(Debug, PartialEq, Serialize, Deserialize, ToSchema)]
174176
#[serde(tag = "status", rename_all = "snake_case")]
175-
pub enum SimulationSummaryResult {
177+
enum SimulationSummaryResult {
176178
/// Minimal information on a simulation's result
177179
Success {
178180
/// Length of a path in mm
@@ -201,6 +203,45 @@ pub enum SimulationSummaryResult {
201203
PathfindingInputError(PathfindingInputError),
202204
}
203205

206+
fn simulation_response(sim: SimulationResponse) -> SimulationSummaryResult {
207+
match sim {
208+
SimulationResponse::Success {
209+
final_output,
210+
provisional,
211+
base,
212+
..
213+
} => {
214+
let report = final_output.report_train;
215+
SimulationSummaryResult::Success {
216+
length: *report.positions.last().unwrap(),
217+
time: *report.times.last().unwrap(),
218+
energy_consumption: report.energy_consumption,
219+
path_item_times_final: report.path_item_times.clone(),
220+
path_item_times_provisional: provisional.path_item_times.clone(),
221+
path_item_times_base: base.path_item_times.clone(),
222+
}
223+
}
224+
SimulationResponse::PathfindingFailed { pathfinding_failed } => match pathfinding_failed {
225+
PathfindingFailure::InternalError { core_error } => {
226+
SimulationSummaryResult::PathfindingFailure { core_error }
227+
}
228+
229+
PathfindingFailure::PathfindingInputError(input_error) => {
230+
SimulationSummaryResult::PathfindingInputError(input_error)
231+
}
232+
233+
PathfindingFailure::PathfindingNotFound(not_found) => {
234+
SimulationSummaryResult::PathfindingNotFound(not_found)
235+
}
236+
},
237+
SimulationResponse::SimulationFailed { core_error } => {
238+
SimulationSummaryResult::SimulationFailed {
239+
error_type: core_error.get_type().into(),
240+
}
241+
}
242+
}
243+
}
244+
204245
/// Represents the bundle of information about the issuer of a request
205246
/// that can be extracted form recognized headers.
206247
#[derive(Debug, Clone)]

editoast/src/views/paced_train.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use utoipa::ToSchema;
2727

2828
use super::path::pathfinding::PathfindingResult;
2929
use super::projection::ProjectPathForm;
30-
use super::train_schedule::simulation_response;
30+
use super::simulation_response;
3131
use super::train_schedule::train_simulation_batch;
3232
use super::AppState;
3333
use super::AuthenticationExt;
@@ -559,8 +559,8 @@ mod tests {
559559
path_item_times: vec![0, 1000, 2000, 3000]
560560
},
561561
provisional: ReportTrain {
562-
positions: vec![],
563-
times: vec![0, 10],
562+
positions: vec![0],
563+
times: vec![0],
564564
speeds: vec![],
565565
energy_consumption: 0.0,
566566
path_item_times: vec![0, 1000, 2000, 3000]

editoast/src/views/train_schedule.rs

+1-40
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use crate::models::prelude::*;
4949
use crate::models::train_schedule::TrainSchedule;
5050
use crate::models::train_schedule::TrainScheduleChangeset;
5151
use crate::views::path::pathfinding::pathfinding_from_train;
52-
use crate::views::path::pathfinding::PathfindingFailure;
5352
use crate::views::path::pathfinding::PathfindingResult;
5453
use crate::views::path::pathfinding_from_train_batch;
5554
use crate::views::path::projection::PathProjection;
@@ -70,6 +69,7 @@ use crate::RollingStockModel;
7069
use crate::ValkeyClient;
7170

7271
use super::projection::ProjectPathForm;
72+
use super::simulation_response;
7373
use super::SimulationSummaryResult;
7474

7575
crate::routes! {
@@ -636,45 +636,6 @@ struct SimulationBatchForm {
636636
ids: HashSet<i64>,
637637
}
638638

639-
pub fn simulation_response(sim: SimulationResponse) -> SimulationSummaryResult {
640-
match sim {
641-
SimulationResponse::Success {
642-
final_output,
643-
provisional,
644-
base,
645-
..
646-
} => {
647-
let report = final_output.report_train;
648-
SimulationSummaryResult::Success {
649-
length: *report.positions.last().unwrap(),
650-
time: *report.times.last().unwrap(),
651-
energy_consumption: report.energy_consumption,
652-
path_item_times_final: report.path_item_times.clone(),
653-
path_item_times_provisional: provisional.path_item_times.clone(),
654-
path_item_times_base: base.path_item_times.clone(),
655-
}
656-
}
657-
SimulationResponse::PathfindingFailed { pathfinding_failed } => match pathfinding_failed {
658-
PathfindingFailure::InternalError { core_error } => {
659-
SimulationSummaryResult::PathfindingFailure { core_error }
660-
}
661-
662-
PathfindingFailure::PathfindingInputError(input_error) => {
663-
SimulationSummaryResult::PathfindingInputError(input_error)
664-
}
665-
666-
PathfindingFailure::PathfindingNotFound(not_found) => {
667-
SimulationSummaryResult::PathfindingNotFound(not_found)
668-
}
669-
},
670-
SimulationResponse::SimulationFailed { core_error } => {
671-
SimulationSummaryResult::SimulationFailed {
672-
error_type: core_error.get_type().into(),
673-
}
674-
}
675-
}
676-
}
677-
678639
/// Associate each train id with its simulation summary response
679640
/// If the simulation fails, it associates the reason: pathfinding failed or running time failed
680641
#[utoipa::path(

0 commit comments

Comments
 (0)