Skip to content

Commit

Permalink
front: fix pr comments
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <egor@berezify.fr>
  • Loading branch information
Wadjetz committed Nov 22, 2024
1 parent 12ba25e commit e76a0cc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
11 changes: 8 additions & 3 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -78,11 +78,16 @@ pub struct PhysicsConsistParameters {
/// In m/s
pub max_speed: Option<f64>,
pub towed_rolling_stock: Option<TowedRollingStock>,
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,
Expand Down
6 changes: 4 additions & 2 deletions editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,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![]),
Expand Down
14 changes: 11 additions & 3 deletions editoast/src/views/path/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -363,7 +369,7 @@ pub async fn pathfinding_from_train_batch(
core: Arc<CoreClient>,
infra: &Infra,
train_schedules: &[TrainSchedule],
rolling_stocks: &HashMap<String, RollingStockModel>,
consists: &HashMap<String, PhysicsConsistParameters>,
) -> Result<Vec<PathfindingResult>> {
let mut results = vec![
PathfindingResult::Failure(PathfindingFailure::PathfindingInputError(
Expand All @@ -376,14 +382,16 @@ 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 },
));
continue;
};

let rolling_stock = rolling_stock.traction_engine;

// Create the path input
let path_input = PathfindingInput {
rolling_stock_loading_gauge: rolling_stock.loading_gauge,
Expand Down
20 changes: 7 additions & 13 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,7 @@ 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?
Expand Down Expand Up @@ -436,11 +429,12 @@ impl VirtualTrainRun {
&[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))
.map(|rs| {
(
rs.name.clone(),
consist_parameters.clone().set_traction_engine(rs.clone()),
)
})
.collect(),
None,
)
Expand Down
4 changes: 1 addition & 3 deletions editoast/src/views/train_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ pub async fn train_simulation_batch(
core.clone(),
infra,
train_schedules,
rolling_stocks,
consists,
electrical_profile_set_id,
)
Expand All @@ -436,7 +435,6 @@ pub async fn consist_train_simulation_batch(
core: Arc<CoreClient>,
infra: &Infra,
train_schedules: &[TrainSchedule],
rolling_stocks: HashMap<String, RollingStockModel>,
consists: HashMap<String, PhysicsConsistParameters>,
electrical_profile_set_id: Option<i64>,
) -> Result<Vec<(SimulationResponse, PathfindingResult)>> {
Expand All @@ -448,7 +446,7 @@ pub async fn consist_train_simulation_batch(
core.clone(),
infra,
train_schedules,
&rolling_stocks,
&consists,
)
.await?;

Expand Down

0 comments on commit e76a0cc

Please sign in to comment.