From 9fa4b7f4c86776b98edf12566147441d6a88ccfc Mon Sep 17 00:00:00 2001 From: Egor Berezovskiy Date: Fri, 22 Nov 2024 13:20:10 +0100 Subject: [PATCH] front: fix pr comments Signed-off-by: Egor Berezovskiy --- editoast/src/core/simulation.rs | 11 ++++++++--- editoast/src/models/fixtures.rs | 6 ++++-- editoast/src/views/path/pathfinding.rs | 14 +++++++++++--- editoast/src/views/timetable/stdcm.rs | 26 ++++++++++---------------- editoast/src/views/train_schedule.rs | 4 +--- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/editoast/src/core/simulation.rs b/editoast/src/core/simulation.rs index adb6a777477..66b71820016 100644 --- a/editoast/src/core/simulation.rs +++ b/editoast/src/core/simulation.rs @@ -4,7 +4,6 @@ use std::collections::HashMap; use editoast_schemas::rolling_stock::EffortCurves; use editoast_schemas::rolling_stock::Gamma; use editoast_schemas::rolling_stock::RollingResistance; -use editoast_schemas::rolling_stock::RollingStock; use editoast_schemas::rolling_stock::TowedRollingStock; use editoast_schemas::train_schedule::Comfort; use editoast_schemas::train_schedule::Distribution; @@ -18,6 +17,7 @@ use utoipa::ToSchema; use super::pathfinding::TrackRange; use crate::core::{AsCoreRequest, Json}; use crate::error::InternalError; +use crate::models::RollingStockModel; use crate::views::path::pathfinding::PathfindingFailure; use derivative::Derivative; use editoast_schemas::primitives::Identifier; @@ -78,11 +78,16 @@ pub struct PhysicsConsistParameters { /// In m/s pub max_speed: Option, pub towed_rolling_stock: Option, - pub traction_engine: RollingStock, + pub traction_engine: RollingStockModel, } impl PhysicsConsistParameters { - pub fn from_traction_engine(traction_engine: RollingStock) -> Self { + pub fn set_traction_engine(mut self, traction_engine: RollingStockModel) -> Self { + self.traction_engine = traction_engine; + self + } + + pub fn from_traction_engine(traction_engine: RollingStockModel) -> Self { PhysicsConsistParameters { max_speed: None, total_length: None, diff --git a/editoast/src/models/fixtures.rs b/editoast/src/models/fixtures.rs index aee9ddae9d2..cfbc55798af 100644 --- a/editoast/src/models/fixtures.rs +++ b/editoast/src/models/fixtures.rs @@ -247,8 +247,10 @@ pub fn create_towed_rolling_stock() -> TowedRollingStock { } } -pub fn create_simple_rolling_stock() -> RollingStock { - RollingStock { +pub fn create_simple_rolling_stock() -> RollingStockModel { + RollingStockModel { + id: 1, + version: 1, name: "SIMPLE_ROLLING_STOCK".to_string(), loading_gauge: LoadingGaugeType::G1, supported_signaling_systems: RollingStockSupportedSignalingSystems(vec![]), diff --git a/editoast/src/views/path/pathfinding.rs b/editoast/src/views/path/pathfinding.rs index ff892b9a171..48e630189cd 100644 --- a/editoast/src/views/path/pathfinding.rs +++ b/editoast/src/views/path/pathfinding.rs @@ -23,6 +23,7 @@ use crate::core::pathfinding::PathfindingInputError; use crate::core::pathfinding::PathfindingNotFound; use crate::core::pathfinding::PathfindingRequest; use crate::core::pathfinding::PathfindingResultSuccess; +use crate::core::simulation::PhysicsConsistParameters; use crate::core::AsCoreRequest; use crate::core::CoreClient; use crate::error::InternalError; @@ -340,7 +341,12 @@ pub async fn pathfinding_from_train( RollingStockModel::retrieve(conn, train_schedule.rolling_stock_name.clone()) .await? .into_iter() - .map(|rs| (rs.name.clone(), rs)) + .map(|rs| { + ( + rs.name.clone(), + PhysicsConsistParameters::from_traction_engine(rs), + ) + }) .collect(); Ok(pathfinding_from_train_batch( @@ -363,7 +369,7 @@ pub async fn pathfinding_from_train_batch( core: Arc, infra: &Infra, train_schedules: &[TrainSchedule], - rolling_stocks: &HashMap, + consists: &HashMap, ) -> Result> { let mut results = vec![ PathfindingResult::Failure(PathfindingFailure::PathfindingInputError( @@ -376,7 +382,7 @@ pub async fn pathfinding_from_train_batch( for (index, train_schedule) in train_schedules.iter().enumerate() { // Retrieve rolling stock let rolling_stock_name = &train_schedule.rolling_stock_name; - let Some(rolling_stock) = rolling_stocks.get(rolling_stock_name).cloned() else { + let Some(rolling_stock) = consists.get(rolling_stock_name).cloned() else { let rolling_stock_name = rolling_stock_name.clone(); results[index] = PathfindingResult::Failure(PathfindingFailure::PathfindingInputError( PathfindingInputError::RollingStockNotFound { rolling_stock_name }, @@ -384,6 +390,8 @@ pub async fn pathfinding_from_train_batch( continue; }; + let rolling_stock = rolling_stock.traction_engine; + // Create the path input let path_input = PathfindingInput { rolling_stock_loading_gauge: rolling_stock.loading_gauge, diff --git a/editoast/src/views/timetable/stdcm.rs b/editoast/src/views/timetable/stdcm.rs index 8405d8bf6ec..fdbf4924416 100644 --- a/editoast/src/views/timetable/stdcm.rs +++ b/editoast/src/views/timetable/stdcm.rs @@ -204,14 +204,10 @@ async fn stdcm( core_client.clone(), &infra, &train_schedules, - vec![rolling_stock.clone()] - .into_iter() - .map(|rs| (rs.name.clone(), rs.clone())) - .collect(), - vec![physics_consist_parameters.clone()] - .into_iter() - .map(|consist| (consist.traction_engine.name.clone(), consist)) - .collect(), + HashMap::from([( + physics_consist_parameters.traction_engine.name.clone(), + physics_consist_parameters.clone(), + )]), stdcm_request.electrical_profile_set_id, ) .await? @@ -434,14 +430,12 @@ impl VirtualTrainRun { core_client, infra, &[train_schedule.clone()], - vec![rolling_stock] - .into_iter() - .map(|rs| (rs.name.clone(), rs.clone())) - .collect(), - vec![consist_parameters.clone()] - .into_iter() - .map(|consist| (consist.traction_engine.name.clone(), consist)) - .collect(), + HashMap::from([( + rolling_stock.name.clone(), + consist_parameters + .clone() + .set_traction_engine(rolling_stock.clone()), + )]), None, ) .await? diff --git a/editoast/src/views/train_schedule.rs b/editoast/src/views/train_schedule.rs index aef0cad38a7..20a0a3d336c 100644 --- a/editoast/src/views/train_schedule.rs +++ b/editoast/src/views/train_schedule.rs @@ -423,7 +423,6 @@ pub async fn train_simulation_batch( core.clone(), infra, train_schedules, - rolling_stocks, consists, electrical_profile_set_id, ) @@ -436,7 +435,6 @@ pub async fn consist_train_simulation_batch( core: Arc, infra: &Infra, train_schedules: &[TrainSchedule], - rolling_stocks: HashMap, consists: HashMap, electrical_profile_set_id: Option, ) -> Result> { @@ -448,7 +446,7 @@ pub async fn consist_train_simulation_batch( core.clone(), infra, train_schedules, - &rolling_stocks, + &consists, ) .await?;