Skip to content

Commit

Permalink
#1007 merge open_issues changes from #950 + change to new alerts table
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielwol committed Jul 5, 2024
1 parent 5b9148d commit ba5b8d9
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions volumes/miovision/sql/views/create-view-open_issues.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
--DROP VIEW miovision_api.open_issues;
CREATE OR REPLACE VIEW miovision_api.open_issues AS

WITH alerts AS (
SELECT
ar.uid,
string_agg(DISTINCT alerts.alert, '; ') AS alerts
FROM miovision_api.anomalous_ranges AS ar
LEFT JOIN miovision_api.alerts_new AS alerts
ON alerts.intersection_uid = ar.intersection_uid
AND alerts.start_time >= ar.range_start
AND (
alerts.end_time < ar.range_end
OR ar.range_end IS NULL
)
GROUP BY ar.uid
)

SELECT
ar.uid,
ar.intersection_uid,
Expand All @@ -13,11 +28,12 @@ SELECT
WHEN ar.classification_uid IS NULL THEN 'All modes'
ELSE c.classification
END,
ar.leg,
ar.range_start::date,
(current_timestamp AT TIME ZONE 'EST5EDT')::date - ar.range_start::date AS num_days,
ar.notes,
SUM(v.volume) AS last_week_volume,
string_agg(DISTINCT alerts.alert, '; ') AS alerts
alerts.alerts
FROM miovision_api.anomalous_ranges AS ar
--keep rows with null classification_uid
LEFT JOIN miovision_api.classifications AS c USING (classification_uid)
Expand All @@ -26,18 +42,19 @@ JOIN miovision_api.intersections AS i USING (intersection_uid)
--find last week volume
LEFT JOIN miovision_api.volumes AS v
ON ar.intersection_uid = v.intersection_uid
--volume within the last 7 days and after AR started
AND v.datetime_bin >= ar.range_start
--prune the partitions
AND v.datetime_bin >= current_date - interval '7 days'
AND (
ar.classification_uid = v.classification_uid
OR ar.classification_uid IS NULL
)
LEFT JOIN miovision_api.alerts
ON alerts.intersection_id = i.id
AND alerts.start_time >= ar.range_start
AND (
alerts.end_time < ar.range_end
OR ar.range_end IS NULL
ar.leg = v.leg
OR ar.leg IS NULL
)
LEFT JOIN alerts ON alerts.uid = ar.uid
WHERE
ar.problem_level <> 'valid-caveat'
--currently active
Expand All @@ -56,7 +73,8 @@ GROUP BY
ar.classification_uid,
c.classification,
ar.range_start,
ar.notes
ar.notes,
alerts.alerts
ORDER BY
ar.intersection_uid,
ar.range_start,
Expand Down

0 comments on commit ba5b8d9

Please sign in to comment.