-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathathena.sql
More file actions
59 lines (59 loc) · 1.18 KB
/
athena.sql
File metadata and controls
59 lines (59 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
with room_state as (
SELECT
System.UnixTime as timestamp,
room_struct.CalculatedTemperature as Temperature,
room_struct.CurrentSetPoint as TargetTemperature,
room_struct.PercentageDemand as PercentageDemand,
'room=' || room_struct.Name as room_tag
FROM "your-db"."your-table"
CROSS JOIN UNNEST(room) as t(room_struct)
)
SELECT metric, timestamp, AVG(value) as value, room_tag FROM
(
(
SELECT
'BoilerState' as metric,
System.UnixTime as timestamp,
case when heatingchannel[1].HeatingRelayState = 'On' then 1 else 0 end as value,
'boiler=1' as room_tag
FROM "your-db"."your-table"
)
UNION
(
SELECT
'Humidity' as metric,
System.UnixTime as timestamp,
roomstat[1].MeasuredHumidity as value,
'room=Hallway' as room_tag
FROM "your-db"."your-table"
)
UNION
(
SELECT
'Temperature' as metric,
timestamp,
Temperature as value,
room_tag
from room_state
)
UNION
(
SELECT
'TargetTemperature' as metric,
timestamp,
TargetTemperature as value,
room_tag
from room_state
)
UNION
(
SELECT
'PercentageDemand' as metric,
timestamp,
PercentageDemand as value,
room_tag
from room_state
)
)
GROUP BY metric, timestamp, room_tag
ORDER BY timestamp asc