-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1018 commit mysteriously missing views
- Loading branch information
1 parent
a9d35ce
commit 50cd40b
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
volumes/ecocounter/views/create-view-ecocounter_status_dashboard.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--DROP VIEW ecocounter.eco_status_dashboard IF EXISTS; | ||
|
||
CREATE OR REPLACE VIEW ecocounter.eco_status_dashboard AS | ||
SELECT | ||
e.site_id::text AS unique_id, | ||
'Eco-Counter'::text AS device_family, | ||
'Inductive'::text AS det_tech, | ||
CASE | ||
WHEN last_active >= now()::date - interval '2 day' THEN 'Online'::text | ||
WHEN last_active >= now()::date - interval '14 day' THEN 'Not Reporting'::text | ||
WHEN date_decommissioned IS NOT NULL THEN 'Decommissioned'::text | ||
--anomalous_range = malfunctioning | ||
WHEN last_active < now()::date - interval '14 day' THEN 'Offline'::text | ||
ELSE 'Unknown'::text | ||
END AS status, | ||
e.site_description AS location_name, | ||
e.geom, | ||
e.first_active::date AS date_installed, | ||
e.last_active::date AS last_active, | ||
e.centreline_id | ||
FROM ecocounter.sites e | ||
ORDER BY e.site_id; | ||
|
||
ALTER TABLE ecocounter.eco_status_dashboard OWNER TO ckousin; | ||
GRANT SELECT ON TABLE ecocounter.eco_status_dashboard TO bdit_humans; | ||
GRANT ALL ON TABLE ecocounter.eco_status_dashboard TO ckousin; |
61 changes: 61 additions & 0 deletions
61
volumes/miovision/sql/views/create-view-miovision_status_dashboard.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
CREATE OR REPLACE VIEW miovision_api.mio_dashboard_data AS | ||
|
||
WITH open_alerts AS ( | ||
SELECT | ||
intersection_uid, | ||
string_agg(DISTINCT alert, ', ') AS alerts | ||
FROM miovision_api.alerts | ||
WHERE end_time IS NULL | ||
GROUP BY intersection_uid | ||
), | ||
|
||
open_anomalous_ranges AS ( | ||
SELECT | ||
intersection_uid, | ||
string_agg(uid::text, ', ') AS uids | ||
FROM miovision_api.anomalous_ranges | ||
WHERE | ||
problem_level <> 'valid-caveat'::text | ||
AND ( | ||
range_end IS NULL | ||
OR ( | ||
notes ~~ '%identified by a daily airflow process%'::text | ||
AND range_end = (now() AT TIME ZONE 'Canada/Eastern'::text)::date | ||
) | ||
) | ||
GROUP BY intersection_uid | ||
), | ||
|
||
last_active AS ( | ||
SELECT | ||
intersection_uid, | ||
MAX(dt) AS max_dt | ||
FROM miovision_api.volumes_daily_unfiltered | ||
GROUP BY intersection_uid | ||
) | ||
|
||
SELECT | ||
i.id AS unique_id, | ||
'Miovision'::text AS device_family, | ||
CASE | ||
WHEN last_active.max_dt < (now() AT TIME ZONE 'Canada/Eastern'::text - interval '14 days')::date THEN 'Offline' | ||
WHEN open_alerts.alerts IS NOT NULL OR open_anomalous_ranges.uids IS NOT NULL THEN 'Malfunctioning' | ||
WHEN last_active.max_dt = (now() AT TIME ZONE 'Canada/Eastern'::text - interval '1 day')::date THEN 'Online' | ||
WHEN i.date_decommissioned IS NOT NULL THEN 'Decommissioned' | ||
END AS status, | ||
i.api_name AS location_name, | ||
i.geom, | ||
'Video' AS det_tech, | ||
i.date_installed, | ||
COALESCE(last_active.max_dt, date_decommissioned) AS last_active, | ||
i.px, | ||
i.int_id | ||
FROM miovision_api.intersections AS i | ||
LEFT JOIN open_anomalous_ranges USING (intersection_uid) | ||
LEFT JOIN open_alerts USING (intersection_uid) | ||
LEFT JOIN last_active USING (intersection_uid); | ||
|
||
ALTER TABLE miovision_api.mio_dashboard_data OWNER TO ckousin; | ||
GRANT ALL ON TABLE miovision_api.mio_dashboard_data TO ckousin; | ||
|
||
GRANT SELECT ON TABLE miovision_api.mio_dashboard_data TO bdit_humans; |
42 changes: 42 additions & 0 deletions
42
volumes/vds/sql/views/create-view-vds_status_dashboard.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
DROP VIEW ckousin.vds_dashboard_data; | ||
CREATE OR REPLACE VIEW ckousin.vds_dashboard_data AS | ||
|
||
WITH last_active AS ( | ||
SELECT | ||
detector_id, | ||
MIN(first_active) AS first_active, | ||
MAX(last_active) AS last_active | ||
FROM vds.detector_inventory | ||
WHERE division_id = 2 | ||
GROUP BY detector_id | ||
) | ||
|
||
SELECT DISTINCT ON (detector_id) | ||
di.detector_id AS unique_id, | ||
di.det_type AS device_family, | ||
CASE | ||
WHEN di.det_type = 'Blue City AI' THEN 'LIDAR' | ||
WHEN di.det_type = 'Smartmicro Sensors' OR det_tech = 'Wavetronix' THEN 'Radar' | ||
ELSE COALESCE(di.det_tech, di.det_type) END AS det_tech, | ||
CASE | ||
WHEN la.last_active >= now()::date - interval '2 day' THEN 'Online'::text | ||
WHEN la.last_active >= now()::date - interval '14 day' THEN 'Not Reporting'::text | ||
--decommissioned? from chris's list? | ||
WHEN la.last_active < now()::date - interval '14 day' THEN 'Offline'::text | ||
ELSE 'Unknown'::text | ||
END AS status, | ||
di.detector_loc AS location_name, | ||
di.sensor_geom AS geom, | ||
di.centreline_id, | ||
la.first_active::date AS date_installed, | ||
la.last_active::date, | ||
null::date AS date_decommissioned | ||
FROM vds.detector_inventory AS di | ||
JOIN last_active AS la USING (detector_id) | ||
WHERE di.division_id = 2 | ||
ORDER BY di.detector_id, la.last_active DESC; | ||
|
||
ALTER TABLE ckousin.vds_dashboard_data OWNER TO ckousin; | ||
|
||
GRANT SELECT ON TABLE ckousin.vds_dashboard_data TO bdit_humans; | ||
GRANT ALL ON TABLE ckousin.vds_dashboard_data TO ckousin; |