Skip to content

Commit

Permalink
anchor_point => anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Nov 22, 2023
1 parent 633a1fd commit 07972f5
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 195 deletions.
92 changes: 46 additions & 46 deletions data_model/app/vw_sign_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def vw_sign_symbol(srid: int, pg_service: str = None):
, {frame_columns}
, sign.rank AS sign_rank
, support.id AS support_id
, support.group_by_anchor_point
, support.group_by_anchor
, support.fk_support_type
, support.geometry::geometry(Point,%(SRID)s) AS support_geometry
, COALESCE(vl_official_sign.directional_sign, FALSE) AS directional_sign
Expand Down Expand Up @@ -164,86 +164,86 @@ def vw_sign_symbol(srid: int, pg_service: str = None):
-- recto NOT ordered by anchor point
ordered_recto_signs_not_grouped_by_anchor_point AS (
ordered_recto_signs_not_grouped_by_anchor AS (
SELECT
joined_tables.*
, azimut AS _azimut_rectified
, offset_x AS _azimut_offset_x_rectified
, offset_y AS _azimut_offset_y_rectified
, frame_anchor_point AS _frame_anchor_point_rectified
, frame_anchor AS _frame_anchor_rectified
, false::bool AS _verso
, ROW_NUMBER () OVER ( PARTITION BY support_id, azimut ORDER BY frame_rank, sign_rank ) AS _rank
FROM joined_tables
WHERE hanging_mode != 'VERSO'::signalo_db.sign_hanging AND group_by_anchor_point IS FALSE
WHERE hanging_mode != 'VERSO'::signalo_db.sign_hanging AND group_by_anchor IS FALSE
ORDER BY support_id, azimut, _rank
),
-- recto ordered by anchor point
ordered_recto_signs_grouped_by_anchor_point AS (
ordered_recto_signs_grouped_by_anchor AS (
SELECT
joined_tables.*
, azimut AS _azimut_rectified
, offset_x AS _azimut_offset_x_rectified
, offset_y AS _azimut_offset_y_rectified
, frame_anchor_point AS _frame_anchor_point_rectified
, frame_anchor AS _frame_anchor_rectified
, false::bool AS _verso
, ROW_NUMBER () OVER ( PARTITION BY support_id, azimut, frame_anchor_point ORDER BY frame_rank, sign_rank ) AS _rank
, ROW_NUMBER () OVER ( PARTITION BY support_id, azimut, frame_anchor ORDER BY frame_rank, sign_rank ) AS _rank
FROM joined_tables
WHERE hanging_mode != 'VERSO'::signalo_db.sign_hanging AND group_by_anchor_point IS TRUE
ORDER BY support_id, azimut, frame_anchor_point, _rank
WHERE hanging_mode != 'VERSO'::signalo_db.sign_hanging AND group_by_anchor IS TRUE
ORDER BY support_id, azimut, frame_anchor, _rank
),
-- verso NOT ordered by anchor point (RECTO-VERSO are duplicated)
ordered_verso_signs_not_grouped_by_anchor_point AS (
ordered_verso_signs_not_grouped_by_anchor AS (
SELECT
jt.*
, jt.azimut+180 AS _azimut_rectified
, COALESCE(az.offset_x, 0) AS _azimut_offset_x_rectified
, COALESCE(az.offset_y, 0) AS _azimut_offset_y_rectified
, CASE
WHEN frame_anchor_point = 'LEFT'::signalo_db.anchor_point THEN 'RIGHT'::signalo_db.anchor_point
WHEN frame_anchor_point = 'RIGHT'::signalo_db.anchor_point THEN 'LEFT'::signalo_db.anchor_point
ELSE 'CENTER'::signalo_db.anchor_point
END AS _frame_anchor_point_rectified
WHEN frame_anchor = 'LEFT'::signalo_db.anchor THEN 'RIGHT'::signalo_db.anchor
WHEN frame_anchor = 'RIGHT'::signalo_db.anchor THEN 'LEFT'::signalo_db.anchor
ELSE 'CENTER'::signalo_db.anchor
END AS _frame_anchor_rectified
, true::bool AS _verso
, 1000 + ROW_NUMBER () OVER ( PARTITION BY support_id, jt.azimut ORDER BY frame_rank, sign_rank ) AS _rank
FROM joined_tables jt
LEFT JOIN signalo_db.azimut az ON az.azimut = ((jt.azimut+180) %% 360) AND az.fk_support = support_id
WHERE hanging_mode != 'RECTO'::signalo_db.sign_hanging AND group_by_anchor_point IS FALSE
WHERE hanging_mode != 'RECTO'::signalo_db.sign_hanging AND group_by_anchor IS FALSE
ORDER BY support_id, jt.azimut, _rank
),
-- verso ordered by anchor point (RECTO-VERSO are duplicated)
ordered_verso_signs_grouped_by_anchor_point AS (
ordered_verso_signs_grouped_by_anchor AS (
SELECT
jt.*
, jt.azimut+180 AS _azimut_rectified
, COALESCE(az.offset_x, 0) AS _azimut_offset_x_rectified
, COALESCE(az.offset_y, 0) AS _azimut_offset_y_rectified
, CASE
WHEN frame_anchor_point = 'LEFT'::signalo_db.anchor_point THEN 'RIGHT'::signalo_db.anchor_point
WHEN frame_anchor_point = 'RIGHT'::signalo_db.anchor_point THEN 'LEFT'::signalo_db.anchor_point
ELSE 'CENTER'::signalo_db.anchor_point
END AS _frame_anchor_point_rectified
WHEN frame_anchor = 'LEFT'::signalo_db.anchor THEN 'RIGHT'::signalo_db.anchor
WHEN frame_anchor = 'RIGHT'::signalo_db.anchor THEN 'LEFT'::signalo_db.anchor
ELSE 'CENTER'::signalo_db.anchor
END AS _frame_anchor_rectified
, true::bool AS _verso
, 1000 + ROW_NUMBER () OVER ( PARTITION BY support_id, jt.azimut, frame_anchor_point ORDER BY frame_rank, sign_rank ) AS _rank
, 1000 + ROW_NUMBER () OVER ( PARTITION BY support_id, jt.azimut, frame_anchor ORDER BY frame_rank, sign_rank ) AS _rank
FROM joined_tables jt
LEFT JOIN signalo_db.azimut az ON az.azimut = ((jt.azimut+180) %% 360) AND az.fk_support = support_id
WHERE hanging_mode != 'RECTO'::signalo_db.sign_hanging AND group_by_anchor_point IS TRUE
ORDER BY support_id, jt.azimut, frame_anchor_point, _rank
WHERE hanging_mode != 'RECTO'::signalo_db.sign_hanging AND group_by_anchor IS TRUE
ORDER BY support_id, jt.azimut, frame_anchor, _rank
),
ordered_signs_not_grouped_by_anchor_point AS (
SELECT * FROM ordered_recto_signs_not_grouped_by_anchor_point
ordered_signs_not_grouped_by_anchor AS (
SELECT * FROM ordered_recto_signs_not_grouped_by_anchor
UNION
SELECT * FROM ordered_verso_signs_not_grouped_by_anchor_point
SELECT * FROM ordered_verso_signs_not_grouped_by_anchor
),
ordered_signs_grouped_by_anchor_point AS (
SELECT * FROM ordered_recto_signs_grouped_by_anchor_point
ordered_signs_grouped_by_anchor AS (
SELECT * FROM ordered_recto_signs_grouped_by_anchor
UNION
SELECT * FROM ordered_verso_signs_grouped_by_anchor_point
SELECT * FROM ordered_verso_signs_grouped_by_anchor
),
ordered_shifted_signs_not_grouped_by_anchor_point AS (
ordered_shifted_signs_not_grouped_by_anchor AS (
SELECT
ordered_signs_not_grouped_by_anchor_point.*
ordered_signs_not_grouped_by_anchor.*
, ROW_NUMBER () OVER ( PARTITION BY support_id, _azimut_rectified ORDER BY _rank ) AS _final_rank
, COALESCE(SUM( _symbol_height ) OVER ( PARTITION BY support_id, _azimut_rectified ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING ), 0) AS _symbol_shift
, COALESCE(SUM( _symbol_height ) OVER ( PARTITION BY support_id, _azimut_rectified), 0) AS _group_height
Expand All @@ -253,39 +253,39 @@ def vw_sign_symbol(srid: int, pg_service: str = None):
, NULLIF(FIRST_VALUE(frame_id) OVER ( PARTITION BY support_id, _azimut_rectified ROWS BETWEEN 1 PRECEDING AND CURRENT ROW ), frame_id) AS _previous_frame
, NULLIF(LAST_VALUE(frame_id) OVER ( PARTITION BY support_id, _azimut_rectified ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING ), frame_id) AS _next_frame
FROM
ordered_signs_not_grouped_by_anchor_point
ordered_signs_not_grouped_by_anchor
),
ordered_shifted_signs_grouped_by_anchor_point AS (
ordered_shifted_signs_grouped_by_anchor AS (
SELECT
ordered_signs_grouped_by_anchor_point.*
, ROW_NUMBER () OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified ORDER BY _rank ) AS _final_rank
, COALESCE(SUM( _symbol_height ) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING ), 0) AS _symbol_shift
, COALESCE(SUM( _symbol_height ) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified), 0) AS _group_height
, MAX(_symbol_width) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified ) AS _group_width
, NULLIF(FIRST_VALUE(id) OVER (PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified, frame_rank ROWS BETWEEN 1 PRECEDING AND CURRENT ROW ), id) AS _previous_sign_in_frame
, NULLIF(LAST_VALUE(id) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified, frame_rank ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING ), id) AS _next_sign_in_frame
, NULLIF(FIRST_VALUE(frame_id) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified ROWS BETWEEN 1 PRECEDING AND CURRENT ROW ), frame_id) AS _previous_frame
, NULLIF(LAST_VALUE(frame_id) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_point_rectified ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING ), frame_id) AS _next_frame
ordered_signs_grouped_by_anchor.*
, ROW_NUMBER () OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified ORDER BY _rank ) AS _final_rank
, COALESCE(SUM( _symbol_height ) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING ), 0) AS _symbol_shift
, COALESCE(SUM( _symbol_height ) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified), 0) AS _group_height
, MAX(_symbol_width) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified ) AS _group_width
, NULLIF(FIRST_VALUE(id) OVER (PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified, frame_rank ROWS BETWEEN 1 PRECEDING AND CURRENT ROW ), id) AS _previous_sign_in_frame
, NULLIF(LAST_VALUE(id) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified, frame_rank ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING ), id) AS _next_sign_in_frame
, NULLIF(FIRST_VALUE(frame_id) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified ROWS BETWEEN 1 PRECEDING AND CURRENT ROW ), frame_id) AS _previous_frame
, NULLIF(LAST_VALUE(frame_id) OVER ( PARTITION BY support_id, _azimut_rectified, _frame_anchor_rectified ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING ), frame_id) AS _next_frame
FROM
ordered_signs_grouped_by_anchor_point
ordered_signs_grouped_by_anchor
),
union_view AS (
SELECT
ossng.*
FROM ordered_shifted_signs_not_grouped_by_anchor_point ossng
FROM ordered_shifted_signs_not_grouped_by_anchor ossng
UNION
SELECT
ossg.*
FROM ordered_shifted_signs_grouped_by_anchor_point ossg
FROM ordered_shifted_signs_grouped_by_anchor ossg
)
SELECT
uv.id || '-' || _verso::int AS pk
, uv.*
, _symbol_height + MAX(_symbol_shift) OVER ( PARTITION BY uv.support_id, azimut, _verso ) AS _max_shift_for_azimut
, CASE
WHEN directional_sign IS TRUE AND (_frame_anchor_point_rectified, natural_direction_or_left) IN (
WHEN directional_sign IS TRUE AND (_frame_anchor_rectified, natural_direction_or_left) IN (
('LEFT', TRUE),
('CENTER', FALSE),
('RIGHT', FALSE)
Expand Down
12 changes: 6 additions & 6 deletions data_model/changelogs/0007/0007_anchor-point.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TYPE signalo_db.anchor_point AS ENUM ('LEFT', 'CENTER', 'RIGHT');
CREATE TYPE signalo_db.anchor AS ENUM ('LEFT', 'CENTER', 'RIGHT');
CREATE TYPE signalo_db.sign_hanging AS ENUM ('RECTO', 'RECTO-VERSO', 'VERSO');

ALTER TABLE signalo_db.support ADD COLUMN group_by_anchor_point BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE signalo_db.frame ADD COLUMN anchor_point signalo_db.anchor_point NOT NULL DEFAULT 'CENTER'::signalo_db.anchor_point;
ALTER TABLE signalo_db.support ADD COLUMN group_by_anchor BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE signalo_db.frame ADD COLUMN anchor signalo_db.anchor NOT NULL DEFAULT 'CENTER'::signalo_db.anchor;
ALTER TABLE signalo_db.azimut ADD COLUMN offset_x INTEGER NOT NULL DEFAULT 0;
ALTER TABLE signalo_db.azimut ADD COLUMN offset_y INTEGER NOT NULL DEFAULT 0;

Expand All @@ -29,15 +29,15 @@ ALTER TABLE signalo_db.vl_official_sign ADD CONSTRAINT directional CHECK (
);

-- adjust frame anchor point based on official sign
UPDATE signalo_db.frame f SET anchor_point = 'LEFT'::signalo_db.anchor_point
UPDATE signalo_db.frame f SET anchor = 'LEFT'::signalo_db.anchor
FROM signalo_db.sign s, signalo_db.vl_official_sign o
WHERE s.fk_frame = f.id AND s.fk_sign_type = 11 AND s.fk_official_sign = o.id AND o.id LIKE '%-r';

UPDATE signalo_db.frame f SET anchor_point = 'RIGHT'::signalo_db.anchor_point
UPDATE signalo_db.frame f SET anchor = 'RIGHT'::signalo_db.anchor
FROM signalo_db.sign s, signalo_db.vl_official_sign o
WHERE s.fk_frame = f.id AND s.fk_sign_type = 11 AND s.fk_official_sign = o.id AND o.id LIKE '%-l';

UPDATE signalo_db.frame f SET anchor_point = 'CENTER'::signalo_db.anchor_point
UPDATE signalo_db.frame f SET anchor = 'CENTER'::signalo_db.anchor
FROM signalo_db.sign s, signalo_db.vl_official_sign o
WHERE s.fk_frame = f.id AND s.fk_sign_type = 11 AND s.fk_official_sign = o.id AND o.id NOT LIKE '%-r' AND o.id NOT LIKE '%-l';

Expand Down
Loading

0 comments on commit 07972f5

Please sign in to comment.