Skip to content

Commit

Permalink
editoast: modify schemas, delete track_link and adapt editoast
Browse files Browse the repository at this point in the history
  • Loading branch information
Tguisnet committed Oct 11, 2023
1 parent d6f7ae1 commit 44edaea
Show file tree
Hide file tree
Showing 49 changed files with 178 additions and 841 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,4 @@ public class RJSInfra {

@Json(name = "neutral_sections")
public List<RJSNeutralSection> neutralSections;
/** Create a new serialized RailJSON file */
public RJSInfra(
Collection<RJSTrackSection> trackSections,
Collection<RJSRoute> routes,
List<RJSSignal> signals,
List<RJSBufferStop> bufferStops,
List<RJSTrainDetector> detectors
) {
this.trackSections = trackSections;
this.switches = new ArrayList<>();
this.operationalPoints = new ArrayList<>();
this.routes = routes;
this.switchTypes = new ArrayList<>();
this.signals = signals;
this.bufferStops = bufferStops;
this.detectors = detectors;
this.speedSections = new ArrayList<>();
this.catenaries = new ArrayList<>();
this.neutralSections = new ArrayList<>();
}
}
Empty file.
20 changes: 20 additions & 0 deletions editoast/migrations/2023-10-11-222214_delete_track_links/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- This file should undo anything in `up.sql`

CREATE TABLE infra_layer_track_section_link (
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
obj_id varchar(255) NOT NULL,
geographic geometry(point, 3857) NOT NULL,
schematic geometry(point, 3857) NOT NULL,
infra_id int8 NOT NULL REFERENCES infra(id) ON DELETE CASCADE,
UNIQUE (infra_id, obj_id)
);
CREATE INDEX infra_layer_track_section_link_geographic ON infra_layer_track_section_link USING gist (geographic);
CREATE INDEX infra_layer_track_section_link_schematic ON infra_layer_track_section_link USING gist (schematic);

CREATE TABLE infra_object_track_section_link (
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
obj_id varchar(255) NOT NULL,
data jsonb NOT NULL,
infra_id int8 NOT NULL REFERENCES infra(id) ON DELETE CASCADE,
UNIQUE (infra_id, obj_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Your SQL goes here

DROP TABLE infra_layer_track_section_link;
DROP TABLE infra_object_track_section_link;
4 changes: 0 additions & 4 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ components:
- out_of_range
- overlapping_speed_sections
- overlapping_switches
- overlapping_track_links
- overlapping_catenaries
- unknown_port_name
- unused_port
Expand Down Expand Up @@ -659,7 +658,6 @@ components:
- Signal
- SpeedSection
- Detector
- TrackSectionLink
- Switch
- SwitchType
- BufferStop
Expand Down Expand Up @@ -1132,8 +1130,6 @@ components:
type: array
switches:
type: array
track_section_links:
type: array
track_sections:
type: array
version:
Expand Down
4 changes: 0 additions & 4 deletions editoast/openapi_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,6 @@ components:
- Signal
- SpeedSection
- Detector
- TrackSectionLink
- Switch
- SwitchType
- BufferStop
Expand All @@ -2504,8 +2503,6 @@ components:
type: array
switches:
type: array
track_section_links:
type: array
track_sections:
type: array
signals:
Expand Down Expand Up @@ -2708,7 +2705,6 @@ components:
- out_of_range
- overlapping_speed_sections
- overlapping_switches
- overlapping_track_links
- overlapping_catenaries
- unknown_port_name
- unused_port
Expand Down
14 changes: 2 additions & 12 deletions editoast/src/converters/generate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ impl Node {
}

/// An edge connects two nodes
/// This connection can be between two tracks (switch and section link)
/// This connection can be between two tracks (switch)
/// Or traversing a whole track
/// Or along a track (detector and buffer stops)
#[derive(Clone, Debug)]
enum EdgeType {
Switch { id: Identifier, port: Identifier },
SectionLink,
Track,
Buffer(Direction),
ToDetector,
Expand All @@ -49,10 +48,9 @@ struct Graph {
}

impl Graph {
/* Part 2: build the graph from track sections, track sections links, switches, buffers and detectors */
/* Part 2: build the graph from track sections, switches, buffers and detectors */
fn load(&mut self, railjson: &RailJson) {
self.edges_from_track_sections(railjson);
self.edges_from_track_sections_links(railjson);
self.edges_from_switches(railjson);
}

Expand Down Expand Up @@ -139,14 +137,6 @@ impl Graph {
}
}

fn edges_from_track_sections_links(&mut self, railjson: &RailJson) {
for link in &railjson.track_section_links {
let u = Node::TrackEndpoint(link.src.clone());
let v = Node::TrackEndpoint(link.dst.clone());
self.add_symmetrical_edge(u, v, EdgeType::SectionLink);
}
}

fn edges_from_switches(&mut self, railjson: &RailJson) {
for switch in &railjson.switches {
let switch_type = railjson
Expand Down
16 changes: 9 additions & 7 deletions editoast/src/converters/osm_to_railjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ pub fn parse_osm(osm_pbf_in: PathBuf) -> Result<RailJson, Box<dyn Error + Send +
.buffer_stops
.push(edge_to_buffer(&node, adj.edges[1], 1));
}
(2, 1) => railjson.track_section_links.push(TrackSectionLink {
id: node.0.to_string().into(),
src: adj.branches[0].0.clone(),
dst: adj.branches[0].1.clone(),
}),
(2, 1) => railjson.switches.push(link_switch(node, &adj.branches)),
(3, 2) => railjson.switches.push(point_switch(node, &adj.branches)),
(4, 2) => railjson.switches.push(cross_switch(node, &adj.branches)),
(4, 4) => railjson
Expand Down Expand Up @@ -148,12 +144,14 @@ mod tests {

#[test]
fn parse_switches() {
/// Need changes because of links turning into switches
fn port_eq(ports: &HashMap<Identifier, TrackEndpoint>, name: &str, expected: &str) -> bool {
ports.get(&name.into()).unwrap().track.0 == expected
}
let mut railjson = parse_osm("src/tests/switches.osm.pbf".into()).unwrap();
assert_eq!(3, railjson.switch_types.len());
assert_eq!(3, railjson.switches.len());
assert_eq!(4, railjson.switch_types.len());
assert_eq!(4, railjson.switches.len());
assert_eq!(18, railjson.buffer_stops.len());

// Switches can be in a random order, we sort them to be sure to extract the expected ones
Expand All @@ -162,6 +160,10 @@ mod tests {
.sort_by(|a, b| a.switch_type.as_str().cmp(b.switch_type.as_str()));

let switch = &railjson.switches[2];
assert_eq!("link", switch.switch_type.as_str());
assert_eq!(2, switch.ports.len());

let switch = &railjson.switches[3];
assert_eq!("point", switch.switch_type.as_str());
assert_eq!(3, switch.ports.len());
assert!(port_eq(&switch.ports, "BASE", "-103478-0"));
Expand Down
27 changes: 27 additions & 0 deletions editoast/src/converters/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ use osmpbfreader::Node;
use std::str::FromStr;

pub fn default_switch_types() -> Vec<SwitchType> {
let mut link_group = std::collections::HashMap::new();
link_group.insert(
"LINK".into(),
vec![SwitchPortConnection {
src: "SOURCE".into(),
dst: "DESTINATION".into(),
}],
);

let mut point_groups = std::collections::HashMap::new();
point_groups.insert(
"LEFT".into(),
Expand Down Expand Up @@ -70,6 +79,11 @@ pub fn default_switch_types() -> Vec<SwitchType> {
);

vec![
SwitchType {
id: "link".into(),
ports: vec!["SOURCE".into(), "DESTINATION".into(), "RIGHT".into()],
groups: link_group,
},
SwitchType {
id: "point".into(),
ports: vec!["BASE".into(), "LEFT".into(), "RIGHT".into()],
Expand Down Expand Up @@ -166,6 +180,19 @@ pub struct NodeAdjacencies<'a> {
pub branches: Vec<Branch>,
}

pub fn link_switch(node: NodeId, branches: &[Branch]) -> Switch {
let mut ports = HashMap::new();
ports.insert("SOURCE".into(), branches[0].0.clone());
ports.insert("DESTINATION".into(), branches[0].1.clone());
Switch {
id: node.0.to_string().into(),
switch_type: "link".into(),
ports,
group_change_delay: 0.,
..Default::default()
}
}

pub fn point_switch(node: NodeId, branches: &[Branch]) -> Switch {
let mut endpoint_count = HashMap::<&TrackEndpoint, u64>::new();
for (src, dst) in branches {
Expand Down
20 changes: 1 addition & 19 deletions editoast/src/generated_data/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod signals;
pub mod speed_sections;
pub mod switch_types;
pub mod switches;
pub mod track_section_links;
pub mod track_sections;

use std::collections::HashMap;
Expand Down Expand Up @@ -153,7 +152,6 @@ fn get_insert_errors_query(obj_type: ObjectType) -> &'static str {
ObjectType::NeutralSection => include_str!("sql/neutral_sections_insert_errors.sql"),
ObjectType::SpeedSection => include_str!("sql/speed_sections_insert_errors.sql"),
ObjectType::Detector => include_str!("sql/detectors_insert_errors.sql"),
ObjectType::TrackSectionLink => include_str!("sql/track_section_links_insert_errors.sql"),
ObjectType::Switch => include_str!("sql/switches_insert_errors.sql"),
ObjectType::SwitchType => include_str!("sql/switch_types_insert_errors.sql"),
ObjectType::BufferStop => include_str!("sql/buffer_stops_insert_errors.sql"),
Expand Down Expand Up @@ -265,14 +263,6 @@ impl GeneratedData for ErrorLayer {
&routes::GLOBAL_GENERATORS,
));

infra_errors.extend(generate_errors(
ObjectType::TrackSectionLink,
infra_cache,
&graph,
&track_section_links::OBJECT_GENERATORS,
&track_section_links::GLOBAL_GENERATORS,
));

infra_errors.extend(generate_errors(
ObjectType::Switch,
infra_cache,
Expand Down Expand Up @@ -311,7 +301,7 @@ impl GeneratedData for ErrorLayer {
mod test {
use super::{
buffer_stops, catenaries, detectors, generate_errors, operational_points, routes, signals,
speed_sections, switch_types, switches, track_section_links, track_sections, Graph,
speed_sections, switch_types, switches, track_sections, Graph,
};

use crate::infra_cache::tests::{create_buffer_stop_cache, create_small_infra_cache};
Expand Down Expand Up @@ -389,14 +379,6 @@ mod test {
&[],
)
.is_empty());
assert!(generate_errors(
ObjectType::TrackSectionLink,
&small_infra_cache,
&graph,
&[],
&track_section_links::GLOBAL_GENERATORS,
)
.is_empty());
assert!(generate_errors(
ObjectType::Switch,
&small_infra_cache,
Expand Down
8 changes: 6 additions & 2 deletions editoast/src/generated_data/error/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ mod tests {
Direction::StartToStop,
Waypoint::new_detector("D1"),
vec!["D2".into()],
Default::default(),
[("tracklink".into(), "LINK".into())].into(),
);
infra_cache.add(route.clone());
let graph = Graph::load(&infra_cache);
Expand All @@ -435,7 +435,11 @@ mod tests {
Direction::StartToStop,
Waypoint::new_detector("D1"),
vec![],
[("switch".into(), "RIGHT".into())].into(),
[
("tracklink".into(), "LINK".into()),
("switch".into(), "RIGHT".into()),
]
.into(),
);
infra_cache.add(route.clone());
let graph = Graph::load(&infra_cache);
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions editoast/src/generated_data/error/switches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub fn check_match_ports_type(
}
}

// TODO : check overlapping switch link and classical switch ?

/// Check if the switch ports are not already used by another switch
fn check_overlapping(
switch: &ObjectCache,
Expand Down
Loading

0 comments on commit 44edaea

Please sign in to comment.