This commit is contained in:
Dona Maria Absi
2025-03-06 21:52:14 +03:00
parent 58228978a3
commit 8b276e9816
6 changed files with 94 additions and 4 deletions
@@ -95,4 +95,4 @@ LEFT JOIN daily_empty_duration d
ON a.space_id = d.space_id
AND a.occupancy_date = d.occupancy_date
join "space" s
on s."uuid" =a.space_id;
on s."uuid" =a.space_id
@@ -0,0 +1,27 @@
SELECT
device.uuid AS device_id,
device.space_device_uuid AS space_id,
-- Mark none_flag if value is 'none'
CASE
WHEN "device-status-log".value = 'none' THEN 1
ELSE 0
END AS none_flag,
"device-status-log".event_time::timestamp AS event_time,
LAG("device-status-log".event_time::timestamp)
OVER (PARTITION BY device.uuid
ORDER BY "device-status-log".event_time) AS prev_timestamp,
LAG(
CASE
WHEN "device-status-log".value = 'none' THEN 1 -- identifies if there was a 'none' flag detected
ELSE 0
END
) OVER (PARTITION BY device.uuid
ORDER BY "device-status-log".event_time) AS prev_none_flag
FROM device
LEFT JOIN "device-status-log"
ON device.uuid = "device-status-log".device_id
LEFT JOIN product
ON product.uuid = device.product_device_uuid
WHERE product.cat_name = 'hps'
AND "device-status-log".code = 'presence_state'
ORDER BY device.uuid, "device-status-log".event_time