Skip to content

Commit 6928f67

Browse files
committed
editoast: add level crossings to railjson_generator
1 parent 55eb097 commit 6928f67

File tree

18 files changed

+293
-53
lines changed

18 files changed

+293
-53
lines changed

python/osrd_schemas/osrd_schemas/infra.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ class RailJsonInfra(BaseModel):
600600
operational_points: List[OperationalPoint] = Field(
601601
description="List of operational points of the corresponding infra"
602602
)
603+
level_crossings: List[LevelCrossing] = Field(
604+
description="List of level crossings of the corresponding infra"
605+
)
603606
routes: List[Route] = Field(description="Routes of the infra")
604607
extended_switch_types: List[SwitchType] = Field(
605608
default=[],

python/railjson_generator/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ uv run -m railjson_generator ../../tests/data/infras ../../tests/infra-scripts/*
2727

2828
- `__init__(self) -> InfraBuilder`: Instantiates an infra builder.
2929
- `add_track_section(self, length, label="track.X", waypoints=[], signals=[], operational_points=[]) -> TrackSection`: Add a track section.
30+
- `add_level_crossing(self, id, name="lc.X", short_zone_length=1000) -> LevelCrossing`: Add a level crossing.
3031
- `add_point_switch(self, base, left, right, label="switch.X", delay=0) -> Switch`: Add a point.
3132
- `add_crossing(self, north, south, east, west, label="switch.X", delay=0) -> Switch`: Add a cross switch.
3233
- `add_double_slip_switch(self, north_1, north_2, south_1, south_2, label="switch.X", delay=0) -> Switch`: Add a double cross switch.
@@ -67,6 +68,10 @@ Route can either be manually created, or generated using `generate_routes`, and
6768

6869
- `add_part(self, track, offset)`: Link an operational point to a position.
6970

71+
### Level crossing
72+
73+
- `add_part(self, track, position, pedal_upstream, pedal_downstream)`: Add a part to a level crossing.
74+
7075
### Infra
7176

7277
- `save(self, path)`: Format to railjson and save at the given location.

python/railjson_generator/railjson_generator/infra_builder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .schema.infra.infra import BufferStop, Infra, Switch, Detector
66
from .schema.infra.neutral_section import NeutralSection
77
from .schema.infra.operational_point import OperationalPoint
8+
from .schema.infra.level_crossing import LevelCrossing
89
from .schema.infra.route import Route
910
from .schema.infra.speed_section import SpeedSection
1011
from .schema.infra.switch import (
@@ -86,6 +87,16 @@ def add_point_switch(
8687
self.infra.switches.append(switch)
8788
return switch
8889

90+
def add_level_crossing(
91+
self, id: str, name: str, short_zone_length: int
92+
) -> LevelCrossing:
93+
"""Build a level crossing, add it to the infra, and return it."""
94+
lc = LevelCrossing(
95+
id=id, name=name, short_zone_length=short_zone_length, parts=[]
96+
)
97+
self.infra.level_crossings.append(lc)
98+
return lc
99+
89100
def add_crossing(
90101
self,
91102
north: TrackEndpoint,

python/railjson_generator/railjson_generator/schema/infra/infra.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from railjson_generator.schema.infra.electrification import Electrification
88
from railjson_generator.schema.infra.neutral_section import NeutralSection
99
from railjson_generator.schema.infra.operational_point import OperationalPoint
10+
from railjson_generator.schema.infra.level_crossing import LevelCrossing
1011
from railjson_generator.schema.infra.route import Route
1112
from railjson_generator.schema.infra.speed_section import SpeedSection
1213
from railjson_generator.schema.infra.switch import Switch
@@ -19,6 +20,7 @@ class Infra:
1920
track_sections: List[TrackSection] = field(default_factory=list)
2021
switches: List[Switch] = field(default_factory=list)
2122
operational_points: List[OperationalPoint] = field(default_factory=list)
23+
level_crossings: List[LevelCrossing] = field(default_factory=list)
2224
routes: List[Route] = field(default_factory=list)
2325
speed_sections: List[SpeedSection] = field(default_factory=list)
2426
electrifications: List[Electrification] = field(default_factory=list)
@@ -40,6 +42,7 @@ def to_rjs(self) -> infra.RailJsonInfra:
4042
buffer_stops=list(self.make_rjs_buffer_stops()),
4143
detectors=list(self.make_rjs_detectors()),
4244
operational_points=self.make_rjs_operational_points(),
45+
level_crossings=[lc.to_rjs() for lc in self.level_crossings],
4346
extended_switch_types=[],
4447
speed_sections=[
4548
speed_section.to_rjs() for speed_section in self.speed_sections
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from dataclasses import dataclass
2+
from typing import List
3+
4+
from osrd_schemas import infra
5+
6+
7+
@dataclass
8+
class LevelCrossingPart:
9+
pedal_upstream: int
10+
pedal_downstream: int
11+
position: float
12+
track: str
13+
14+
def to_rjs(self):
15+
return infra.LevelCrossingPart(
16+
track=self.track,
17+
position=self.position,
18+
pedal_upstream=self.pedal_upstream,
19+
pedal_downstream=self.pedal_downstream,
20+
)
21+
22+
23+
@dataclass
24+
class LevelCrossing:
25+
id: str
26+
name: str
27+
short_zone_length: int
28+
parts: List[LevelCrossingPart]
29+
30+
def add_part(
31+
self, track: str, position: float, pedal_upstream: int, pedal_downstream: int
32+
):
33+
part = LevelCrossingPart(
34+
track=track,
35+
position=position,
36+
pedal_upstream=pedal_upstream,
37+
pedal_downstream=pedal_downstream,
38+
)
39+
self.parts.append(part)
40+
41+
def to_rjs(self):
42+
return infra.LevelCrossing(
43+
id=self.id,
44+
name=self.name,
45+
short_zone_length=self.short_zone_length,
46+
parts=[part.to_rjs() for part in self.parts],
47+
)

0 commit comments

Comments
 (0)