Skip to content

Commit

Permalink
editoast: lmr add max speed to towed rolling stock
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Dec 5, 2024
1 parent 419a315 commit 1b93bd4
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ diesel::table! {
version -> Int8,
#[max_length = 255]
label -> Varchar,
max_speed -> Nullable<Float8>,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pub struct TowedRollingStock {
/// The constant gamma braking coefficient used when NOT circulating
/// under ETCS/ERTMS signaling system in m/s^2
pub const_gamma: f64,
pub max_speed: Option<f64>,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE towed_rolling_stock
DROP max_speed;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE towed_rolling_stock
ADD max_speed FLOAT8;
8 changes: 8 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10654,6 +10654,10 @@ components:
mass:
type: number
format: double
max_speed:
type: number
format: double
nullable: true
name:
type: string
railjson_version:
Expand Down Expand Up @@ -10707,6 +10711,10 @@ components:
mass:
type: number
format: double
max_speed:
type: number
format: double
nullable: true
name:
type: string
rolling_resistance:
Expand Down
22 changes: 18 additions & 4 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,17 @@ impl PhysicsConsistParameters {
}

pub fn compute_max_speed(&self) -> f64 {
self.max_speed
.map(|max_speed_parameter| {
f64::min(self.traction_engine.max_speed, max_speed_parameter)
})
let max_speeds = [
self.max_speed,
self.towed_rolling_stock
.as_ref()
.and_then(|towed| towed.max_speed),
Some(self.traction_engine.max_speed),
];
max_speeds
.into_iter()
.flatten()
.reduce(f64::min)
.unwrap_or(self.traction_engine.max_speed)
}

Expand Down Expand Up @@ -555,6 +562,7 @@ mod tests {

#[test]
fn physics_consist_max_speed() {
// Towed max speed 35
let mut physics_consist = create_physics_consist();
physics_consist.max_speed = Some(20.0); // m/s
physics_consist.traction_engine.max_speed = 22.0; // m/s
Expand All @@ -569,6 +577,12 @@ mod tests {

physics_consist.max_speed = None;
assert_eq!(physics_consist.compute_max_speed(), 24.0);

physics_consist.traction_engine.max_speed = 40.0; // m/s
assert_eq!(physics_consist.compute_max_speed(), 35.0);

physics_consist.towed_rolling_stock = None;
assert_eq!(physics_consist.compute_max_speed(), 40.0);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ pub fn create_towed_rolling_stock() -> TowedRollingStock {
C: 0.0002, // In N/(m/s)²
},
const_gamma: 1.0,
max_speed: Some(35.0),
railjson_version: "3.4".to_string(),
}
}
Expand Down
3 changes: 3 additions & 0 deletions editoast/src/models/towed_rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct TowedRollingStockModel {
pub mass: f64,
/// In m
pub length: f64,
/// In km/h
pub max_speed: Option<f64>,
pub comfort_acceleration: f64,
pub startup_acceleration: f64,
pub inertia_coefficient: f64,
Expand All @@ -48,6 +50,7 @@ impl From<TowedRollingStockModel> for TowedRollingStock {
inertia_coefficient: model.inertia_coefficient,
rolling_resistance: model.rolling_resistance,
const_gamma: model.const_gamma,
max_speed: model.max_speed,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions editoast/src/views/rolling_stock/towed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct TowedRollingStock {
inertia_coefficient: f64,
rolling_resistance: RollingResistancePerWeight,
const_gamma: f64,
max_speed: Option<f64>,
}

impl From<TowedRollingStockModel> for TowedRollingStock {
Expand All @@ -77,6 +78,7 @@ impl From<TowedRollingStockModel> for TowedRollingStock {
inertia_coefficient: towed_rolling_stock.inertia_coefficient,
rolling_resistance: towed_rolling_stock.rolling_resistance,
const_gamma: towed_rolling_stock.const_gamma,
max_speed: towed_rolling_stock.max_speed,
}
}
}
Expand Down Expand Up @@ -105,6 +107,7 @@ pub struct TowedRollingStockForm {
pub inertia_coefficient: f64,
pub rolling_resistance: RollingResistancePerWeight,
pub const_gamma: f64,
pub max_speed: Option<f64>,
}

impl From<TowedRollingStockForm> for Changeset<TowedRollingStockModel> {
Expand All @@ -121,6 +124,7 @@ impl From<TowedRollingStockForm> for Changeset<TowedRollingStockModel> {
.inertia_coefficient(towed_rolling_stock_form.inertia_coefficient)
.rolling_resistance(towed_rolling_stock_form.rolling_resistance)
.const_gamma(towed_rolling_stock_form.const_gamma)
.max_speed(towed_rolling_stock_form.max_speed)
}
}

Expand Down
3 changes: 3 additions & 0 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::sync::Arc;
use thiserror::Error;
use utoipa::IntoParams;
use utoipa::ToSchema;
use validator::Validate;

use crate::core::conflict_detection::Conflict;
use crate::core::conflict_detection::TrainRequirements;
Expand Down Expand Up @@ -139,6 +140,8 @@ async fn stdcm(
return Err(AuthorizationError::Unauthorized.into());
}

stdcm_request.validate()?;

let conn = &mut db_pool.get().await?;

let timetable_id = id;
Expand Down
6 changes: 5 additions & 1 deletion editoast/src/views/timetable/stdcm/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;
use validator::Validate;

use crate::core::pathfinding::PathfindingInputError;
use crate::error::Result;
Expand Down Expand Up @@ -65,7 +66,7 @@ struct StepTimingData {
}

/// An STDCM request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Validate, ToSchema)]
pub(super) struct Request {
/// Deprecated, first step arrival time should be used instead
pub(super) start_time: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -102,10 +103,13 @@ pub(super) struct Request {
#[schema(value_type = Option<String>, example = json!(["5%", "2min/100km"]))]
pub(super) margin: Option<MarginValue>,
/// Total mass of the consist in kg
#[validate(range(exclusive_min = 0.0))]
pub(super) total_mass: Option<f64>,
/// Total length of the consist in meters
#[validate(range(exclusive_min = 0.0))]
pub(super) total_length: Option<f64>,
/// Maximum speed of the consist in km/h
#[validate(range(exclusive_min = 0.0))]
pub(super) max_speed: Option<f64>,
pub(super) loading_gauge_type: Option<LoadingGaugeType>,
}
Expand Down
6 changes: 3 additions & 3 deletions front/src/applications/stdcm/hooks/useStdcmConsist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';

import { min } from 'lodash';
import { useSelector } from 'react-redux';

import type { LightRollingStockWithLiveries, TowedRollingStock } from 'common/api/osrdEditoastApi';
Expand Down Expand Up @@ -57,9 +58,8 @@ const useStdcmConsist = () => {
}

if (!maxSpeedChanged) {
dispatch(
updateMaxSpeed(rollingStock?.max_speed ? Math.floor(rollingStock.max_speed) : undefined)
);
const consistMaxSpeed = min([rollingStock?.max_speed, towed?.max_speed]);
dispatch(updateMaxSpeed(consistMaxSpeed ? Math.floor(consistMaxSpeed) : undefined));
}
};

Expand Down
2 changes: 2 additions & 0 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3372,6 +3372,7 @@ export type TowedRollingStock = {
length: number;
locked: boolean;
mass: number;
max_speed?: number | null;
name: string;
railjson_version: string;
rolling_resistance: RollingResistancePerWeight;
Expand All @@ -3385,6 +3386,7 @@ export type TowedRollingStockForm = {
length: number;
locked: boolean;
mass: number;
max_speed?: number | null;
name: string;
rolling_resistance: RollingResistancePerWeight;
startup_acceleration: number;
Expand Down

0 comments on commit 1b93bd4

Please sign in to comment.