Skip to content

Commit

Permalink
railjson: remove "applicable_directions" field from detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
hamz2a committed Jan 8, 2024
1 parent 1f806fd commit 66c4afb
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 506 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RJSInfra {
.build()
.adapter(RJSInfra.class);

public static final transient String CURRENT_VERSION = "3.4.6";
public static final transient String CURRENT_VERSION = "3.4.7";

/** The version of the infra format used */
public String version;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UPDATE infra_object_detector
SET data = jsonb_set(data, '{applicable_directions}', '"BOTH"');

UPDATE infra
SET railjson_version = '3.4.6';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UPDATE infra_object_detector
SET data = data - 'applicable_directions';

UPDATE infra
SET railjson_version = '3.4.7';
44 changes: 11 additions & 33 deletions editoast/src/converters/generate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,16 @@ impl Graph {

fn edges_from_track_sections(&mut self, railjson: &RailJson) {
// We need to split handle separately the signals that are forward
let mut fwd_detectors = HashMap::<_, Vec<_>>::new();
let mut push_fwd = |d: &Detector| {
fwd_detectors
.entry(d.track.clone())
.or_default()
.push(d.clone())
};
let mut bwd_detectors = HashMap::<_, Vec<_>>::new();
let mut push_bwd = |d: &Detector| {
bwd_detectors
.entry(d.track.clone())
.or_default()
.push(d.clone())
};
let mut detectors = HashMap::<_, Vec<_>>::new();

for detector in &railjson.detectors {
match detector.applicable_directions {
ApplicableDirections::StartToStop => push_fwd(detector),
ApplicableDirections::StopToStart => push_bwd(detector),
ApplicableDirections::Both => {
push_fwd(detector);
push_bwd(detector);
}
}
detectors
.entry(detector.track.clone())
.or_default()
.push(detector.clone());
}

for (track, detectors) in &fwd_detectors {
for (track, detectors) in &detectors {
// When going from start to end
// We only consider the last detector (closest to end) that is on the same track
// All the other can be considered as block defining
Expand All @@ -96,9 +79,7 @@ impl Graph {
let v = Node::from_track_endpoint(track, Endpoint::End);
self.add_directed_edge(u, d.clone(), EdgeType::ToDetector);
self.add_directed_edge(d.clone(), v, EdgeType::FromDetector(Direction::StartToStop));
}

for (track, detectors) in &bwd_detectors {
// When going from end to start,
// We only consider the first detector (closest to start) that is on the same track
// All the other can be considered as block defining
Expand Down Expand Up @@ -128,11 +109,8 @@ impl Graph {
// We only consider tracks that have no detector for the given direction on them as we split them
let u = Node::from_track_endpoint(&track.id, Endpoint::Begin);
let v = Node::from_track_endpoint(&track.id, Endpoint::End);
if !fwd_detectors.contains_key(&track.id) {
self.add_directed_edge(u.clone(), v.clone(), EdgeType::Track);
}
if !bwd_detectors.contains_key(&track.id) {
self.add_directed_edge(v.clone(), u.clone(), EdgeType::Track);
if !detectors.contains_key(&track.id) {
self.add_symmetrical_edge(v.clone(), u.clone(), EdgeType::Track);
}
}
}
Expand Down Expand Up @@ -401,16 +379,16 @@ mod tests {
}

#[test]
/* ----o---d>---
\------
/* ----o---<d>---
\-------
The test case has one switch and one detector
*/
fn generate_routes() {
let railjson =
crate::converters::osm_to_railjson::parse_osm("src/tests/routes.osm.pbf".into())
.unwrap();
let routes = super::routes(&railjson);
assert_eq!(5, routes.len());
assert_eq!(6, routes.len());
let routes_with_switches_count = routes
.iter()
.filter(|r| r.switches_directions.len() == 1)
Expand Down
5 changes: 0 additions & 5 deletions editoast/src/converters/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,6 @@ pub fn detector(signal: &Signal) -> Detector {
id: signal.id.clone(),
track: signal.track.clone(),
position: signal.position,
applicable_directions: if signal.direction == Direction::StartToStop {
ApplicableDirections::StartToStop
} else {
ApplicableDirections::StopToStart
},
extensions: Default::default(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/models/infra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use strum::IntoEnumIterator;
use thiserror::Error;
use uuid::Uuid;

pub const RAILJSON_VERSION: &str = "3.4.6";
pub const RAILJSON_VERSION: &str = "3.4.7";
pub const INFRA_VERSION: &str = "0";

#[derive(
Expand Down
2 changes: 0 additions & 2 deletions editoast/src/schema/detector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::ApplicableDirections;
use super::OSRDIdentified;

use super::utils::Identifier;
Expand All @@ -23,7 +22,6 @@ pub struct Detector {
#[derivative(Default(value = r#""InvalidRef".into()"#))]
pub track: Identifier,
pub position: f64,
pub applicable_directions: ApplicableDirections,
#[serde(default)]
pub extensions: DetectorExtension,
}
Expand Down
Loading

0 comments on commit 66c4afb

Please sign in to comment.