Skip to content

Commit

Permalink
editoast, schemas: add 'train_type' to the rolling stock model
Browse files Browse the repository at this point in the history
Signed-off-by: Jean SIMARD <[email protected]>
  • Loading branch information
woshilapin committed Sep 18, 2024
1 parent 512fe9a commit a3132aa
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion editoast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ To make sure it is always valid a CI check has been set up. To update the
OpenApi when a change has been made to an endpoint, run the following command:

```sh
cargo run openapi > openapi.yaml
cargo run -- openapi > openapi.yaml
```

## Batch dependency updates
Expand Down
1 change: 1 addition & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ diesel::table! {
raise_pantograph_time -> Nullable<Float8>,
version -> Int8,
supported_signaling_systems -> Array<Nullable<Text>>,
freight_compatible -> Nullable<Bool>,
}
}

Expand Down
1 change: 1 addition & 0 deletions editoast/editoast_schemas/src/rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ pub struct RollingStock {
pub railjson_version: String,
#[serde(default)]
pub metadata: Option<RollingStockMetadata>,
pub freight_compatible: Option<bool>,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
ALTER TABLE rolling_stock
DROP COLUMN freight_compatible;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE rolling_stock
ADD freight_compatible BOOLEAN;
6 changes: 6 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7577,6 +7577,9 @@ components:
type: array
items:
$ref: '#/components/schemas/EnergySource'
freight_compatible:
type: boolean
nullable: true
gamma:
$ref: '#/components/schemas/Gamma'
id:
Expand Down Expand Up @@ -7729,6 +7732,9 @@ components:
type: array
items:
$ref: '#/components/schemas/EnergySource'
freight_compatible:
type: boolean
nullable: true
gamma:
$ref: '#/components/schemas/Gamma'
inertia_coefficient:
Expand Down
3 changes: 3 additions & 0 deletions editoast/src/models/rolling_stock_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct RollingStockModel {
#[schema(value_type = Vec<String>)]
#[model(remote = "Vec<Option<String>>")]
pub supported_signaling_systems: RollingStockSupportedSignalingSystems,
pub freight_compatible: Option<bool>,
}

impl RollingStockModel {
Expand Down Expand Up @@ -167,6 +168,7 @@ impl From<RollingStockModel> for RollingStock {
electrical_power_startup_time: rolling_stock_model.electrical_power_startup_time,
raise_pantograph_time: rolling_stock_model.raise_pantograph_time,
supported_signaling_systems: rolling_stock_model.supported_signaling_systems,
freight_compatible: rolling_stock_model.freight_compatible,
}
}
}
Expand Down Expand Up @@ -194,6 +196,7 @@ impl From<RollingStock> for RollingStockModelChangeset {
.electrical_power_startup_time(rolling_stock.electrical_power_startup_time)
.raise_pantograph_time(rolling_stock.raise_pantograph_time)
.supported_signaling_systems(rolling_stock.supported_signaling_systems)
.freight_compatible(rolling_stock.freight_compatible)
}
}

Expand Down
3 changes: 2 additions & 1 deletion editoast/src/tests/example_rolling_stock_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,6 @@
"power_restrictions": {"C2":"2", "C5":"5"},
"electrical_power_startup_time": 5.0,
"raise_pantograph_time": 15.0,
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"]
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
"freight_compatible": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,6 @@
"power_restrictions": {},
"electrical_power_startup_time": 6.0,
"raise_pantograph_time": 16.0,
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"]
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
"freight_compatible": true
}
3 changes: 2 additions & 1 deletion editoast/src/tests/example_rolling_stock_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
"power_restrictions": {},
"electrical_power_startup_time": 4.0,
"raise_pantograph_time": 14.0,
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"]
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
"freight_compatible": true
}
3 changes: 3 additions & 0 deletions editoast/src/views/rolling_stock/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct RollingStockForm {
pub supported_signaling_systems: RollingStockSupportedSignalingSystems,
pub locked: Option<bool>,
pub metadata: Option<RollingStockMetadata>,
pub freight_compatible: Option<bool>,
}

impl From<RollingStockForm> for Changeset<RollingStockModel> {
Expand All @@ -77,6 +78,7 @@ impl From<RollingStockForm> for Changeset<RollingStockModel> {
.electrical_power_startup_time(rolling_stock.electrical_power_startup_time)
.raise_pantograph_time(rolling_stock.raise_pantograph_time)
.supported_signaling_systems(rolling_stock.supported_signaling_systems)
.freight_compatible(rolling_stock.freight_compatible)
}
}

Expand Down Expand Up @@ -115,6 +117,7 @@ impl From<RollingStockModel> for RollingStockForm {
supported_signaling_systems: value.supported_signaling_systems,
locked: Some(value.locked),
metadata: value.metadata,
freight_compatible: value.freight_compatible,
}
}
}
2 changes: 2 additions & 0 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,7 @@ export type RollingStock = {
effort_curves: EffortCurves;
electrical_power_startup_time: number | null;
energy_sources: EnergySource[];
freight_compatible?: boolean | null;
gamma: Gamma;
id: number;
inertia_coefficient: number;
Expand Down Expand Up @@ -2559,6 +2560,7 @@ export type RollingStockForm = {
/** The time the train takes before actually using electrical power (in seconds). Is null if the train is not electric. */
electrical_power_startup_time?: number | null;
energy_sources?: EnergySource[];
freight_compatible?: boolean | null;
gamma: Gamma;
inertia_coefficient: number;
length: number;
Expand Down
3 changes: 3 additions & 0 deletions python/osrd_schemas/osrd_schemas/rolling_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ class RollingStock(BaseModel, extra="forbid"):
ge=0,
)
supported_signaling_systems: List[str] = Field(default_factory=list)
freight_compatible: Optional[bool] = Field(
description="The type of the train, wether it's a locomotive or something else", default=None
)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion tests/data/rolling_stocks/electric_rolling_stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -977,5 +977,6 @@
"BAPR",
"TVM300",
"TVM430"
]
],
"freight_compatible": false
}
3 changes: 2 additions & 1 deletion tests/data/rolling_stocks/fast_rolling_stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
"BAPR",
"TVM300",
"TVM430"
]
],
"freight_compatible": true
}
3 changes: 2 additions & 1 deletion tests/data/rolling_stocks/fast_rolling_stock_high_gamma.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@
"BAPR",
"TVM300",
"TVM430"
]
],
"freight_compatible": true
}
3 changes: 2 additions & 1 deletion tests/data/rolling_stocks/short_fast_rolling_stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@
"BAPR",
"TVM300",
"TVM430"
]
],
"freight_compatible": true
}
3 changes: 2 additions & 1 deletion tests/data/rolling_stocks/short_slow_rolling_stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@
"BAPR",
"TVM300",
"TVM430"
]
],
"freight_compatible": true
}
3 changes: 2 additions & 1 deletion tests/data/rolling_stocks/slow_rolling_stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@
"BAPR",
"TVM300",
"TVM430"
]
],
"freight_compatible": true
}

0 comments on commit a3132aa

Please sign in to comment.