Skip to content

Commit

Permalink
Redirected the realtime hourly queue update to the new table
Browse files Browse the repository at this point in the history
  • Loading branch information
caparker committed Nov 12, 2024
1 parent 0016d3d commit 37ba617
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions ingest/fetch_ingest_full.sql
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,31 @@ SET datetime_last = GREATEST(sensors_rollup.datetime_last, EXCLUDED.datetime_las


-- Update the table that will help to track hourly rollups
INSERT INTO hourly_stats (datetime)
SELECT date_trunc('hour', datetime)
FROM temp_inserted_measurements
GROUP BY 1
ON CONFLICT (datetime) DO UPDATE
SET modified_on = now();
--INSERT INTO hourly_stats (datetime)
-- SELECT date_trunc('hour', datetime)
-- FROM temp_inserted_measurements
-- GROUP BY 1
--ON CONFLICT (datetime) DO UPDATE
--SET modified_on = now();

WITH inserted_hours AS (
-- first we group things, adding an hour to make it time-ending after truncating
SELECT datetime + '1h'::interval as datetime
, utc_offset(datetime + '1h'::interval, tz.tzid) as tz_offset
FROM temp_inserted_measurements m
JOIN sensors s ON (s.sensors_id = m.sensors_id)
JOIN sensor_systems sy ON (s.sensor_systems_id = sy.sensor_systems_id)
JOIN sensor_nodes sn ON (sy.sensor_nodes_id = sn.sensor_nodes_id)
JOIN timezones tz ON (sn.timezones_id = tz.timezones_id)
GROUP BY 1, 2
)
INSERT INTO hourly_data_queue (datetime, tz_offset)
SELECT as_utc_hour(datetime, tz_offset), tz_offset
FROM inserted_hours
GROUP BY 1, 2
ON CONFLICT (datetime, tz_offset) DO UPDATE
SET modified_on = now();


-- update the table that will track the daily exports
WITH e AS (
Expand Down

0 comments on commit 37ba617

Please sign in to comment.