Skip to content

Commit d70428f

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 f9aae87 commit d70428f

File tree

8 files changed

+75
-22
lines changed

8 files changed

+75
-22
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/pathfinding.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ pub mod tests {
504504
.post(format!("/infra/{}/pathfinding/blocks", small_infra.id).as_str())
505505
.json(&json!({
506506
"path_items":[
507-
{"uic":3,"secondary_code":"BV", "track_reference": {"track_label": "V2"}},
508-
{"uic":8 ,"secondary_code":"BV", "track_reference": {"track_label": "V245"}},
507+
{"uic":3,"secondary_code":"BV", "track_reference": {"track_name": "V2"}},
508+
{"uic":8 ,"secondary_code":"BV", "track_reference": {"track_name": "V245"}},
509509
],
510510
"rolling_stock_is_thermal":true,
511511
"rolling_stock_loading_gauge":"G1",
@@ -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)