Skip to content

Commit bd8ec45

Browse files
committed
Merge branch 'main' into 24064_update_project_components_and_funding_components_to_sx_prop
2 parents d830e2c + 938b198 commit bd8ec45

33 files changed

Lines changed: 1204 additions & 643 deletions

moped-database/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Architecture Independent Docker Stack Components for Moped Development Environment
22
services:
33
hasura:
4-
image: hasura/graphql-engine:v2.48.4
4+
image: hasura/graphql-engine:v2.48.5
55
depends_on:
66
- moped-pgsql
77
expose:

moped-database/metadata/databases/default/tables/public_component_arcgis_online_view.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ select_permissions:
55
- role: moped-admin
66
permission:
77
columns:
8-
- component_categories
98
- component_description
109
- component_id
1110
- component_location_description
@@ -44,6 +43,7 @@ select_permissions:
4443
- parent_project_url
4544
- project_added_by
4645
- project_component_id
46+
- project_created_at
4747
- project_description
4848
- project_designer
4949
- project_development_status
@@ -86,7 +86,6 @@ select_permissions:
8686
- role: moped-editor
8787
permission:
8888
columns:
89-
- component_categories
9089
- component_description
9190
- component_id
9291
- component_location_description
@@ -125,6 +124,7 @@ select_permissions:
125124
- parent_project_url
126125
- project_added_by
127126
- project_component_id
127+
- project_created_at
128128
- project_description
129129
- project_designer
130130
- project_development_status
@@ -167,7 +167,6 @@ select_permissions:
167167
- role: moped-viewer
168168
permission:
169169
columns:
170-
- component_categories
171170
- component_description
172171
- component_id
173172
- component_location_description
@@ -206,6 +205,7 @@ select_permissions:
206205
- parent_project_url
207206
- project_added_by
208207
- project_component_id
208+
- project_created_at
209209
- project_description
210210
- project_designer
211211
- project_development_status
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
DROP VIEW IF EXISTS exploded_component_arcgis_online_view;
2+
DROP VIEW IF EXISTS component_arcgis_online_view;
3+
4+
CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS (
5+
SELECT
6+
mpcwt.project_component_id,
7+
string_agg(mwt.name, ', '::text) AS work_types
8+
FROM moped_proj_component_work_types mpcwt
9+
LEFT JOIN moped_work_types mwt ON mpcwt.work_type_id = mwt.id
10+
WHERE mpcwt.is_deleted = false
11+
GROUP BY mpcwt.project_component_id
12+
),
13+
14+
council_districts AS (
15+
SELECT
16+
features.component_id AS project_component_id,
17+
string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts,
18+
string_agg(DISTINCT lpad(features_council_districts.council_district_id::text, 2, '0'::text), ', '::text) AS council_districts_searchable
19+
FROM features_council_districts
20+
LEFT JOIN features ON features_council_districts.feature_id = features.id
21+
WHERE features.is_deleted = false
22+
GROUP BY features.component_id
23+
),
24+
25+
comp_geography AS (
26+
SELECT
27+
feature_union.component_id AS project_component_id,
28+
string_agg(DISTINCT feature_union.id::text, ', '::text) AS feature_ids,
29+
st_asgeojson(st_multi(st_union(array_agg(feature_union.geography))))::json AS geometry,
30+
st_asgeojson(st_multi(st_union(array_agg(feature_union.line_geography))))::json AS line_geometry,
31+
string_agg(DISTINCT feature_union.signal_id::text, ', '::text) AS signal_ids,
32+
sum(feature_union.length_feet) AS length_feet_total
33+
FROM (
34+
SELECT
35+
feature_signals.id,
36+
feature_signals.component_id,
37+
feature_signals.geography::geometry AS geography,
38+
st_exteriorring(st_buffer(feature_signals.geography, 7::double precision)::geometry) AS line_geography,
39+
feature_signals.signal_id,
40+
null::integer AS length_feet
41+
FROM feature_signals
42+
WHERE feature_signals.is_deleted = false
43+
UNION ALL
44+
SELECT
45+
feature_street_segments.id,
46+
feature_street_segments.component_id,
47+
feature_street_segments.geography::geometry AS geography,
48+
feature_street_segments.geography::geometry AS line_geography,
49+
null::integer AS signal_id,
50+
feature_street_segments.length_feet
51+
FROM feature_street_segments
52+
WHERE feature_street_segments.is_deleted = false
53+
UNION ALL
54+
SELECT
55+
feature_intersections.id,
56+
feature_intersections.component_id,
57+
feature_intersections.geography::geometry AS geography,
58+
st_exteriorring(st_buffer(feature_intersections.geography, 7::double precision)::geometry) AS line_geography,
59+
null::integer AS signal_id,
60+
null::integer AS length_feet
61+
FROM feature_intersections
62+
WHERE feature_intersections.is_deleted = false
63+
UNION ALL
64+
SELECT
65+
feature_drawn_points.id,
66+
feature_drawn_points.component_id,
67+
feature_drawn_points.geography::geometry AS geography,
68+
st_exteriorring(st_buffer(feature_drawn_points.geography, 7::double precision)::geometry) AS line_geography,
69+
null::integer AS signal_id,
70+
null::integer AS length_feet
71+
FROM feature_drawn_points
72+
WHERE feature_drawn_points.is_deleted = false
73+
UNION ALL
74+
SELECT
75+
feature_drawn_lines.id,
76+
feature_drawn_lines.component_id,
77+
feature_drawn_lines.geography::geometry AS geography,
78+
feature_drawn_lines.geography::geometry AS line_geography,
79+
null::integer AS signal_id,
80+
feature_drawn_lines.length_feet
81+
FROM feature_drawn_lines
82+
WHERE feature_drawn_lines.is_deleted = false
83+
UNION ALL
84+
SELECT
85+
feature_school_beacons.id,
86+
feature_school_beacons.component_id,
87+
feature_school_beacons.geography::geometry AS geography,
88+
st_exteriorring(st_buffer(feature_school_beacons.geography, 7::double precision)::geometry) AS line_geography,
89+
null::integer AS signal_id,
90+
null::integer AS length_feet
91+
FROM feature_school_beacons
92+
WHERE feature_school_beacons.is_deleted = false
93+
) feature_union
94+
GROUP BY feature_union.component_id
95+
),
96+
97+
subcomponents AS (
98+
SELECT
99+
mpcs.project_component_id,
100+
string_agg(ms.subcomponent_name, ', '::text) AS subcomponents
101+
FROM moped_proj_components_subcomponents mpcs
102+
LEFT JOIN moped_subcomponents ms ON mpcs.subcomponent_id = ms.subcomponent_id
103+
WHERE mpcs.is_deleted = false
104+
GROUP BY mpcs.project_component_id
105+
),
106+
107+
component_tags AS (
108+
SELECT
109+
mpct.project_component_id,
110+
string_agg(mct.full_name, ', '::text) AS component_tags
111+
FROM moped_proj_component_tags mpct
112+
LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id
113+
WHERE mpct.is_deleted = false
114+
GROUP BY mpct.project_component_id
115+
),
116+
117+
related_projects AS (
118+
SELECT
119+
pmp.project_id,
120+
concat_ws(', '::text, pmp.project_id, string_agg(cmp.project_id::text, ', '::text)) AS related_project_ids_with_self,
121+
concat_ws(', '::text, lpad(pmp.project_id::text, 5, '0'::text), string_agg(lpad(cmp.project_id::text, 5, '0'::text), ', '::text)) AS related_project_ids_searchable_with_self
122+
FROM moped_project pmp
123+
LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id
124+
WHERE cmp.is_deleted = false
125+
GROUP BY pmp.project_id
126+
),
127+
128+
latest_public_meeting_date AS (
129+
SELECT
130+
mpm.project_id,
131+
coalesce(max(mpm.date_actual), max(mpm.date_estimate)) AS latest
132+
FROM moped_proj_milestones mpm
133+
WHERE mpm.milestone_id = 65 AND mpm.is_deleted = false
134+
GROUP BY mpm.project_id
135+
),
136+
137+
earliest_active_or_construction_phase_date AS (
138+
SELECT
139+
mpp.project_id,
140+
min(mpp.phase_start) AS earliest
141+
FROM moped_proj_phases mpp
142+
LEFT JOIN moped_phases mp ON mpp.phase_id = mp.phase_id
143+
WHERE (mp.phase_name_simple = any(ARRAY['Active'::text, 'Construction'::text])) AND mpp.is_deleted = false
144+
GROUP BY mpp.project_id
145+
)
146+
147+
SELECT
148+
mpc.project_id,
149+
mpc.project_component_id,
150+
comp_geography.feature_ids,
151+
mpc.component_id,
152+
comp_geography.geometry,
153+
comp_geography.line_geometry,
154+
comp_geography.signal_ids,
155+
council_districts.council_districts,
156+
council_districts.council_districts_searchable,
157+
NOT coalesce(council_districts.council_districts IS null OR council_districts.council_districts = ''::text, false) AS is_within_city_limits,
158+
comp_geography.length_feet_total,
159+
round(comp_geography.length_feet_total::numeric / 5280::numeric, 2) AS length_miles_total,
160+
mc.component_name,
161+
mc.component_subtype,
162+
mc.component_name_full,
163+
'placeholder text'::text AS component_categories,
164+
CASE
165+
WHEN mc.line_representation = true THEN 'Line'::text
166+
ELSE 'Point'::text
167+
END AS geometry_type,
168+
CASE
169+
WHEN comp_geography.geometry IS null THEN false
170+
ELSE true
171+
END AS is_mapped,
172+
subcomponents.subcomponents AS component_subcomponents,
173+
work_types.work_types AS component_work_types,
174+
component_tags.component_tags,
175+
mpc.description AS component_description,
176+
mpc.interim_project_component_id,
177+
CASE
178+
WHEN mpc.phase_id IS null THEN plv.substantial_completion_date
179+
WHEN mpc.phase_id IS NOT null AND mpc.completion_date IS null THEN null::timestamp with time zone
180+
ELSE mpc.completion_date
181+
END AS substantial_completion_date,
182+
plv.substantial_completion_date_estimated,
183+
mpc.srts_id,
184+
mpc.location_description AS component_location_description,
185+
plv.project_name,
186+
plv.project_name_secondary,
187+
plv.project_name_full,
188+
plv.project_description,
189+
plv.ecapris_subproject_id,
190+
plv.project_website,
191+
plv.updated_at AS project_updated_at,
192+
mpc.phase_id AS component_phase_id,
193+
mph.phase_name AS component_phase_name,
194+
mph.phase_name_simple AS component_phase_name_simple,
195+
current_phase.phase_id AS project_phase_id,
196+
current_phase.phase_name AS project_phase_name,
197+
current_phase.phase_name_simple AS project_phase_name_simple,
198+
coalesce(mph.phase_name, current_phase.phase_name) AS current_phase_name,
199+
coalesce(mph.phase_name_simple, current_phase.phase_name_simple) AS current_phase_name_simple,
200+
plv.project_team_members,
201+
plv.project_sponsor,
202+
plv.project_lead,
203+
plv.public_process_status,
204+
plv.interim_project_id,
205+
plv.project_partners,
206+
plv.task_order_names,
207+
plv.funding_source_and_program_names AS funding_sources,
208+
plv.project_status_update,
209+
plv.project_status_update_date_created,
210+
to_char(timezone('US/Central'::text, plv.construction_start_date), 'YYYY-MM-DD'::text) AS construction_start_date,
211+
plv.project_inspector,
212+
plv.project_designer,
213+
plv.project_tags,
214+
plv.workgroup_contractors,
215+
plv.contract_numbers,
216+
plv.parent_project_id,
217+
plv.parent_project_name,
218+
plv.parent_project_url,
219+
plv.parent_project_name AS parent_project_name_full,
220+
rp.related_project_ids_with_self AS related_project_ids,
221+
rp.related_project_ids_searchable_with_self AS related_project_ids_searchable,
222+
plv.knack_project_id AS knack_data_tracker_project_record_id,
223+
plv.project_url,
224+
(plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url,
225+
get_project_development_status(lpmd.latest::timestamp with time zone, eaocpd.earliest, coalesce(mpc.completion_date, plv.substantial_completion_date), plv.substantial_completion_date_estimated, coalesce(mph.phase_name_simple, current_phase.phase_name_simple)) AS project_development_status,
226+
project_development_status_date.result AS project_development_status_date,
227+
to_char(project_development_status_date.result, 'YYYY'::text)::integer AS project_development_status_date_calendar_year,
228+
to_char(project_development_status_date.result, 'FMMonth YYYY'::text) AS project_development_status_date_calendar_year_month,
229+
to_char(project_development_status_date.result, 'YYYY-MM'::text) AS project_development_status_date_calendar_year_month_numeric,
230+
date_part('quarter'::text, project_development_status_date.result)::text AS project_development_status_date_calendar_year_quarter,
231+
CASE
232+
WHEN date_part('quarter'::text, project_development_status_date.result) = 4::double precision THEN (to_char(project_development_status_date.result, 'YYYY'::text)::integer + 1)::text
233+
ELSE to_char(project_development_status_date.result, 'YYYY'::text)
234+
END AS project_development_status_date_fiscal_year,
235+
CASE
236+
WHEN date_part('quarter'::text, project_development_status_date.result) = 4::double precision THEN 1::double precision
237+
ELSE date_part('quarter'::text, project_development_status_date.result) + 1::double precision
238+
END::text AS project_development_status_date_fiscal_year_quarter,
239+
plv.added_by AS project_added_by
240+
FROM moped_proj_components mpc
241+
LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id
242+
LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id
243+
LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id
244+
LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id
245+
LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id
246+
LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id
247+
LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id
248+
LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id
249+
LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id
250+
LEFT JOIN related_projects rp ON mpc.project_id = rp.project_id
251+
LEFT JOIN latest_public_meeting_date lpmd ON mpc.project_id = lpmd.project_id
252+
LEFT JOIN earliest_active_or_construction_phase_date eaocpd ON mpc.project_id = eaocpd.project_id
253+
LEFT JOIN LATERAL (SELECT timezone('US/Central'::text, get_project_development_status_date(lpmd.latest::timestamp with time zone, eaocpd.earliest, coalesce(mpc.completion_date, plv.substantial_completion_date), plv.substantial_completion_date_estimated, coalesce(mph.phase_name_simple, current_phase.phase_name_simple))) AS result) project_development_status_date ON true
254+
WHERE mpc.is_deleted = false AND plv.is_deleted = false;
255+
256+
CREATE OR REPLACE VIEW exploded_component_arcgis_online_view AS SELECT
257+
component_arcgis_online_view.project_id,
258+
component_arcgis_online_view.project_component_id,
259+
st_geometrytype(dump.geom) AS geometry_type,
260+
dump.path[1] AS point_index,
261+
component_arcgis_online_view.geometry AS original_geometry,
262+
st_asgeojson(dump.geom) AS exploded_geometry,
263+
component_arcgis_online_view.project_updated_at
264+
FROM component_arcgis_online_view,
265+
LATERAL st_dump(st_geomfromgeojson(component_arcgis_online_view.geometry)) dump (path, geom)
266+
WHERE st_geometrytype(st_geomfromgeojson(component_arcgis_online_view.geometry)) = 'ST_MultiPoint'::text;

0 commit comments

Comments
 (0)