From ba0ab2655f25b7de4ae54f70a0327663af3d2ece Mon Sep 17 00:00:00 2001 From: gabrielwol <80077912+gabrielwol@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:35:41 -0500 Subject: [PATCH] #868 update function-find_gaps.sql remove 15 minute buffer + change to adding artificial point at each day --- .../sql/function/function-find_gaps.sql | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/volumes/miovision/sql/function/function-find_gaps.sql b/volumes/miovision/sql/function/function-find_gaps.sql index 0b3a96d24..c13f434a2 100644 --- a/volumes/miovision/sql/function/function-find_gaps.sql +++ b/volumes/miovision/sql/function/function-find_gaps.sql @@ -2,6 +2,10 @@ -- miovision_api.unacceptable_gaps table. gap_tolerance set using 60 day -- lookback avg volumes and thresholds defined in gapsize_lookup. +--when run in 1 day increments (as in daily airflow), this function +--will miss small gaps that overlap midnight, but that are deemed +--OK when looking only at data before midnight. + CREATE OR REPLACE FUNCTION miovision_api.find_gaps( start_date timestamp, end_date timestamp, @@ -58,12 +62,12 @@ BEGIN bins.datetime_bin, interval '0 minutes' AS gap_adjustment --don't need to reduce gap width for artificial data FROM daily_intersections AS i - --add artificial data points at start and end of each day to find gaps overlapping start/end. - CROSS JOIN LATERAL ( - VALUES - --catch gaps overlapping days - (i.dt - interval '15 minutes'), - (i.dt + interval '1 day') + --add artificial data points at start and end of each day to make + --gaps not overlap multiple days (exception: multi full-day outage). + CROSS JOIN generate_series( + i.dt, + i.dt + interval '1 day', + interval '1 day' ) AS bins(datetime_bin) --group by in next step takes care of duplicates @@ -78,7 +82,7 @@ BEGIN interval '1 minute' AS gap_adjustment FROM miovision_api.volumes WHERE - datetime_bin >= start_date - interval '15 minutes' + datetime_bin >= start_date AND datetime_bin < end_date AND intersection_uid = ANY(target_intersections) ), @@ -130,8 +134,7 @@ BEGIN FROM bin_times AS bt --match gaps to the 15 minute bins they intersect JOIN generate_series( - --catch gaps overlapping days - start_date - interval '15 minutes', + start_date, end_date, interval '15 minutes' ) AS bins(datetime_bin) ON @@ -188,4 +191,4 @@ ALTER FUNCTION miovision_api.find_gaps(timestamp, timestamp, integer []) OWNER TO miovision_admins; GRANT EXECUTE ON FUNCTION miovision_api.find_gaps(timestamp, timestamp, integer []) -TO miovision_api_bot; \ No newline at end of file +TO miovision_api_bot;