Skip to content

Commit 2168f09

Browse files
committed
editoast: add new track_section field in operational point layer
Signed-off-by: Youness CHRIFI ALAOUI <youness.chrifi@gmail.com>
1 parent e06f44c commit 2168f09

File tree

9 files changed

+80
-48
lines changed

9 files changed

+80
-48
lines changed

editoast/editoast_models/src/tables.rs

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ diesel::table! {
191191
geographic -> Geometry,
192192
infra_id -> Int8,
193193
kp -> Nullable<Text>,
194+
track_section -> Text,
194195
}
195196
}
196197

editoast/map_layers.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ layers:
8080
views:
8181
geo:
8282
on_field: geographic
83-
data_expr: operational_point.data - 'parts' || jsonb_build_object('kp', layer.kp)
83+
data_expr: operational_point.data - 'parts' || jsonb_build_object('kp', layer.kp, 'track_id', layer.track_section, 'track_name', track_section.data->'extensions'->'sncf'->'track_name')
8484
joins:
8585
- inner join infra_object_operational_point operational_point on operational_point.obj_id = layer.obj_id and operational_point.infra_id = layer.infra_id
86+
- inner join infra_object_track_section track_section on track_section.obj_id = layer.track_section and track_section.infra_id = layer.infra_id
8687

8788
electrifications:
8889
table_name: infra_layer_electrification
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE infra_layer_operational_point DROP COLUMN track_section;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
DELETE FROM infra_layer_operational_point;
2+
ALTER TABLE infra_layer_operational_point ADD COLUMN track_section text NOT NULL;
3+
4+
WITH ops AS (
5+
SELECT obj_id AS op_id,
6+
infra_id,
7+
(
8+
jsonb_array_elements(data->'parts')->'position'
9+
)::float AS position,
10+
jsonb_array_elements(data->'parts')->>'track' AS track_id,
11+
jsonb_array_elements(data->'parts')->'extensions'->'sncf'->>'kp' AS kp
12+
FROM infra_object_operational_point
13+
),
14+
collect AS (
15+
SELECT ops.op_id,
16+
ST_LineInterpolatePoint(
17+
tracks_layer.geographic,
18+
LEAST(
19+
GREATEST(
20+
ops.position / (tracks.data->'length')::float,
21+
0.
22+
),
23+
1.
24+
)
25+
) AS geo,
26+
ops.kp AS kp,
27+
ops.infra_id AS infra_id,
28+
ops.track_id AS track_section
29+
FROM ops
30+
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = ops.track_id AND tracks.infra_id = ops.infra_id
31+
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
32+
AND tracks.infra_id = tracks_layer.infra_id
33+
)
34+
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp, track_section)
35+
SELECT op_id,
36+
infra_id,
37+
geo,
38+
kp,
39+
track_section
40+
FROM collect;

editoast/src/generated_data/sql/generate_operational_point_layer.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ collect AS (
2020
1.
2121
)
2222
) AS geo,
23-
ops.kp AS kp
23+
ops.kp AS kp,
24+
ops.track_id AS track_section
2425
FROM ops
2526
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = ops.track_id
2627
AND tracks.infra_id = $1
2728
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
2829
AND tracks.infra_id = tracks_layer.infra_id
2930
)
30-
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp)
31+
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp, track_section)
3132
SELECT op_id,
3233
$1,
3334
geo,
34-
kp
35+
kp,
36+
track_section
3537
FROM collect

editoast/src/generated_data/sql/insert_operational_point_layer.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ collect AS (
2121
1.
2222
)
2323
) AS geo,
24-
ops.kp AS kp
24+
ops.kp AS kp,
25+
ops.track_id AS track_section
2526
FROM ops
2627
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = ops.track_id
2728
AND tracks.infra_id = $1
2829
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
2930
AND tracks.infra_id = tracks_layer.infra_id
3031
)
31-
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp)
32+
INSERT INTO infra_layer_operational_point (obj_id, infra_id, geographic, kp, track_section)
3233
SELECT op_id,
3334
$1,
3435
geo,
35-
kp
36+
kp,
37+
track_section
3638
FROM collect

editoast/src/models/infra.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,19 @@ impl Infra {
148148

149149
if let Some(layer_table) = get_geometry_layer_table(&object) {
150150
let layer_table = layer_table.to_string();
151-
let sql = if object != ObjectType::Signal {
152-
format!("INSERT INTO {layer_table}(obj_id,geographic,infra_id) SELECT obj_id,geographic,$1 FROM {layer_table} WHERE infra_id=$2")
153-
} else {
154-
format!("INSERT INTO {layer_table}(obj_id,geographic,infra_id, angle_geo, signaling_system, sprite)
151+
let sql = match object {
152+
ObjectType::Signal => {
153+
format!("INSERT INTO {layer_table}(obj_id,geographic,infra_id, angle_geo, signaling_system, sprite)
155154
SELECT obj_id,geographic,$1,angle_geo, signaling_system, sprite FROM {layer_table} WHERE infra_id = $2")
155+
}
156+
,
157+
ObjectType::OperationalPoint => {
158+
format!("INSERT INTO {layer_table}(obj_id,geographic,infra_id, kp, track_section)
159+
SELECT obj_id,geographic,$1,kp, track_section FROM {layer_table} WHERE infra_id = $2")
160+
}
161+
_ => {
162+
format!("INSERT INTO {layer_table}(obj_id,geographic,infra_id) SELECT obj_id,geographic,$1 FROM {layer_table} WHERE infra_id=$2")
163+
}
156164
};
157165

158166
sql_query(sql)

editoast/src/views/path/path_item_cache.rs

+7-28
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,20 @@ impl PathItemCache {
117117
PathItemLocation::OperationalPointReference(OperationalPointReference {
118118
reference: OperationalPointIdentifier::OperationalPointId { operational_point },
119119
track_reference,
120-
}) => match self.get_from_id(&operational_point.0) {
121-
Some(op) => {
122-
let track_offsets = op.track_offset();
123-
let track_offsets =
124-
self.track_reference_filter(track_offsets, track_reference);
125-
if track_offsets.is_empty() {
126-
invalid_path_items.push(InvalidPathItem {
127-
index,
128-
path_item: path_item.clone(),
129-
});
130-
continue;
131-
};
132-
track_offsets
120+
}) => {
121+
let mut track_offsets = vec![];
122+
if let Some(op) = self.get_from_id(&operational_point.0) {
123+
track_offsets = op.track_offset();
124+
track_offsets = self.track_reference_filter(track_offsets, track_reference);
133125
}
134-
None => {
126+
if track_offsets.is_empty() {
135127
invalid_path_items.push(InvalidPathItem {
136128
index,
137129
path_item: path_item.clone(),
138130
});
139131
continue;
140132
}
133+
track_offsets
141134
},
142135
PathItemLocation::OperationalPointReference(OperationalPointReference {
143136
reference:
@@ -152,13 +145,6 @@ impl PathItemCache {
152145
.cloned()
153146
.unwrap_or_default();
154147
let ops = secondary_code_filter(secondary_code, ops);
155-
if ops.is_empty() {
156-
invalid_path_items.push(InvalidPathItem {
157-
index,
158-
path_item: path_item.clone(),
159-
});
160-
continue;
161-
}
162148
let track_offsets = track_offsets_from_ops(&ops);
163149
let track_offsets = self.track_reference_filter(track_offsets, track_reference);
164150
if track_offsets.is_empty() {
@@ -183,13 +169,6 @@ impl PathItemCache {
183169
.cloned()
184170
.unwrap_or_default();
185171
let ops = secondary_code_filter(secondary_code, ops);
186-
if ops.is_empty() {
187-
invalid_path_items.push(InvalidPathItem {
188-
index,
189-
path_item: path_item.clone(),
190-
});
191-
continue;
192-
}
193172
let track_offsets = track_offsets_from_ops(&ops);
194173
let track_offsets = self.track_reference_filter(track_offsets, track_reference);
195174
if track_offsets.is_empty() {

editoast/src/views/path/pathfinding.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,13 @@ pub mod tests {
525525
index: 1,
526526
path_item: PathItemLocation::OperationalPointReference(
527527
OperationalPointReference {
528-
reference:
529-
OperationalPointIdentifier::OperationalPointUic {
530-
uic: 8,
531-
secondary_code: Some("BV".into())
532-
},
533-
track_reference:
534-
Some(TrackReference::Name {
535-
track_name: "V245".into()
536-
}),
528+
reference: OperationalPointIdentifier::OperationalPointUic {
529+
uic: 8,
530+
secondary_code: Some("BV".into())
531+
},
532+
track_reference: Some(TrackReference::Name {
533+
track_name: "V245".into()
534+
}),
537535
}
538536
)
539537
}]

0 commit comments

Comments
 (0)