mirror of
https://github.com/SyncrowIOT/data.git
synced 2025-08-25 14:29:41 +00:00
divide by 100 to convert to Kwh
This commit is contained in:
@ -1,22 +1,22 @@
|
|||||||
-- model shows the energy consumed per day per device
|
-- model shows the energy consumed per day per device
|
||||||
|
|
||||||
WITH total_energy AS (
|
WITH total_energy AS (--/100 to get value in kWh
|
||||||
SELECT
|
SELECT
|
||||||
device_id,
|
device_id,
|
||||||
event_time::date AS date,
|
event_time::date AS date,
|
||||||
MIN(value)::integer AS min_value,
|
MIN(value)::integer/100 AS min_value,
|
||||||
MAX(value)::integer AS max_value
|
MAX(value)::integer/100 AS max_value
|
||||||
FROM "device-status-log"
|
FROM "device-status-log"
|
||||||
where code='EnergyConsumed'
|
where code='EnergyConsumed'
|
||||||
GROUP BY device_id, date
|
GROUP BY device_id, date
|
||||||
)
|
)
|
||||||
|
|
||||||
, energy_phase_A AS (
|
, energy_phase_A AS ( --in
|
||||||
SELECT
|
SELECT
|
||||||
device_id,
|
device_id,
|
||||||
event_time::date AS date,
|
event_time::date AS date,
|
||||||
MIN(value)::integer AS min_value,
|
MIN(value)::integer/100 AS min_value,
|
||||||
MAX(value)::integer AS max_value
|
MAX(value)::integer/100 AS max_value
|
||||||
FROM "device-status-log"
|
FROM "device-status-log"
|
||||||
where code='EnergyConsumedA'
|
where code='EnergyConsumedA'
|
||||||
GROUP BY device_id, date
|
GROUP BY device_id, date
|
||||||
@ -26,8 +26,8 @@ WITH total_energy AS (
|
|||||||
SELECT
|
SELECT
|
||||||
device_id,
|
device_id,
|
||||||
event_time::date AS date,
|
event_time::date AS date,
|
||||||
MIN(value)::integer AS min_value,
|
MIN(value)::integer/100 AS min_value,
|
||||||
MAX(value)::integer AS max_value
|
MAX(value)::integer/100 AS max_value
|
||||||
FROM "device-status-log"
|
FROM "device-status-log"
|
||||||
where code='EnergyConsumedB'
|
where code='EnergyConsumedB'
|
||||||
GROUP BY device_id, date
|
GROUP BY device_id, date
|
||||||
@ -37,8 +37,8 @@ WITH total_energy AS (
|
|||||||
SELECT
|
SELECT
|
||||||
device_id,
|
device_id,
|
||||||
event_time::date AS date,
|
event_time::date AS date,
|
||||||
MIN(value)::integer AS min_value,
|
MIN(value)::integer/100 AS min_value,
|
||||||
MAX(value)::integer AS max_value
|
MAX(value)::integer/100 AS max_value
|
||||||
FROM "device-status-log"
|
FROM "device-status-log"
|
||||||
where code='EnergyConsumedC'
|
where code='EnergyConsumedC'
|
||||||
GROUP BY device_id, date
|
GROUP BY device_id, date
|
||||||
@ -62,7 +62,3 @@ JOIN energy_phase_B
|
|||||||
JOIN energy_phase_C
|
JOIN energy_phase_C
|
||||||
ON total_energy.device_id=energy_phase_C.device_id
|
ON total_energy.device_id=energy_phase_C.device_id
|
||||||
and total_energy.date=energy_phase_C.date;
|
and total_energy.date=energy_phase_C.date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user