Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup rollingstock model #6590

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public class RJSRollingStock implements Identified {
@Json(name = "inertia_coefficient")
public double inertiaCoefficient = Double.NaN;

/** The list of equipments (protection systems, signaling equipment) the train is able to deal with */
public String[] features = new String[0];

/** The mass of the train */
public double mass = Double.NaN;

Expand All @@ -95,7 +92,7 @@ public class RJSRollingStock implements Identified {
public Double raisePantographTime = null;

@Json(name = "supported_signaling_systems")
public String[] supportedSignalingSystems = null;
public String[] supportedSignalingSystems = new String[0];

public enum GammaType {
CONST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ else if (!rjsRollingStock.railjsonVersion.equals(RJSRollingStock.CURRENT_VERSION
if (Double.isNaN(rjsRollingStock.inertiaCoefficient))
throw OSRDError.newMissingRollingStockFieldError("inertia_coefficient");

if (rjsRollingStock.features == null)
throw OSRDError.newMissingRollingStockFieldError("features");

if (rjsRollingStock.loadingGauge == null)
throw OSRDError.newMissingRollingStockFieldError("loading_gauge");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE rolling_stock
ADD features text [] NOT NULL DEFAULT '{}',
ALTER COLUMN supported_signaling_systems type jsonb USING Array_to_json(supported_signaling_systems::text []),
ALTER COLUMN supported_signaling_systems
SET DEFAULT ('["BAPR", "BAL", "TVM300", "TVM430"]');
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE rolling_stock DROP COLUMN features,
ALTER COLUMN supported_signaling_systems DROP DEFAULT,
ALTER COLUMN supported_signaling_systems TYPE TEXT [] USING TRANSLATE(
supported_signaling_systems::jsonb::text, '[]', '{}')::TEXT [];
22 changes: 3 additions & 19 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,6 @@ components:
items:
$ref: '#/components/schemas/EnergySource'
type: array
features:
items:
type: string
type: array
gamma:
$ref: '#/components/schemas/Gamma'
id:
Expand Down Expand Up @@ -886,7 +882,7 @@ components:
type: number
supported_signaling_systems:
items:
$ref: '#/components/schemas/SignalingSystem'
type: string
type: array
required:
- id
Expand All @@ -901,7 +897,6 @@ components:
- comfort_acceleration
- gamma
- inertia_coefficient
- features
- mass
- rolling_resistance
- loading_gauge
Expand Down Expand Up @@ -1925,10 +1920,6 @@ components:
items:
$ref: '#/components/schemas/EnergySource'
type: array
features:
items:
type: string
type: array
gamma:
$ref: '#/components/schemas/Gamma'
inertia_coefficient:
Expand Down Expand Up @@ -1968,7 +1959,7 @@ components:
type: number
supported_signaling_systems:
items:
$ref: '#/components/schemas/SignalingSystem'
type: string
type: array
required:
- name
Expand All @@ -1981,11 +1972,11 @@ components:
- comfort_acceleration
- gamma
- inertia_coefficient
- features
- mass
- rolling_resistance
- loading_gauge
- power_restrictions
- supported_signaling_systems
type: object
RollingStockError:
oneOf:
Expand Down Expand Up @@ -2721,13 +2712,6 @@ components:
- aspect_label
- track
type: object
SignalingSystem:
enum:
- BAL
- BAPR
- TVM300
- TVM430
type: string
SimulationPowerRestrictionRange:
properties:
code:
Expand Down
12 changes: 4 additions & 8 deletions editoast/src/models/rolling_stock/light_rolling_stock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::error::Result;
use crate::models::rolling_stock::rolling_stock_livery::RollingStockLiveryMetadata;
use crate::models::{rolling_stock::rolling_stock_livery::RollingStockLiveryMetadata, TextArray};
use crate::schema::rolling_stock::light_rolling_stock::{
LightEffortCurves, LightRollingStock, LightRollingStockWithLiveries,
};
use crate::schema::rolling_stock::{
EnergySource, Gamma, RollingResistance, RollingStockMetadata, SignalingSystem,
};
use crate::schema::rolling_stock::{EnergySource, Gamma, RollingResistance, RollingStockMetadata};
use crate::tables::rolling_stock;
use crate::views::pagination::{Paginate, PaginatedResponse};
use crate::DbPool;
Expand Down Expand Up @@ -39,7 +37,6 @@ pub struct LightRollingStockModel {
gamma: DieselJson<Gamma>,
inertia_coefficient: f64,
pub base_power_class: Option<String>,
features: Vec<Option<String>>,
mass: f64,
#[schema(value_type = RollingResistance)]
rolling_resistance: DieselJson<RollingResistance>,
Expand All @@ -53,8 +50,8 @@ pub struct LightRollingStockModel {
electrical_power_startup_time: Option<f64>,
raise_pantograph_time: Option<f64>,
pub version: i64,
#[schema(value_type = Vec<SignalingSystem>)]
supported_signaling_systems: DieselJson<Vec<SignalingSystem>>,
#[diesel(deserialize_as = TextArray)]
supported_signaling_systems: Vec<String>,
}

impl LightRollingStockModel {
Expand Down Expand Up @@ -114,7 +111,6 @@ impl From<LightRollingStockModel> for LightRollingStock {
comfort_acceleration: rolling_stock_model.comfort_acceleration,
gamma: rolling_stock_model.gamma,
inertia_coefficient: rolling_stock_model.inertia_coefficient,
features: rolling_stock_model.features.into_iter().flatten().collect(),
mass: rolling_stock_model.mass,
rolling_resistance: rolling_stock_model.rolling_resistance,
loading_gauge: rolling_stock_model.loading_gauge,
Expand Down
14 changes: 5 additions & 9 deletions editoast/src/models/rolling_stock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::models::rolling_stock::rolling_stock_livery::RollingStockLiveryMetada
use crate::models::{Create, Identifiable, TextArray, Update};
use crate::schema::rolling_stock::{
EffortCurves, EnergySource, Gamma, RollingResistance, RollingStock, RollingStockCommon,
RollingStockMetadata, RollingStockWithLiveries, SignalingSystem,
RollingStockMetadata, RollingStockWithLiveries,
};
use crate::schema::track_section::LoadingGaugeType;
use crate::tables::rolling_stock;
Expand Down Expand Up @@ -97,9 +97,6 @@ pub struct RollingStockModel {
#[diesel(deserialize_as = Option<String>)]
#[schema(value_type = Option<String>)]
pub base_power_class: Option<Option<String>>,
#[diesel(deserialize_as = TextArray)]
#[schema(value_type = Vec<String>)]
pub features: Option<Vec<String>>,
#[diesel(deserialize_as = f64)]
#[schema(value_type = f64)]
pub mass: Option<f64>,
Expand Down Expand Up @@ -130,9 +127,9 @@ pub struct RollingStockModel {
#[diesel(deserialize_as = i64)]
#[schema(value_type = i64)]
pub version: Option<i64>,
#[diesel(deserialize_as = DieselJson<Vec<SignalingSystem>>)]
#[schema(value_type = Vec<SignalingSystem>)]
pub supported_signaling_systems: Option<DieselJson<Vec<SignalingSystem>>>,
#[diesel(deserialize_as = TextArray)]
#[schema(value_type = Vec<String>)]
pub supported_signaling_systems: Option<Vec<String>>,
}

fn validate_rolling_stock(
Expand Down Expand Up @@ -288,7 +285,6 @@ impl From<RollingStockModel> for RollingStockCommon {
comfort_acceleration: rolling_stock_model.comfort_acceleration.unwrap(),
gamma: rolling_stock_model.gamma.unwrap().0,
inertia_coefficient: rolling_stock_model.inertia_coefficient.unwrap(),
features: rolling_stock_model.features.unwrap(),
mass: rolling_stock_model.mass.unwrap(),
rolling_resistance: rolling_stock_model.rolling_resistance.unwrap().0,
loading_gauge: rolling_stock_model.loading_gauge.unwrap(),
Expand All @@ -298,7 +294,7 @@ impl From<RollingStockModel> for RollingStockCommon {
.electrical_power_startup_time
.unwrap(),
raise_pantograph_time: rolling_stock_model.raise_pantograph_time.unwrap(),
supported_signaling_systems: rolling_stock_model.supported_signaling_systems.unwrap().0,
supported_signaling_systems: rolling_stock_model.supported_signaling_systems.unwrap(),
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions editoast/src/schema/rolling_stock/light_rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use utoipa::ToSchema;

use crate::models::rolling_stock::rolling_stock_livery::RollingStockLiveryMetadata;

use super::{EnergySource, Gamma, RollingResistance, RollingStockMetadata, SignalingSystem};
use super::{EnergySource, Gamma, RollingResistance, RollingStockMetadata};

crate::schemas! {
LightRollingStock,
Expand Down Expand Up @@ -45,8 +45,6 @@ pub struct LightRollingStock {
pub gamma: DieselJson<Gamma>,
#[diesel(sql_type = Double)]
pub inertia_coefficient: f64,
#[diesel(sql_type = Array<Text>)]
pub features: Vec<String>,
#[diesel(sql_type = Double)]
pub mass: f64,
#[diesel(sql_type = Jsonb)]
Expand All @@ -67,9 +65,8 @@ pub struct LightRollingStock {
#[serde(skip)]
#[diesel(sql_type = BigInt)]
pub version: i64,
#[diesel(sql_type = Jsonb)]
#[schema(value_type = Vec<SignalingSystem>)]
pub supported_signaling_systems: DieselJson<Vec<SignalingSystem>>,
#[diesel(sql_type = Array<Text>)]
pub supported_signaling_systems: Vec<String>,
}

#[derive(Debug, QueryableByName, Serialize, Deserialize, ToSchema)]
Expand Down
16 changes: 1 addition & 15 deletions editoast/src/schema/rolling_stock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ crate::schemas! {
EnergyStorage,
RefillLaw,
RollingStockLivery,
SignalingSystem,
light_rolling_stock::schemas(),
}

Expand All @@ -48,7 +47,6 @@ pub struct RollingStockCommon {
pub comfort_acceleration: f64,
pub gamma: Gamma,
pub inertia_coefficient: f64,
pub features: Vec<String>,
pub mass: f64,
pub rolling_resistance: RollingResistance,
#[schema(value_type = LoadingGaugeType)]
Expand All @@ -64,8 +62,7 @@ pub struct RollingStockCommon {
/// The time it takes to raise this train's pantograph in seconds. Is null if the train is not electric.
#[schema(example = 15.0)]
pub raise_pantograph_time: Option<f64>,
#[serde(default)]
pub supported_signaling_systems: Vec<SignalingSystem>,
pub supported_signaling_systems: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
Expand Down Expand Up @@ -265,17 +262,6 @@ pub enum EnergySource {
},
}

#[derive(Clone, Debug, PartialEq, EnumString, Deserialize, Serialize, ToSchema)]
#[strum(serialize_all = "UPPERCASE")]
#[serde(rename_all = "UPPERCASE")]
#[serde(deny_unknown_fields)]
pub enum SignalingSystem {
Bal,
Bapr,
Tvm300,
Tvm430,
}

#[cfg(test)]
mod tests {
use crate::schema::rolling_stock::EffortCurve;
Expand Down
3 changes: 1 addition & 2 deletions editoast/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ diesel::table! {
inertia_coefficient -> Float8,
#[max_length = 255]
base_power_class -> Nullable<Varchar>,
features -> Array<Nullable<Text>>,
mass -> Float8,
rolling_resistance -> Jsonb,
#[max_length = 16]
Expand All @@ -423,7 +422,7 @@ diesel::table! {
electrical_power_startup_time -> Nullable<Float8>,
raise_pantograph_time -> Nullable<Float8>,
version -> Int8,
supported_signaling_systems -> Jsonb,
supported_signaling_systems -> Array<Nullable<Text>>,
}
}

Expand Down
1 change: 0 additions & 1 deletion editoast/src/tests/example_rolling_stock_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"startup_acceleration": 0.05,
"comfort_acceleration": 0.25,
"inertia_coefficient": 1.05,
"features": ["TVM300", "TVM430", "ETCS1", "ETCS2", "KVB"],
"name": "fast_rolling_stock",
"mass": 900000.0,
"loading_gauge": "G1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"startup_acceleration": 0.25,
"comfort_acceleration": 0.12,
"inertia_coefficient": 1.02,
"features": [],
"name": "other_rolling_stock",
"mass": 50000.0,
"loading_gauge": "G2",
Expand Down
1 change: 0 additions & 1 deletion editoast/src/tests/example_rolling_stock_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"startup_acceleration": 0.25,
"comfort_acceleration": 0.12,
"inertia_coefficient": 1.02,
"features": [],
"name": "other_rolling_stock",
"mass": 50000.0,
"loading_gauge": "G2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"value": 0.5
},
"inertia_coefficient": 1.2,
"features": [],
"mass": 132000,
"rolling_resistance": {
"type": "davis",
Expand Down
5 changes: 1 addition & 4 deletions editoast/src/views/rolling_stocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,14 @@ impl From<RollingStockForm> for RollingStockModel {
comfort_acceleration: Some(rolling_stock.common.comfort_acceleration),
gamma: Some(DieselJson(rolling_stock.common.gamma)),
inertia_coefficient: Some(rolling_stock.common.inertia_coefficient),
features: Some(rolling_stock.common.features),
mass: Some(rolling_stock.common.mass),
rolling_resistance: Some(DieselJson(rolling_stock.common.rolling_resistance)),
loading_gauge: Some(rolling_stock.common.loading_gauge),
power_restrictions: Some(rolling_stock.common.power_restrictions),
energy_sources: Some(DieselJson(rolling_stock.common.energy_sources)),
electrical_power_startup_time: Some(rolling_stock.common.electrical_power_startup_time),
raise_pantograph_time: Some(rolling_stock.common.raise_pantograph_time),
supported_signaling_systems: Some(DieselJson(
rolling_stock.common.supported_signaling_systems,
)),
supported_signaling_systems: Some(rolling_stock.common.supported_signaling_systems),
..Default::default()
}
}
Expand Down
7 changes: 2 additions & 5 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1591,13 +1591,11 @@ export type RollingResistance = {
C: number;
type: string;
};
export type SignalingSystem = 'BAL' | 'BAPR' | 'TVM300' | 'TVM430';
export type LightRollingStock = {
base_power_class?: string | null;
comfort_acceleration: number;
effort_curves: LightEffortCurves;
energy_sources: EnergySource[];
features: string[];
gamma: Gamma;
id: number;
inertia_coefficient: number;
Expand All @@ -1615,7 +1613,7 @@ export type LightRollingStock = {
rolling_resistance: RollingResistance;
startup_acceleration: number;
startup_time: number;
supported_signaling_systems: SignalingSystem[];
supported_signaling_systems: string[];
};
export type RollingStockLiveryMetadata = {
compound_image_id?: number | null;
Expand Down Expand Up @@ -1889,7 +1887,6 @@ export type RollingStockCommon = {
effort_curves: EffortCurves;
electrical_power_startup_time?: number | null;
energy_sources?: EnergySource[];
features: string[];
gamma: Gamma;
inertia_coefficient: number;
length: number;
Expand All @@ -1904,7 +1901,7 @@ export type RollingStockCommon = {
rolling_resistance: RollingResistance;
startup_acceleration: number;
startup_time: number;
supported_signaling_systems?: SignalingSystem[];
supported_signaling_systems: string[];
};
export type RollingStock = RollingStockCommon & {
id: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ export default function RollingStockCardDetail({
</table>
</div>
<div className="col-sm-6">
{rollingStock.features && rollingStock.features.length > 0 && (
<div className="pb-1">
{t('features')}
<span className="ml-1">{rollingStock.features.join(', ')}</span>
</div>
)}
{rollingStock.power_restrictions &&
Object.keys(rollingStock.power_restrictions).length !== 0 && (
<table className="rollingstock-details-table mb-1">
Expand Down
Loading
Loading