Skip to content

Commit

Permalink
editoast: fix psl signs angle
Browse files Browse the repository at this point in the history
  • Loading branch information
younesschrifi committed Feb 5, 2024
1 parent 914b9c3 commit a7e2358
Show file tree
Hide file tree
Showing 24 changed files with 245 additions and 137 deletions.
4 changes: 2 additions & 2 deletions editoast/map_layers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ layers:
geo:
on_field: geographic
cache_duration: 3600
data_expr: layer.data
data_expr: layer.data || jsonb_build_object('angle', layer.angle_geo)
sch:
on_field: schematic
cache_duration: 3600
data_expr: layer.data
data_expr: layer.data || jsonb_build_object('angle', layer.angle_geo)

neutral_signs:
table_name: infra_layer_neutral_sign
Expand Down
51 changes: 51 additions & 0 deletions editoast/migrations/2024-01-30-232707_add_neutral_sign/down.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
DROP TABLE infra_layer_neutral_sign;
ALTER TABLE infra_layer_psl_sign DROP COLUMN angle_geo;
ALTER TABLE infra_layer_psl_sign DROP COLUMN angle_sch;
UPDATE infra_object_speed_section
SET data = jsonb_set(
data,
'{extensions,psl_sncf,announcement}',
(
SELECT jsonb_agg(
jsonb_set(
jsonb_set(element - 'direction', '{angle_geo}', '0'),
'{angle_sch}',
'0'
)
)
FROM jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement') AS element
)
)
WHERE data->'extensions'->'psl_sncf'->'announcement' IS NOT NULL
AND data->'extensions'->'psl_sncf'->'announcement' != '[]'::jsonb;
UPDATE infra_object_speed_section
SET data = jsonb_set(
data,
'{extensions,psl_sncf,r}',
(
SELECT jsonb_agg(
jsonb_set(
jsonb_set(element - 'direction', '{angle_geo}', '0'),
'{angle_sch}',
'0'
)
)
FROM jsonb_array_elements(data->'extensions'->'psl_sncf'->'r') AS element
)
)
WHERE data->'extensions'->'psl_sncf'->'r' IS NOT NULL
AND data->'extensions'->'psl_sncf'->'r' != '[]'::jsonb;
UPDATE infra_object_speed_section
SET data = jsonb_set(
jsonb_set(
jsonb_set(
data,
'{extensions,psl_sncf,z}',
(data->'extensions'->'psl_sncf'->'z') - 'direction'
),
'{extensions,psl_sncf,z,angle_geo}',
'0'
),
'{extensions,psl_sncf,z,angle_sch}',
'0'
)
WHERE data->'extensions'->'psl_sncf'->'z' IS NOT NULL;
UPDATE infra
SET railjson_version = '3.4.8';
49 changes: 49 additions & 0 deletions editoast/migrations/2024-01-30-232707_add_neutral_sign/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,54 @@ CREATE TABLE infra_layer_neutral_sign (
);
CREATE INDEX infra_layer_neutral_sign_geographic ON infra_layer_neutral_sign USING gist (geographic);
CREATE INDEX infra_layer_neutral_sign_schematic ON infra_layer_neutral_sign USING gist (schematic);
ALTER TABLE infra_layer_psl_sign
ADD COLUMN angle_geo float8 DEFAULT 0;
ALTER TABLE infra_layer_psl_sign
ADD COLUMN angle_sch float8 DEFAULT 0;
UPDATE infra_object_speed_section
SET data = jsonb_set(
jsonb_set(
data,
'{extensions,psl_sncf,z}',
(data->'extensions'->'psl_sncf'->'z') - 'angle_geo' - 'angle_sch'
),
'{extensions,psl_sncf,z,direction}',
'"START_TO_STOP"'
)
WHERE data->'extensions'->'psl_sncf'->'z' IS NOT NULL;
UPDATE infra_object_speed_section
SET data = jsonb_set(
data,
'{extensions,psl_sncf,r}',
(
SELECT jsonb_agg(
jsonb_set(
element - 'angle_geo' - 'angle_sch',
'{direction}',
'"START_TO_STOP"'
)
)
FROM jsonb_array_elements(data->'extensions'->'psl_sncf'->'r') AS element
)
)
WHERE data->'extensions'->'psl_sncf'->'r' IS NOT NULL
AND data->'extensions'->'psl_sncf'->'r' != '[]'::jsonb;
UPDATE infra_object_speed_section
SET data = jsonb_set(
data,
'{extensions,psl_sncf,announcement}',
(
SELECT jsonb_agg(
jsonb_set(
element - 'angle_geo' - 'angle_sch',
'{direction}',
'"START_TO_STOP"'
)
)
FROM jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement') AS element
)
)
WHERE data->'extensions'->'psl_sncf'->'announcement' IS NOT NULL
AND data->'extensions'->'psl_sncf'->'announcement' != '[]'::jsonb;
UPDATE infra
SET railjson_version = '3.4.9';
76 changes: 50 additions & 26 deletions editoast/src/generated_data/sql/generate_psl_sign_layer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WITH signs AS (
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement')->'position'
)::float AS position,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement')->>'track' AS track_id,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement')->>'direction' AS direction,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement') AS data
FROM infra_object_speed_section
WHERE infra_id = $1
Expand All @@ -14,6 +15,7 @@ WITH signs AS (
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r')->'position'
)::float AS position,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r')->>'track' AS track_id,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r')->>'direction' AS direction,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r') AS data
FROM infra_object_speed_section
WHERE infra_id = $1
Expand All @@ -22,6 +24,7 @@ WITH signs AS (
SELECT obj_id AS sc_id,
(data->'extensions'->'psl_sncf'->'z'->'position')::float AS position,
data->'extensions'->'psl_sncf'->'z'->>'track' AS track_id,
data->'extensions'->'psl_sncf'->'z'->>'direction' AS direction,
data->'extensions'->'psl_sncf'->'z' AS data
FROM infra_object_speed_section
WHERE infra_id = $1
Expand All @@ -30,36 +33,57 @@ WITH signs AS (
collect AS (
SELECT signs.sc_id,
signs.data,
ST_LineInterpolatePoint(
tracks_layer.geographic,
LEAST(
GREATEST(
signs.position / (tracks.data->'length')::float,
0.
),
1.
)
) AS geo,
ST_LineInterpolatePoint(
tracks_layer.schematic,
LEAST(
GREATEST(
signs.position / (tracks.data->'length')::float,
0.
),
1.
)
) AS sch
tracks_layer.geographic AS track_geo,
tracks_layer.schematic AS track_sch,
LEAST(
GREATEST(position / (tracks.data->>'length')::float, 0.),
1.
) AS norm_pos,
CASE
direction
WHEN 'STOP_TO_START' THEN 180.
ELSE 0.
END AS angle_direction
FROM signs
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = signs.track_id
AND tracks.infra_id = $1
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
INNER JOIN infra_layer_track_section AS tracks_layer ON signs.track_id = tracks_layer.obj_id
AND tracks.infra_id = tracks_layer.infra_id
)
INSERT INTO infra_layer_psl_sign (obj_id, infra_id, geographic, schematic, data)
SELECT sc_id,
INSERT INTO infra_layer_psl_sign (
obj_id,
infra_id,
geographic,
schematic,
angle_geo,
angle_sch,
data
)
SELECT DISTINCT ON (
ST_LineInterpolatePoint(track_geo, norm_pos),
ST_LineInterpolatePoint(track_sch, norm_pos),
(data->>'type')::text
) collect.sc_id,
$1,
geo,
sch,
data
ST_LineInterpolatePoint(track_geo, norm_pos),
ST_LineInterpolatePoint(track_sch, norm_pos),
COALESCE(
degrees(
ST_Azimuth(
ST_LineInterpolatePoint(track_geo, GREATEST(norm_pos - 0.0001, 0.)),
ST_LineInterpolatePoint(track_geo, LEAST(norm_pos + 0.0001, 1.))
)
) + angle_direction,
0.
),
COALESCE(
degrees(
ST_Azimuth(
ST_LineInterpolatePoint(track_sch, GREATEST(norm_pos - 0.0001, 0.)),
ST_LineInterpolatePoint(track_sch, LEAST(norm_pos + 0.0001, 1.))
)
) + angle_direction,
0.
),
collect.data
FROM collect
76 changes: 50 additions & 26 deletions editoast/src/generated_data/sql/insert_psl_sign_layer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WITH signs AS (
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement')->'position'
)::float AS position,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement')->>'track' AS track_id,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement')->>'direction' AS direction,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'announcement') AS data
FROM infra_object_speed_section
WHERE infra_id = $1
Expand All @@ -15,6 +16,7 @@ WITH signs AS (
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r')->'position'
)::float AS position,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r')->>'track' AS track_id,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r')->>'direction' AS direction,
jsonb_array_elements(data->'extensions'->'psl_sncf'->'r') AS data
FROM infra_object_speed_section
WHERE infra_id = $1
Expand All @@ -24,6 +26,7 @@ WITH signs AS (
SELECT obj_id AS sc_id,
(data->'extensions'->'psl_sncf'->'z'->'position')::float AS position,
data->'extensions'->'psl_sncf'->'z'->>'track' AS track_id,
data->'extensions'->'psl_sncf'->'z'->>'direction' AS direction,
data->'extensions'->'psl_sncf'->'z' AS data
FROM infra_object_speed_section
WHERE infra_id = $1
Expand All @@ -33,36 +36,57 @@ WITH signs AS (
collect AS (
SELECT signs.sc_id,
signs.data,
ST_LineInterpolatePoint(
tracks_layer.geographic,
LEAST(
GREATEST(
signs.position / (tracks.data->'length')::float,
0.
),
1.
)
) AS geo,
ST_LineInterpolatePoint(
tracks_layer.schematic,
LEAST(
GREATEST(
signs.position / (tracks.data->'length')::float,
0.
),
1.
)
) AS sch
tracks_layer.geographic AS track_geo,
tracks_layer.schematic AS track_sch,
LEAST(
GREATEST(position / (tracks.data->>'length')::float, 0.),
1.
) AS norm_pos,
CASE
direction
WHEN 'STOP_TO_START' THEN 180.
ELSE 0.
END AS angle_direction
FROM signs
INNER JOIN infra_object_track_section AS tracks ON tracks.obj_id = signs.track_id
AND tracks.infra_id = $1
INNER JOIN infra_layer_track_section AS tracks_layer ON tracks.obj_id = tracks_layer.obj_id
INNER JOIN infra_layer_track_section AS tracks_layer ON signs.track_id = tracks_layer.obj_id
AND tracks.infra_id = tracks_layer.infra_id
)
INSERT INTO infra_layer_psl_sign (obj_id, infra_id, geographic, schematic, data)
SELECT sc_id,
INSERT INTO infra_layer_psl_sign (
obj_id,
infra_id,
geographic,
schematic,
angle_geo,
angle_sch,
data
)
SELECT DISTINCT ON (
ST_LineInterpolatePoint(track_geo, norm_pos),
ST_LineInterpolatePoint(track_sch, norm_pos),
(data->>'type')::text
) collect.sc_id,
$1,
geo,
sch,
data
ST_LineInterpolatePoint(track_geo, norm_pos),
ST_LineInterpolatePoint(track_sch, norm_pos),
COALESCE(
degrees(
ST_Azimuth(
ST_LineInterpolatePoint(track_geo, GREATEST(norm_pos - 0.0001, 0.)),
ST_LineInterpolatePoint(track_geo, LEAST(norm_pos + 0.0001, 1.))
)
) + angle_direction,
0.
),
COALESCE(
degrees(
ST_Azimuth(
ST_LineInterpolatePoint(track_sch, GREATEST(norm_pos - 0.0001, 0.)),
ST_LineInterpolatePoint(track_sch, LEAST(norm_pos + 0.0001, 1.))
)
) + angle_direction,
0.
),
collect.data
FROM collect
1 change: 0 additions & 1 deletion editoast/src/models/infra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use strum::IntoEnumIterator;
use thiserror::Error;
use uuid::Uuid;

pub const RAILJSON_VERSION: &str = "3.4.9";
pub const INFRA_VERSION: &str = "0";

#[derive(
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/schema/railjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
use derivative::Derivative;
use serde::{Deserialize, Serialize};

pub const RAILJSON_VERSION: &str = "3.4.8";
pub const RAILJSON_VERSION: &str = "3.4.9";

#[derive(Deserialize, Derivative, Serialize, Clone, Debug)]
#[derivative(Default)]
Expand Down
2 changes: 2 additions & 0 deletions editoast/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ diesel::table! {
schematic -> Geometry,
data -> Jsonb,
infra_id -> Int8,
angle_geo -> Nullable<Float8>,
angle_sch -> Nullable<Float8>,
}
}

Expand Down
4 changes: 0 additions & 4 deletions editoast/src/views/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ async fn cache_and_get_mvt_tile(

let geo_json_query = get_geo_json_sql_query(&layer.table_name, view);
let mut conn = db_pool.get().await?;
println!("{}", geo_json_query.clone());
println!("{}", z);
println!("{}", x);
println!("{}", y);
let records = sql_query(geo_json_query)
.bind::<Integer, _>(z as i32)
.bind::<Integer, _>(x as i32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const getNewAnnouncementSign = (
const speedInKmH = msToKmh(speedLimit);
const speedMultipleOfFive = Math.ceil(speedInKmH / 5) * 5;
return {
angle_geo: 0,
angle_sch: 0,
angle: 0,
position: firstRange.begin,
side: 'LEFT',
track: firstRange.track,
Expand All @@ -41,8 +40,7 @@ const getNewRSign = (
) => {
const lastRange = trackRanges[trackRanges.length - 1];
return {
angle_geo: 0,
angle_sch: 0,
angle: 0,
position: lastRange.end,
side: 'LEFT',
track: lastRange.track,
Expand Down
Loading

0 comments on commit a7e2358

Please sign in to comment.