Skip to content

Commit 7c2a993

Browse files
WadjetzKhoyo
authored andcommitted
editoast: move energy source to schemas
1 parent 73f0aad commit 7c2a993

File tree

5 files changed

+78
-65
lines changed

5 files changed

+78
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use serde::Deserialize;
2+
use serde::Serialize;
3+
use utoipa::ToSchema;
4+
5+
// Energy sources schema
6+
7+
/// energy source of a rolling stock
8+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
9+
#[serde(tag = "energy_source_type", deny_unknown_fields)]
10+
pub enum EnergySource {
11+
/// energy source for a rolling stock representing a electrification
12+
Electrification {
13+
max_input_power: SpeedDependantPower,
14+
max_output_power: SpeedDependantPower,
15+
#[schema(minimum = 0, maximum = 1)]
16+
efficiency: f64,
17+
},
18+
PowerPack {
19+
max_input_power: SpeedDependantPower,
20+
max_output_power: SpeedDependantPower,
21+
energy_storage: EnergyStorage,
22+
#[schema(minimum = 0, maximum = 1)]
23+
efficiency: f64,
24+
},
25+
/// energy source for a rolling stock representing a battery
26+
Battery {
27+
max_input_power: SpeedDependantPower,
28+
max_output_power: SpeedDependantPower,
29+
energy_storage: EnergyStorage,
30+
#[schema(minimum = 0, maximum = 1)]
31+
efficiency: f64,
32+
},
33+
}
34+
35+
/// power-speed curve (in an energy source)
36+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
37+
#[serde(deny_unknown_fields)]
38+
pub struct SpeedDependantPower {
39+
speeds: Vec<f64>,
40+
powers: Vec<f64>,
41+
}
42+
43+
/// energy storage of an energy source (of a rolling stock, can be a electrical battery or a hydrogen/fuel powerPack)
44+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
45+
#[serde(deny_unknown_fields)]
46+
pub struct EnergyStorage {
47+
capacity: f64,
48+
#[schema(minimum = 0, maximum = 1)]
49+
soc: f64,
50+
#[schema(minimum = 0, maximum = 1)]
51+
soc_min: f64,
52+
#[schema(minimum = 0, maximum = 1)]
53+
soc_max: f64,
54+
#[schema(required)]
55+
refill_law: Option<RefillLaw>,
56+
}
57+
58+
/// physical law defining how the storage can be refilled
59+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
60+
#[serde(deny_unknown_fields)]
61+
pub struct RefillLaw {
62+
#[schema(minimum = 0)]
63+
tau: f64,
64+
#[schema(minimum = 0, maximum = 1)]
65+
soc_ref: f64,
66+
}

editoast/editoast_schemas/src/rolling_stock/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ pub use effort_curves::RollingStockComfortType;
1111

1212
mod rolling_resistance;
1313
pub use rolling_resistance::RollingResistance;
14+
15+
mod energy_source;
16+
pub use energy_source::EnergySource;
17+
pub use energy_source::EnergyStorage;
18+
pub use energy_source::RefillLaw;
19+
pub use energy_source::SpeedDependantPower;

editoast/src/modelsv2/light_rolling_stock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use diesel::QueryDsl;
77
use diesel::SelectableHelper;
88
use diesel_async::RunQueryDsl;
99
use editoast_derive::ModelV2;
10+
use editoast_schemas::rolling_stock::EnergySource;
1011
use editoast_schemas::rolling_stock::Gamma;
1112
use editoast_schemas::rolling_stock::RollingResistance;
1213
use serde::Serialize;
@@ -20,7 +21,6 @@ use crate::modelsv2::Model;
2021
use crate::schema::rolling_stock::light_rolling_stock::LightEffortCurves;
2122
use crate::schema::rolling_stock::light_rolling_stock::LightRollingStock;
2223
use crate::schema::rolling_stock::light_rolling_stock::LightRollingStockWithLiveriesModel;
23-
use crate::schema::rolling_stock::EnergySource;
2424
use crate::schema::rolling_stock::RollingStockMetadata;
2525
use crate::schema::track_section::LoadingGaugeType;
2626
use crate::views::pagination::Paginate;

editoast/src/modelsv2/rolling_stock_model.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use diesel::SelectableHelper;
88
use diesel_async::RunQueryDsl;
99
use editoast_derive::ModelV2;
1010
use editoast_schemas::rolling_stock::EffortCurves;
11+
use editoast_schemas::rolling_stock::EnergySource;
1112
use editoast_schemas::rolling_stock::Gamma;
1213
use editoast_schemas::rolling_stock::RollingResistance;
1314
use serde::Deserialize;
@@ -20,7 +21,6 @@ use validator::ValidationErrors;
2021
use crate::error::Result;
2122
use crate::modelsv2::prelude::*;
2223
use crate::modelsv2::rolling_stock_livery::RollingStockLiveryMetadataModel;
23-
use crate::schema::rolling_stock::EnergySource;
2424
use crate::schema::rolling_stock::RollingStock;
2525
use crate::schema::rolling_stock::RollingStockMetadata;
2626
use crate::schema::rolling_stock::RollingStockWithLiveries;

editoast/src/schema/rolling_stock/mod.rs

+4-63
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ use editoast_schemas::rolling_stock::ConditionalEffortCurve;
88
use editoast_schemas::rolling_stock::EffortCurve;
99
use editoast_schemas::rolling_stock::EffortCurveConditions;
1010
use editoast_schemas::rolling_stock::EffortCurves;
11+
use editoast_schemas::rolling_stock::EnergySource;
12+
use editoast_schemas::rolling_stock::EnergyStorage;
1113
use editoast_schemas::rolling_stock::Gamma;
1214
use editoast_schemas::rolling_stock::ModeEffortCurves;
15+
use editoast_schemas::rolling_stock::RefillLaw;
1316
use editoast_schemas::rolling_stock::RollingResistance;
1417
use editoast_schemas::rolling_stock::RollingStockComfortType;
18+
use editoast_schemas::rolling_stock::SpeedDependantPower;
1519
use serde::Deserialize;
1620
use serde::Serialize;
1721
use utoipa::ToSchema;
@@ -108,66 +112,3 @@ pub struct RollingStockMetadata {
108112
number: String,
109113
reference: String,
110114
}
111-
112-
// Energy sources schema
113-
114-
/// physical law defining how the storage can be refilled
115-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
116-
#[serde(deny_unknown_fields)]
117-
pub struct RefillLaw {
118-
#[schema(minimum = 0)]
119-
tau: f64,
120-
#[schema(minimum = 0, maximum = 1)]
121-
soc_ref: f64,
122-
}
123-
124-
/// energy storage of an energy source (of a rolling stock, can be a electrical battery or a hydrogen/fuel powerPack)
125-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
126-
#[serde(deny_unknown_fields)]
127-
pub struct EnergyStorage {
128-
capacity: f64,
129-
#[schema(minimum = 0, maximum = 1)]
130-
soc: f64,
131-
#[schema(minimum = 0, maximum = 1)]
132-
soc_min: f64,
133-
#[schema(minimum = 0, maximum = 1)]
134-
soc_max: f64,
135-
#[schema(required)]
136-
refill_law: Option<RefillLaw>,
137-
}
138-
139-
/// power-speed curve (in an energy source)
140-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
141-
#[serde(deny_unknown_fields)]
142-
pub struct SpeedDependantPower {
143-
speeds: Vec<f64>,
144-
powers: Vec<f64>,
145-
}
146-
147-
/// energy source of a rolling stock
148-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, ToSchema)]
149-
#[serde(tag = "energy_source_type", deny_unknown_fields)]
150-
pub enum EnergySource {
151-
/// energy source for a rolling stock representing a electrification
152-
Electrification {
153-
max_input_power: SpeedDependantPower,
154-
max_output_power: SpeedDependantPower,
155-
#[schema(minimum = 0, maximum = 1)]
156-
efficiency: f64,
157-
},
158-
PowerPack {
159-
max_input_power: SpeedDependantPower,
160-
max_output_power: SpeedDependantPower,
161-
energy_storage: EnergyStorage,
162-
#[schema(minimum = 0, maximum = 1)]
163-
efficiency: f64,
164-
},
165-
/// energy source for a rolling stock representing a battery
166-
Battery {
167-
max_input_power: SpeedDependantPower,
168-
max_output_power: SpeedDependantPower,
169-
energy_storage: EnergyStorage,
170-
#[schema(minimum = 0, maximum = 1)]
171-
efficiency: f64,
172-
},
173-
}

0 commit comments

Comments
 (0)