Skip to content

Commit

Permalink
#862 make alter statements specific to params
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielwol committed Feb 8, 2024
1 parent c8cc0e7 commit bce252a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BEGIN

WITH deleted AS (
DELETE FROM miovision_api.volumes_daily_unfiltered
WHERE
WHERE
dt >= start_date
AND dt < end_date
AND intersection_uid = ANY(target_intersections)
Expand Down Expand Up @@ -107,13 +107,15 @@ BEGIN
END;
$BODY$;

COMMENT ON FUNCTION miovision_api.aggregate_volumes_daily
COMMENT ON FUNCTION miovision_api.aggregate_volumes_daily(date, date, integer [])
IS 'Function for inserting daily volumes into miovision_api.volumes_daily_unfiltered.
Contains an optional intersection parameter.';

ALTER FUNCTION miovision_api.aggregate_volumes_daily OWNER TO miovision_admins;
ALTER FUNCTION miovision_api.aggregate_volumes_daily(date, date, integer [])
OWNER TO miovision_admins;

GRANT EXECUTE ON FUNCTION miovision_api.aggregate_volumes_daily
GRANT EXECUTE ON FUNCTION miovision_api.aggregate_volumes_daily(date, date, integer [])
TO miovision_api_bot;

REVOKE ALL ON FUNCTION miovision_api.aggregate_volumes_daily FROM public;
REVOKE ALL ON FUNCTION miovision_api.aggregate_volumes_daily(date, date, integer [])
FROM public;
10 changes: 8 additions & 2 deletions volumes/miovision/sql/function/function-find_gaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ BEGIN
END;
$BODY$;

COMMENT ON FUNCTION miovision_api.find_gaps
COMMENT ON FUNCTION miovision_api.find_gaps(timestamp, timestamp, integer [])
IS 'Function to identify gaps in miovision_api.volumes data and insert into
miovision_api.unacceptable_gaps table. gap_tolerance set using 60 day
lookback avg volumes and thresholds defined in miovision_api.gapsize_lookup.
Contains optional intersection parameter.';
Contains optional intersection parameter.';

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;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AS $BODY$
WHERE
dt >= start_date
AND dt < end_date
AND intersection_uid = ANY(intersections);
AND intersection_uid = ANY(gapsize_lookup_insert.intersections);

WITH study_dates AS (
SELECT
Expand Down Expand Up @@ -45,7 +45,7 @@ AS $BODY$
WHERE
v.datetime_bin >= start_date - interval '60 days'
AND v.datetime_bin < end_date
AND v.intersection_uid = ANY(intersections)
AND v.intersection_uid = ANY(gapsize_lookup_insert.intersections)
GROUP BY
dates.dt,
v.intersection_uid,
Expand All @@ -72,7 +72,7 @@ AS $BODY$
UNION SELECT NULL::integer --represents all classifications
) AS classifications
CROSS JOIN generate_series(0, 23, 1) AS hours(hour_bin)
WHERE intersection_uid = ANY(intersections)
WHERE intersection_uid = ANY(gapsize_lookup_insert.intersections)
),

lookback_avgs AS (
Expand Down Expand Up @@ -130,13 +130,13 @@ AS $BODY$
END;
$BODY$;

ALTER FUNCTION miovision_api.gapsize_lookup_insert
ALTER FUNCTION miovision_api.gapsize_lookup_insert(timestamp, timestamp, integer [])
OWNER TO miovision_admins;

GRANT EXECUTE ON FUNCTION miovision_api.gapsize_lookup_insert
GRANT EXECUTE ON FUNCTION miovision_api.gapsize_lookup_insert(timestamp, timestamp, integer [])
TO miovision_api_bot;

COMMENT ON FUNCTION miovision_api.gapsize_lookup_insert
COMMENT ON FUNCTION miovision_api.gapsize_lookup_insert(timestamp, timestamp, integer [])
IS 'Determine the average volumes for each hour/intersection/daytype/classification
based on a 60 day lookback. Uses GROUPING SETS to identify both volume for individual
classifications and total interseciton volumes (classification_uid IS NULL).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ END;

$BODY$;

ALTER FUNCTION miovision_api.identify_zero_counts(date)
ALTER FUNCTION miovision_api.identify_zero_counts(date, integer [])
OWNER TO miovision_admins;

GRANT EXECUTE ON FUNCTION miovision_api.identify_zero_counts(date)
GRANT EXECUTE ON FUNCTION miovision_api.identify_zero_counts(date, integer [])
TO miovision_api_bot;

GRANT EXECUTE ON FUNCTION miovision_api.identify_zero_counts(date)
GRANT EXECUTE ON FUNCTION miovision_api.identify_zero_counts(date, integer [])
TO miovision_admins;

0 comments on commit bce252a

Please sign in to comment.