Skip to content

Commit

Permalink
osrd_schemas: explicit signaling systems
Browse files Browse the repository at this point in the history
  • Loading branch information
flomonster committed Sep 5, 2023
1 parent 451d16d commit 16be0d6
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/osrd_schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ jobs:
run: |
cd python/osrd_schemas
poetry install --no-interaction --no-root
poetry run python osrd_schemas/infra.py > current_infra_schema.json
poetry run python osrd_schemas/infra_editor.py > current_infra_schema.json
diff current_infra_schema.json ../../front/src/reducers/osrdconf/infra_schema.json
4 changes: 2 additions & 2 deletions editoast/src/converters/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ pub fn signals(
track,
position,
sight_distance: 400.,
logical_signals: Some(vec![LogicalSignal {
logical_signals: vec![LogicalSignal {
signaling_system: "BAL".to_string(),
settings,
..Default::default()
}]),
}],
linked_detector: Some(node.id.0.to_string()),
extensions: SignalExtensions {
sncf: Some(sncf_extensions(&node)),
Expand Down
3 changes: 2 additions & 1 deletion editoast/src/schema/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub struct Signal {
#[derivative(Default(value = "400."))]
pub sight_distance: f64,
pub linked_detector: Option<String>,
pub logical_signals: Option<Vec<LogicalSignal>>,
#[serde(default)]
pub logical_signals: Vec<LogicalSignal>,
#[serde(default)]
pub extensions: SignalExtensions,
}
Expand Down
208 changes: 195 additions & 13 deletions front/src/reducers/osrdconf/infra_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,66 @@
"title": "ApplicableDirectionsTrackRange",
"type": "object"
},
"BalSystem": {
"properties": {
"next_signaling_systems": {
"description": "The list of allowed input signaling systems",
"items": {
"$ref": "#/$defs/SignalingSystem"
},
"title": "Next Signaling Systems",
"type": "array"
},
"settings": {
"allOf": [
{
"$ref": "#/$defs/__main____BalSystem__Settings"
}
],
"description": "BAL signal settings"
},
"signaling_system": {
"const": "BAL",
"default": "BAL",
"title": "Signaling System"
}
},
"required": [
"settings"
],
"title": "BalSystem",
"type": "object"
},
"BaprSystem": {
"properties": {
"next_signaling_systems": {
"description": "The list of allowed input signaling systems",
"items": {
"$ref": "#/$defs/SignalingSystem"
},
"title": "Next Signaling Systems",
"type": "array"
},
"settings": {
"allOf": [
{
"$ref": "#/$defs/__main____BaprSystem__Settings"
}
],
"description": "BAPR signal settings"
},
"signaling_system": {
"const": "BAPR",
"default": "BAPR",
"title": "Signaling System"
}
},
"required": [
"settings"
],
"title": "BaprSystem",
"type": "object"
},
"BufferStop": {
"description": "This class defines the buffer stop object.\n A buffer stop is a device placed at the end of a dead-end road\n to stop any drifting trains from continuing off the road.\n A buffer stop is characterized by its id and its corresponding track.\n ",
"properties": {
Expand Down Expand Up @@ -284,6 +344,37 @@
"title": "Endpoint",
"type": "string"
},
"FlagSignalParameter": {
"enum": [
"true",
"false"
],
"title": "FlagSignalParameter",
"type": "string"
},
"LimitedLogicalSignal": {
"description": "Limited list of logical signals. Used to generate a usable schema for the front editor",
"discriminator": {
"mapping": {
"BAL": "#/$defs/BalSystem",
"BAPR": "#/$defs/BaprSystem",
"TVM": "#/$defs/TvmSystem"
},
"propertyName": "signaling_system"
},
"oneOf": [
{
"$ref": "#/$defs/BalSystem"
},
{
"$ref": "#/$defs/BaprSystem"
},
{
"$ref": "#/$defs/TvmSystem"
}
],
"title": "LimitedLogicalSignal"
},
"LineString": {
"description": "LineString Model",
"properties": {
Expand Down Expand Up @@ -861,20 +952,12 @@
"title": "Linked Detector"
},
"logical_signals": {
"anyOf": [
{
"items": {
"$ref": "#/$defs/LogicalSignal"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"description": "Logical signals bundled into this physical signal",
"title": "Logical Signals"
"items": {
"$ref": "#/$defs/LimitedLogicalSignal"
},
"title": "Logical Signals",
"type": "array"
},
"position": {
"description": "Offset of the point in meters to the beginning of the track section",
Expand Down Expand Up @@ -999,6 +1082,15 @@
"title": "SignalSncfExtension",
"type": "object"
},
"SignalingSystem": {
"enum": [
"BAL",
"BAPR",
"TVM"
],
"title": "SignalingSystem",
"type": "string"
},
"Slope": {
"description": "\n This class is used to define the slope object.\n A slope correspond at the gradient in the part of corresponding track section.\n The gradient can be positive (case of ramp) or negative (slope case)\n ",
"properties": {
Expand Down Expand Up @@ -1463,6 +1555,96 @@
],
"title": "TrackSectionSncfExtension",
"type": "object"
},
"TvmSystem": {
"properties": {
"next_signaling_systems": {
"description": "The list of allowed input signaling systems",
"items": {
"$ref": "#/$defs/SignalingSystem"
},
"title": "Next Signaling Systems",
"type": "array"
},
"settings": {
"allOf": [
{
"$ref": "#/$defs/__main____TvmSystem__Settings"
}
],
"description": "TVM signal settings"
},
"signaling_system": {
"const": "TVM",
"default": "TVM",
"title": "Signaling System"
}
},
"required": [
"settings"
],
"title": "TvmSystem",
"type": "object"
},
"__main____BalSystem__Settings": {
"properties": {
"Nf": {
"allOf": [
{
"$ref": "#/$defs/FlagSignalParameter"
}
],
"description": "Is the signal non-passable"
}
},
"required": [
"Nf"
],
"title": "Settings",
"type": "object"
},
"__main____BaprSystem__Settings": {
"properties": {
"Nf": {
"allOf": [
{
"$ref": "#/$defs/FlagSignalParameter"
}
],
"description": "Is the signal non-passable"
},
"distant": {
"allOf": [
{
"$ref": "#/$defs/FlagSignalParameter"
}
],
"description": "Is it a distant signal"
}
},
"required": [
"Nf",
"distant"
],
"title": "Settings",
"type": "object"
},
"__main____TvmSystem__Settings": {
"properties": {
"is_430": {
"allOf": [
{
"$ref": "#/$defs/FlagSignalParameter"
}
],
"description": "Is it TVM-430"
}
},
"required": [
"is_430"
],
"title": "Settings",
"type": "object"
}
},
"description": "This class is used to build an infra.",
Expand Down
2 changes: 1 addition & 1 deletion python/api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions python/osrd_schemas/osrd_schemas/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ class Signal(BaseObjectTrait, TrackLocationTrait):
linked_detector: Optional[Identifier] = Field(
description="Identifier of the detector linked to the signal", default=None
)
logical_signals: Optional[List[LogicalSignal]] = Field(
description="Logical signals bundled into this physical signal", default=None
logical_signals: List[LogicalSignal] = Field(
description="Logical signals bundled into this physical signal", default_factory=list
)


Expand Down
71 changes: 71 additions & 0 deletions python/osrd_schemas/osrd_schemas/infra_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from enum import Enum
from typing import List, Literal, Union

import infra
from pydantic import BaseModel, Field, RootModel


class SignalingSystem(str, Enum):
bal = "BAL"
bapr = "BAPR"
tmv = "TVM"


class FlagSignalParameter(str, Enum):
true = "true"
false = "false"


class BaseLogicalSignal(BaseModel):
next_signaling_systems: List[SignalingSystem] = Field(
description="The list of allowed input signaling systems", default_factory=list
)


class BalSystem(BaseLogicalSignal):
class Settings(BaseModel):
Nf: FlagSignalParameter = Field(description="Is the signal non-passable")

signaling_system: Literal["BAL"] = Field(default="BAL")
settings: Settings = Field(description="BAL signal settings")


class BaprSystem(BaseLogicalSignal):
class Settings(BaseModel):
Nf: FlagSignalParameter = Field(description="Is the signal non-passable")
distant: FlagSignalParameter = Field(description="Is it a distant signal")

signaling_system: Literal["BAPR"] = Field(default="BAPR")
settings: Settings = Field(description="BAPR signal settings")


class TvmSystem(BaseLogicalSignal):
class Settings(BaseModel):
is_430: FlagSignalParameter = Field(description="Is it TVM-430")

signaling_system: Literal["TVM"] = Field(default="TVM")
settings: Settings = Field(description="TVM signal settings")


class LimitedLogicalSignal(RootModel):
"""Limited list of logical signals. Used to generate a usable schema for the front editor"""

root: Union[BalSystem, BaprSystem, TvmSystem] = Field(..., discriminator="signaling_system")


class _TmpSignal(BaseModel):
logical_signals: List[LimitedLogicalSignal] = Field(
description="Logical signals bundled into this physical signal", default_factory=list
)


if __name__ == "__main__":
from json import dumps

railjson_schema = infra.RailJsonInfra.model_json_schema()
tmp_signal_schema = _TmpSignal.model_json_schema()
railjson_schema["$defs"].update(tmp_signal_schema["$defs"])
railjson_schema["$defs"]["Signal"]["properties"].update(tmp_signal_schema["properties"])

# sort keys in order to diff correctly in the CI
print(dumps(railjson_schema, indent=4, sort_keys=True))
2 changes: 1 addition & 1 deletion python/osrd_schemas/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "osrd_schemas"
version = "0.6.1"
version = "0.6.2"
description = ""
authors = ["OSRD <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion python/railjson_generator/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16be0d6

Please sign in to comment.