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

Fix editoast path properties schema #7226

Merged
merged 1 commit into from
Apr 17, 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
38 changes: 35 additions & 3 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,7 @@ components:
properties:
electrifications:
allOf:
- description: Property string values along a path. Each value is associated to a range of the path.
- description: Electrification property along a path. Each value is associated to a range of the path.
properties:
boundaries:
description: |-
Expand All @@ -4086,7 +4086,39 @@ components:
values:
description: List of `n+1` values associated to the ranges
items:
type: string
oneOf:
- description: Elecrtified section with a given voltage
properties:
type:
enum:
- electrification
type: string
voltage:
type: string
required:
- voltage
- type
type: object
- description: Neutral section with a lower pantograph instruction or just a dead section
properties:
lower_pantograph:
type: boolean
type:
enum:
- neutral_section
type: string
required:
- lower_pantograph
- type
type: object
- properties:
type:
enum:
- non_electrified
type: string
required:
- type
type: object
type: array
required:
- boundaries
Expand Down Expand Up @@ -4173,7 +4205,7 @@ components:
type: object
PathPropertiesInput:
properties:
rolling_stock_supported_electrification:
rolling_stock_supported_electrifications:
description: |-
List of supported electrification modes.
Empty if does not support any electrification
Expand Down
38 changes: 27 additions & 11 deletions editoast/src/views/v2/path/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct PathProperties {
gradients: Option<PropertyValuesF64>,
/// Electrification modes and neutral section along the path
#[schema(inline)]
electrifications: Option<PropertyValuesString>,
electrifications: Option<PropertyElectrificationValues>,
/// Geometry of the path
geometry: Option<GeoJsonLineString>,
/// Operational points along the path
Expand Down Expand Up @@ -129,18 +129,26 @@ struct PropertyValuesF64 {
values: Vec<f64>,
}

/// Property string values along a path. Each value is associated to a range of the path.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Derivative)]
#[derivative(Default)]
struct PropertyValuesString {
/// Electrification property along a path. Each value is associated to a range of the path.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
struct PropertyElectrificationValues {
/// List of `n` boundaries of the ranges.
/// A boundary is a distance from the beginning of the path in mm.
#[derivative(Default(value = "vec![1000]"))]
boundaries: Vec<u64>,
#[schema(inline)]
/// List of `n+1` values associated to the ranges
#[derivative(Default(value = r#"vec!["1500V".into(), "25000V".into()]"#))]
values: Vec<String>,
values: Vec<PropertyElectrificationValue>,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
enum PropertyElectrificationValue {
/// Elecrtified section with a given voltage
Electrification { voltage: String },
/// Neutral section with a lower pantograph instruction or just a dead section
NeutralSection { lower_pantograph: bool },
/// Non electrified section
NonElectrified,
}

/// Operational point along a path.
Expand All @@ -164,7 +172,7 @@ struct PathPropertiesInput {
/// List of supported electrification modes.
/// Empty if does not support any electrification
#[serde(default)]
rolling_stock_supported_electrification: Vec<String>,
rolling_stock_supported_electrifications: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
Expand Down Expand Up @@ -243,7 +251,15 @@ pub async fn post(
let computed_path_properties = PathProperties {
slopes: Some(Default::default()),
gradients: Some(Default::default()),
electrifications: Some(Default::default()),
electrifications: Some(PropertyElectrificationValues {
boundaries: vec![1000],
values: vec![
PropertyElectrificationValue::Electrification {
voltage: "25kV".to_string(),
},
PropertyElectrificationValue::NonElectrified,
],
}),
geometry: Some(
serde_json::from_str(r#"{"type":"LineString","coordinates":[[0,0],[1,1]]}"#)
.unwrap(),
Expand Down Expand Up @@ -290,7 +306,7 @@ async fn retrieve_path_properties(
.await?
.unwrap_or_default();

let elec_property: Option<PropertyValuesString> = redis_conn
let elec_property: Option<PropertyElectrificationValues> = redis_conn
.json_get_ex(&path_elec_property_hash, CACHE_PATH_EXPIRATION)
.await?;

Expand Down
16 changes: 14 additions & 2 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,19 @@ export type PathProperties = {
A boundary is a distance from the beginning of the path in mm. */
boundaries: number[];
/** List of `n+1` values associated to the ranges */
values: string[];
values: (
| {
type: 'electrification';
voltage: string;
}
| {
lower_pantograph: boolean;
type: 'neutral_section';
}
| {
type: 'non_electrified';
}
)[];
} | null;
geometry?: GeoJsonLineString | null;
gradients?: {
Expand Down Expand Up @@ -2930,7 +2942,7 @@ export type PathProperties = {
export type PathPropertiesInput = {
/** List of supported electrification modes.
Empty if does not support any electrification */
rolling_stock_supported_electrification?: string[];
rolling_stock_supported_electrifications?: string[];
/** list of track sections */
track_ranges: TrackRange[];
};
Expand Down
Empty file added openapi.yaml
Empty file.
Loading