remove all output without DEBUG=1 for cron use
[eg5120] / views.sql
1 drop view s_all;
2 create view s_all as
3 select time AT TIME ZONE 'UTC-2' as time,
4         addr,
5         (json->'sensor_type')::int  as sensor_type,
6         (json->'sensor_name')::text as sensor_name,
7         (json->>'battery')::float as bettery,
8         (json->>'battery_percent')::float as battery_percent,
9         (json->'counter')::int as counter
10 from eg5120
11 ;
12 grant select on s_all to gread ;
13
14 -- 1 Temperature/Humidity
15 drop view s_1;
16 create view s_1 as
17 select time AT TIME ZONE 'UTC-2' as time,
18         addr,
19         (json->'sensor_type')::int  as sensor_type,
20         (json->'sensor_name')::text as sensor_name,
21         (json->'sensor_data'->'temperature')::float as temperature,
22         (json->'sensor_data'->'humidity')::float as humidity,
23         (json->>'battery')::float as bettery,
24         (json->>'battery_percent')::float as battery_percent,
25         (json->'counter')::int as counter
26 from eg5120
27 where sensor_type = 1;
28 ;
29 grant select on s_1 to gread ;
30
31 -- 2 2 Channel Push Notification
32 drop view s_2;
33 create view s_2 as
34 select time AT TIME ZONE 'UTC-2' as time,
35         addr,
36         (json->'sensor_type')::int  as sensor_type,
37         (json->'sensor_name')::text as sensor_name,
38         (json->'sensor_data'->'input_1')::int as input_1,
39         (json->'sensor_data'->'input_2')::int as input_2,
40         (json->>'battery')::float as bettery,
41         (json->>'battery_percent')::float as battery_percent,
42         (json->'counter')::int as counter
43 from eg5120
44 where sensor_type = 2;
45 ;
46 grant select on s_2 to gread ;
47
48 -- 29 Linear Displacement
49 drop view s_29;
50 create view s_29 as
51 select time AT TIME ZONE 'UTC-2' as time,
52         addr,
53         (json->'sensor_type')::int  as sensor_type,
54         (json->'sensor_name')::text as sensor_name,
55         (json->'sensor_data'->'adc')::int as adc,
56         (json->'sensor_data'->'position')::float as position,
57         (json->>'battery')::float as bettery,
58         (json->>'battery_percent')::float as battery_percent,
59         (json->'counter')::int as counter
60 from eg5120
61 where sensor_type = 29;
62 ;
63 grant select on s_29 to gread ;
64
65 -- 30 Structural Monitoring
66 drop view s_30;
67 create view s_30 as
68 select time AT TIME ZONE 'UTC-2' as time,
69         addr,
70         (json->'sensor_type')::int  as sensor_type,
71         (json->'sensor_name')::text as sensor_name,
72         (json->'sensor_data'->'adc')::int as adc,
73         (json->'sensor_data'->'position')::float as position,
74         (json->>'battery')::float as bettery,
75         (json->>'battery_percent')::float as battery_percent,
76         (json->'counter')::int as counter
77 from eg5120
78 where sensor_type = 30;
79 ;
80 grant select on s_30 to gread ;
81
82 -- 47 Wireless Tilt Sensor
83 drop view s_47;
84 create view s_47 as
85 select time AT TIME ZONE 'UTC-2' as time,
86         addr,
87         (json->'sensor_type')::int  as sensor_type,
88         (json->'sensor_name')::text as sensor_name,
89         (json->'sensor_data'->'Roll')::float as Roll,
90         (json->'sensor_data'->'Pitch')::float as Pitch,
91         (json->>'battery')::float as bettery,
92         (json->>'battery_percent')::float as battery_percent,
93         (json->'counter')::int as counter
94 from eg5120
95 where sensor_type = 47;
96 ;
97 grant select on s_47 to gread ;
98
99 -- 81 Two Channel Vibration Plus
100 drop view s_81;
101 create view s_81 as
102 select time AT TIME ZONE 'UTC-2' as time,
103         addr,
104         (json->'sensor_type')::int  as sensor_type,
105         (json->'sensor_name')::text as sensor_name,
106         (json->'sensor_data'->'s1_temperature')::float as s1_temperature,
107         (json->'sensor_data'->'s2_temperature')::float as s2_temperature,
108         (json->'sensor_data'->'x1_max_ACC_G')::float as x1_max_ACC_G,
109         (json->'sensor_data'->'x1_rms_ACC_G')::float as x1_rms_ACC_G,
110         (json->'sensor_data'->'x2_max_ACC_G')::float as x2_max_ACC_G,
111         (json->'sensor_data'->'x2_rms_ACC_G')::float as x2_rms_ACC_G,
112         (json->'sensor_data'->'y1_max_ACC_G')::float as y1_max_ACC_G,
113         (json->'sensor_data'->'y1_rms_ACC_G')::float as y1_rms_ACC_G,
114         (json->'sensor_data'->'y2_max_ACC_G')::float as y2_max_ACC_G,
115         (json->'sensor_data'->'y2_rms_ACC_G')::float as y2_rms_ACC_G,
116         (json->'sensor_data'->'z1_max_ACC_G')::float as z1_max_ACC_G,
117         (json->'sensor_data'->'z1_rms_ACC_G')::float as z1_rms_ACC_G,
118         (json->'sensor_data'->'z2_max_ACC_G')::float as z2_max_ACC_G,
119         (json->'sensor_data'->'z2_rms_ACC_G')::float as z2_rms_ACC_G,
120         (json->'sensor_data'->'x1_peak_one_Hz')::float as x1_peak_one_Hz,
121         (json->'sensor_data'->'x1_peak_two_Hz')::float as x1_peak_two_Hz,
122         (json->'sensor_data'->'x2_peak_one_Hz')::float as x2_peak_one_Hz,
123         (json->'sensor_data'->'x2_peak_two_Hz')::float as x2_peak_two_Hz,
124         (json->'sensor_data'->'y1_peak_one_Hz')::float as y1_peak_one_Hz,
125         (json->'sensor_data'->'y1_peak_two_Hz')::float as y1_peak_two_Hz,
126         (json->'sensor_data'->'y2_peak_one_Hz')::float as y2_peak_one_Hz,
127         (json->'sensor_data'->'y2_peak_two_Hz')::float as y2_peak_two_Hz,
128         (json->'sensor_data'->'z1_peak_one_Hz')::float as z1_peak_one_Hz,
129         (json->'sensor_data'->'z1_peak_two_Hz')::float as z1_peak_two_Hz,
130         (json->'sensor_data'->'z2_peak_one_Hz')::float as z2_peak_one_Hz,
131         (json->'sensor_data'->'z2_peak_two_Hz')::float as z2_peak_two_Hz,
132         (json->'sensor_data'->'x1_peak_three_Hz')::float as x1_peak_three_Hz,
133         (json->'sensor_data'->'x2_peak_three_Hz')::float as x2_peak_three_Hz,
134         (json->'sensor_data'->'y1_peak_three_Hz')::float as y1_peak_three_Hz,
135         (json->'sensor_data'->'y2_peak_three_Hz')::float as y2_peak_three_Hz,
136         (json->'sensor_data'->'z1_peak_three_Hz')::float as z1_peak_three_Hz,
137         (json->'sensor_data'->'z2_peak_three_Hz')::float as z2_peak_three_Hz,
138         (json->'sensor_data'->'x1_displacement_mm')::float as x1_displacement_mm,
139         (json->'sensor_data'->'x1_velocity_mm_sec')::float as x1_velocity_mm_sec,
140         (json->'sensor_data'->'x2_displacement_mm')::float as x2_displacement_mm,
141         (json->'sensor_data'->'x2_velocity_mm_sec')::float as x2_velocity_mm_sec,
142         (json->'sensor_data'->'y1_displacement_mm')::float as y1_displacement_mm,
143         (json->'sensor_data'->'y1_velocity_mm_sec')::float as y1_velocity_mm_sec,
144         (json->'sensor_data'->'y2_displacement_mm')::float as y2_displacement_mm,
145         (json->'sensor_data'->'y2_velocity_mm_sec')::float as y2_velocity_mm_sec,
146         (json->'sensor_data'->'z1_displacement_mm')::float as z1_displacement_mm,
147         (json->'sensor_data'->'z1_velocity_mm_sec')::float as z1_velocity_mm_sec,
148         (json->'sensor_data'->'z2_displacement_mm')::float as z2_displacement_mm,
149         (json->'sensor_data'->'z2_velocity_mm_sec')::float as z2_velocity_mm_sec,
150         (json->>'battery')::float as bettery,
151         (json->>'battery_percent')::float as battery_percent,
152         (json->'counter')::int as counter
153 from eg5120
154 where sensor_type = 81
155 order by time
156 ;
157 grant select on s_81 to gread ;
158