energy consumed

This commit is contained in:
Dona Maria Absi
2025-03-18 15:17:03 +03:00
parent c231b000ce
commit 992fe20d4f
3 changed files with 68 additions and 20 deletions
@@ -51,23 +51,21 @@ WITH start_date AS (
AND a.device_id <> b.device_id
AND a.start_time < b.end_time
AND b.start_time < a.end_time
)
)
, daily_total_occupancy AS (
SELECT
start_date.space_id,
dim_date.daily_date,
t.space_id,
DATE(t.start_time) AS occupancy_date,
86,400 - COALESCE(SUM(o.overlap_duration_seconds), 0) AS total_occupancy_seconds
FROM dim_date
FROM time_intervals t
LEFT JOIN overlaping_none_presence o
--ON t.space_id = o.space_id
ON dim_date.daily_date = o.overlap_start::date
--AND t.start_time < o.overlap_end
-- AND o.overlap_start < t.end_time
left join start_date
on start_date.space_id = o.space_id
GROUP BY 1,2
ON t.space_id = o.space_id
AND t.start_time < o.overlap_end
AND o.overlap_start < t.end_time
GROUP BY t.space_id, DATE(t.start_time)
)
SELECT * FROM daily_total_occupancy
SELECT * FROM daily_total_occupancy