@golemio/microclimate 1.2.8-dev.1384166512 → 1.2.8-dev.1561229684

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,208 +1,208 @@
1
- DROP VIEW analytic.v_microclimate_measurements_daily_w_hights;
2
-
3
- DROP VIEW analytic.v_microclimate_measurements_daily;
4
-
5
- CREATE OR REPLACE VIEW analytic.v_microclimate_measurements_daily
6
- AS WITH calendar AS (
7
- SELECT calendar_1.date,
8
- sensors_1.sensor_id
9
- FROM ( SELECT generate_series('2022-08-02 00:00:00+02'::timestamp with time zone, CURRENT_DATE::timestamp with time zone, '1 day'::interval)::date AS date) calendar_1
10
- CROSS JOIN ( SELECT DISTINCT sensor_devices_import.sensor_id
11
- FROM microclimate.sensor_devices_import) sensors_1
12
- ), first_measurement_per_hour AS (
13
- SELECT DISTINCT ON (m.sensor_id, (timezone('CET'::text, m.measured_at)::date), (date_part('hour'::text, timezone('CET'::text, m.measured_at)))) m.sensor_id,
14
- timezone('CET'::text, m.measured_at) AS measured_at,
15
- timezone('CET'::text, m.measured_at)::date AS date,
16
- date_part('hour'::text, timezone('CET'::text, m.measured_at)) AS hour,
17
- m.air_temp,
18
- m.air_hum,
19
- m.pressure,
20
- m.wind_speed,
21
- m.water_pot,
22
- m.soil_temp
23
- FROM microclimate.measurements m
24
- WHERE date_part('hour'::text, timezone('CET'::text, m.measured_at)) = ANY (ARRAY[7::double precision, 14::double precision, 21::double precision])
25
- ORDER BY m.sensor_id, (timezone('CET'::text, m.measured_at)::date), (date_part('hour'::text, timezone('CET'::text, m.measured_at))), m.measured_at
26
- ), seven AS (
27
- SELECT first_measurement_per_hour.sensor_id,
28
- first_measurement_per_hour.measured_at,
29
- first_measurement_per_hour.date,
30
- first_measurement_per_hour.hour,
31
- first_measurement_per_hour.air_temp,
32
- first_measurement_per_hour.air_hum,
33
- first_measurement_per_hour.pressure,
34
- first_measurement_per_hour.wind_speed,
35
- first_measurement_per_hour.water_pot,
36
- first_measurement_per_hour.soil_temp
37
- FROM first_measurement_per_hour
38
- WHERE first_measurement_per_hour.hour = 7::double precision
39
- ), two AS (
40
- SELECT first_measurement_per_hour.sensor_id,
41
- first_measurement_per_hour.measured_at,
42
- first_measurement_per_hour.date,
43
- first_measurement_per_hour.hour,
44
- first_measurement_per_hour.air_temp,
45
- first_measurement_per_hour.air_hum,
46
- first_measurement_per_hour.pressure,
47
- first_measurement_per_hour.wind_speed,
48
- first_measurement_per_hour.water_pot,
49
- first_measurement_per_hour.soil_temp
50
- FROM first_measurement_per_hour
51
- WHERE first_measurement_per_hour.hour = 14::double precision
52
- ), nine AS (
53
- SELECT first_measurement_per_hour.sensor_id,
54
- first_measurement_per_hour.measured_at,
55
- first_measurement_per_hour.date,
56
- first_measurement_per_hour.hour,
57
- first_measurement_per_hour.air_temp,
58
- first_measurement_per_hour.air_hum,
59
- first_measurement_per_hour.pressure,
60
- first_measurement_per_hour.wind_speed,
61
- first_measurement_per_hour.water_pot,
62
- first_measurement_per_hour.soil_temp
63
- FROM first_measurement_per_hour
64
- WHERE first_measurement_per_hour.hour = 21::double precision
65
- ), wind AS (
66
- SELECT DISTINCT ON (m.sensor_id, (timezone('CET'::text, m.measured_at)::date)) m.sensor_id,
67
- timezone('CET'::text, m.measured_at)::date AS date,
68
- m.wind_speed AS max_wind_speed,
69
- CASE
70
- WHEN m.wind_dir::text = 'N'::text THEN 0
71
- WHEN m.wind_dir::text = 'S'::text THEN 180
72
- WHEN m.wind_dir::text = 'E'::text THEN 90
73
- WHEN m.wind_dir::text = 'W'::text THEN 270
74
- WHEN m.wind_dir::text = 'SW'::text THEN 200
75
- WHEN m.wind_dir::text = 'NW'::text THEN 320
76
- WHEN m.wind_dir::text = 'NE'::text THEN 45
77
- ELSE NULL::integer
78
- END AS wind_dir_at_max_speed
79
- FROM microclimate.measurements m
80
- ORDER BY m.sensor_id, (timezone('CET'::text, m.measured_at)::date), m.wind_speed DESC
81
- ), min_max_daily_temp AS (
82
- SELECT m.sensor_id,
83
- timezone('-04'::text, m.measured_at)::date AS date,
84
- max(m.air_temp) AS max_temperature,
85
- min(m.air_temp) AS min_temperature
86
- FROM microclimate.measurements m
87
- GROUP BY m.sensor_id, (timezone('-04'::text, m.measured_at)::date)
88
- ORDER BY m.sensor_id, (timezone('-04'::text, m.measured_at)::date)
89
- ), precip AS (
90
- SELECT m.sensor_id,
91
- timezone('+06'::text, m.measured_at)::date AS date,
92
- sum(m.precip) AS sum_precip
93
- FROM microclimate.measurements m
94
- GROUP BY m.sensor_id, (timezone('+06'::text, m.measured_at)::date)
95
- ORDER BY m.sensor_id, (timezone('+06'::text, m.measured_at)::date)
96
- ), calc AS (
97
- SELECT sensors.address,
98
- sensors.sensor_position_detail,
99
- sensors.point_id,
100
- sensors.air_temp,
101
- sensors.air_hum,
102
- sensors.pressure,
103
- sensors.precip,
104
- sensors.wind_dir,
105
- sensors.wind_impact,
106
- sensors.wind_speed,
107
- sensors.sun_irr,
108
- sensors.soil_temp,
109
- sensors.water_pot,
110
- sensors.dendro_circ,
111
- sensors.dendro_gain,
112
- calendar.date,
113
- calendar.sensor_id,
114
- (seven.air_temp + two.air_temp + 2::double precision * nine.air_temp) / 4::double precision AS avg_temperature,
115
- (seven.air_hum + two.air_hum + nine.air_hum) / 3::double precision AS avg_air_hum,
116
- (seven.pressure + two.pressure + nine.pressure) / 3 / 100 AS avg_pressure,
117
- (seven.wind_speed + two.wind_speed + nine.wind_speed) / 3::double precision AS avg_wind_speed,
118
- (seven.water_pot + two.water_pot + nine.water_pot) / 3::double precision AS avg_water_pot,
119
- (seven.soil_temp + two.soil_temp + nine.soil_temp) / 3::double precision AS avg_soil_temp,
120
- wind.max_wind_speed,
121
- wind.wind_dir_at_max_speed,
122
- min_max_daily_temp.max_temperature,
123
- min_max_daily_temp.min_temperature,
124
- precip.sum_precip
125
- FROM calendar
126
- LEFT JOIN seven ON calendar.sensor_id::text = seven.sensor_id::text AND calendar.date = seven.date
127
- LEFT JOIN two ON calendar.sensor_id::text = two.sensor_id::text AND calendar.date = two.date
128
- LEFT JOIN nine ON calendar.sensor_id::text = nine.sensor_id::text AND calendar.date = nine.date
129
- LEFT JOIN wind ON calendar.sensor_id::text = wind.sensor_id::text AND calendar.date = wind.date
130
- LEFT JOIN min_max_daily_temp ON calendar.sensor_id::text = min_max_daily_temp.sensor_id::text AND calendar.date = min_max_daily_temp.date
131
- LEFT JOIN precip ON calendar.sensor_id::text = precip.sensor_id::text AND calendar.date = precip.date
132
- LEFT JOIN microclimate.sensor_devices_import sensors ON calendar.sensor_id::text = sensors.sensor_id::text
133
- )
134
- SELECT calc.address,
135
- calc.sensor_position_detail,
136
- calc.date,
137
- calc.sensor_id,
138
- calc.point_id,
139
- unpivot.metrika,
140
- unpivot.value
141
- FROM calc,
142
- LATERAL ( VALUES ('avg_temperature'::text,calc.avg_temperature), ('avg_air_hum'::text,calc.avg_air_hum), ('avg_pressure'::text,calc.avg_pressure), ('avg_wind_speed'::text,calc.avg_wind_speed), ('avg_water_pot'::text,calc.avg_water_pot), ('avg_soil_temp'::text,calc.avg_soil_temp), ('max_wind_speed'::text,calc.max_wind_speed), ('max_temperature'::text,calc.max_temperature), ('min_temperature'::text,calc.min_temperature), ('sum_precip'::text,calc.sum_precip), ('wind_dir_at_max_speed'::text,calc.wind_dir_at_max_speed)) unpivot(metrika, value)
143
- WHERE unpivot.value IS NOT NULL;
144
-
145
- CREATE OR REPLACE VIEW analytic.v_microclimate_measurements_daily_w_hights
146
- AS SELECT m.date,
147
- m.sensor_id,
148
- m.address,
149
- m.sensor_position_detail,
150
- h.measure,
151
- m.value,
152
- h.hight_cm,
153
- CASE
154
- WHEN h.measure = 'wind_dir_at_max_speed'::text THEN 'Směr maximální rychlosti větru'::text
155
- WHEN h.measure = 'sum_precip'::text THEN 'Denní úhrn srážek'::text
156
- WHEN h.measure = 'avg_temperature'::text THEN 'Průměrná denní teplota vzduchu'::text
157
- WHEN h.measure = 'max_wind_speed'::text THEN 'Maximální rychlost větru'::text
158
- WHEN h.measure = 'avg_water_pot'::text THEN 'Průměrná denní vlhkost půdy'::text
159
- WHEN h.measure = 'avg_wind_speed'::text THEN 'Průměrná denní rychlost větru'::text
160
- WHEN h.measure = 'avg_air_hum'::text THEN 'Průměrná denní relativní vlhkost vzduchu'::text
161
- WHEN h.measure = 'avg_pressure'::text THEN 'Průměrný denní tlak vzduchu'::text
162
- WHEN h.measure = 'max_temperature'::text THEN 'Maximální denní teplota vzduchu'::text
163
- WHEN h.measure = 'avg_soil_temp'::text THEN 'Průměrná denní teplota půdy'::text
164
- WHEN h.measure = 'min_temperature'::text THEN 'Minimální denní teplota vzduchu'::text
165
- ELSE NULL::text
166
- END AS measure_cz,
167
- CASE
168
- WHEN h.measure = 'wind_dir_at_max_speed'::text THEN 'm/s'::text
169
- WHEN h.measure = 'sum_precip'::text THEN 'mm'::text
170
- WHEN h.measure = 'avg_temperature'::text THEN '°C'::text
171
- WHEN h.measure = 'max_wind_speed'::text THEN 'm/s'::text
172
- WHEN h.measure = 'avg_water_pot'::text THEN 'kPa'::text
173
- WHEN h.measure = 'avg_wind_speed'::text THEN 'm/s'::text
174
- WHEN h.measure = 'avg_air_hum'::text THEN '%'::text
175
- WHEN h.measure = 'avg_pressure'::text THEN 'hPa'::text
176
- WHEN h.measure = 'max_temperature'::text THEN '°C'::text
177
- WHEN h.measure = 'avg_soil_temp'::text THEN '°C'::text
178
- WHEN h.measure = 'min_temperature'::text THEN '°C'::text
179
- ELSE NULL::text
180
- END AS unit
181
- FROM analytic.v_microclimate_measurements_daily m
182
- LEFT JOIN analytic.v_microclimate_measurement_hights h ON m.sensor_id::text = h.sensor_id::text AND m.metrika = h.measure
183
- ORDER BY m.sensor_id, m.date;
184
-
185
- CREATE OR REPLACE VIEW analytic.v_microclimate_wind_dir_at_max_speed
186
- AS WITH max_wind_speed AS (
187
- SELECT DISTINCT ON (v_microclimate_measurements_daily_w_hights.sensor_id, (date_trunc('month'::text, v_microclimate_measurements_daily_w_hights.date::timestamp with time zone))) v_microclimate_measurements_daily_w_hights.date,
188
- v_microclimate_measurements_daily_w_hights.sensor_id,
189
- v_microclimate_measurements_daily_w_hights.value AS wind_speed
190
- FROM analytic.v_microclimate_measurements_daily_w_hights
191
- WHERE v_microclimate_measurements_daily_w_hights.measure = 'max_wind_speed'::text
192
- ORDER BY v_microclimate_measurements_daily_w_hights.sensor_id, (date_trunc('month'::text, v_microclimate_measurements_daily_w_hights.date::timestamp with time zone)), v_microclimate_measurements_daily_w_hights.value DESC
193
- ), dir_wind_speed AS (
194
- SELECT vmma.date,
195
- vmma.sensor_id,
196
- vmma.value AS wind_dir
197
- FROM analytic.v_microclimate_measurements_daily_w_hights vmma
198
- WHERE vmma.measure = 'wind_dir_at_max_speed'::text AND vmma.value IS NOT NULL
199
- )
200
- SELECT max_wind_speed.date,
201
- max_wind_speed.wind_speed,
202
- max_wind_speed.sensor_id,
203
- dir_wind_speed.wind_dir AS dir
204
- FROM max_wind_speed
205
- JOIN dir_wind_speed ON max_wind_speed.sensor_id::text = dir_wind_speed.sensor_id::text AND max_wind_speed.date = dir_wind_speed.date
206
- ORDER BY max_wind_speed.date;
207
-
208
-
1
+ DROP VIEW analytic.v_microclimate_measurements_daily_w_hights;
2
+
3
+ DROP VIEW analytic.v_microclimate_measurements_daily;
4
+
5
+ CREATE OR REPLACE VIEW analytic.v_microclimate_measurements_daily
6
+ AS WITH calendar AS (
7
+ SELECT calendar_1.date,
8
+ sensors_1.sensor_id
9
+ FROM ( SELECT generate_series('2022-08-02 00:00:00+02'::timestamp with time zone, CURRENT_DATE::timestamp with time zone, '1 day'::interval)::date AS date) calendar_1
10
+ CROSS JOIN ( SELECT DISTINCT sensor_devices_import.sensor_id
11
+ FROM microclimate.sensor_devices_import) sensors_1
12
+ ), first_measurement_per_hour AS (
13
+ SELECT DISTINCT ON (m.sensor_id, (timezone('CET'::text, m.measured_at)::date), (date_part('hour'::text, timezone('CET'::text, m.measured_at)))) m.sensor_id,
14
+ timezone('CET'::text, m.measured_at) AS measured_at,
15
+ timezone('CET'::text, m.measured_at)::date AS date,
16
+ date_part('hour'::text, timezone('CET'::text, m.measured_at)) AS hour,
17
+ m.air_temp,
18
+ m.air_hum,
19
+ m.pressure,
20
+ m.wind_speed,
21
+ m.water_pot,
22
+ m.soil_temp
23
+ FROM microclimate.measurements m
24
+ WHERE date_part('hour'::text, timezone('CET'::text, m.measured_at)) = ANY (ARRAY[7::double precision, 14::double precision, 21::double precision])
25
+ ORDER BY m.sensor_id, (timezone('CET'::text, m.measured_at)::date), (date_part('hour'::text, timezone('CET'::text, m.measured_at))), m.measured_at
26
+ ), seven AS (
27
+ SELECT first_measurement_per_hour.sensor_id,
28
+ first_measurement_per_hour.measured_at,
29
+ first_measurement_per_hour.date,
30
+ first_measurement_per_hour.hour,
31
+ first_measurement_per_hour.air_temp,
32
+ first_measurement_per_hour.air_hum,
33
+ first_measurement_per_hour.pressure,
34
+ first_measurement_per_hour.wind_speed,
35
+ first_measurement_per_hour.water_pot,
36
+ first_measurement_per_hour.soil_temp
37
+ FROM first_measurement_per_hour
38
+ WHERE first_measurement_per_hour.hour = 7::double precision
39
+ ), two AS (
40
+ SELECT first_measurement_per_hour.sensor_id,
41
+ first_measurement_per_hour.measured_at,
42
+ first_measurement_per_hour.date,
43
+ first_measurement_per_hour.hour,
44
+ first_measurement_per_hour.air_temp,
45
+ first_measurement_per_hour.air_hum,
46
+ first_measurement_per_hour.pressure,
47
+ first_measurement_per_hour.wind_speed,
48
+ first_measurement_per_hour.water_pot,
49
+ first_measurement_per_hour.soil_temp
50
+ FROM first_measurement_per_hour
51
+ WHERE first_measurement_per_hour.hour = 14::double precision
52
+ ), nine AS (
53
+ SELECT first_measurement_per_hour.sensor_id,
54
+ first_measurement_per_hour.measured_at,
55
+ first_measurement_per_hour.date,
56
+ first_measurement_per_hour.hour,
57
+ first_measurement_per_hour.air_temp,
58
+ first_measurement_per_hour.air_hum,
59
+ first_measurement_per_hour.pressure,
60
+ first_measurement_per_hour.wind_speed,
61
+ first_measurement_per_hour.water_pot,
62
+ first_measurement_per_hour.soil_temp
63
+ FROM first_measurement_per_hour
64
+ WHERE first_measurement_per_hour.hour = 21::double precision
65
+ ), wind AS (
66
+ SELECT DISTINCT ON (m.sensor_id, (timezone('CET'::text, m.measured_at)::date)) m.sensor_id,
67
+ timezone('CET'::text, m.measured_at)::date AS date,
68
+ m.wind_speed AS max_wind_speed,
69
+ CASE
70
+ WHEN m.wind_dir::text = 'N'::text THEN 0
71
+ WHEN m.wind_dir::text = 'S'::text THEN 180
72
+ WHEN m.wind_dir::text = 'E'::text THEN 90
73
+ WHEN m.wind_dir::text = 'W'::text THEN 270
74
+ WHEN m.wind_dir::text = 'SW'::text THEN 200
75
+ WHEN m.wind_dir::text = 'NW'::text THEN 320
76
+ WHEN m.wind_dir::text = 'NE'::text THEN 45
77
+ ELSE NULL::integer
78
+ END AS wind_dir_at_max_speed
79
+ FROM microclimate.measurements m
80
+ ORDER BY m.sensor_id, (timezone('CET'::text, m.measured_at)::date), m.wind_speed DESC
81
+ ), min_max_daily_temp AS (
82
+ SELECT m.sensor_id,
83
+ timezone('-04'::text, m.measured_at)::date AS date,
84
+ max(m.air_temp) AS max_temperature,
85
+ min(m.air_temp) AS min_temperature
86
+ FROM microclimate.measurements m
87
+ GROUP BY m.sensor_id, (timezone('-04'::text, m.measured_at)::date)
88
+ ORDER BY m.sensor_id, (timezone('-04'::text, m.measured_at)::date)
89
+ ), precip AS (
90
+ SELECT m.sensor_id,
91
+ timezone('+06'::text, m.measured_at)::date AS date,
92
+ sum(m.precip) AS sum_precip
93
+ FROM microclimate.measurements m
94
+ GROUP BY m.sensor_id, (timezone('+06'::text, m.measured_at)::date)
95
+ ORDER BY m.sensor_id, (timezone('+06'::text, m.measured_at)::date)
96
+ ), calc AS (
97
+ SELECT sensors.address,
98
+ sensors.sensor_position_detail,
99
+ sensors.point_id,
100
+ sensors.air_temp,
101
+ sensors.air_hum,
102
+ sensors.pressure,
103
+ sensors.precip,
104
+ sensors.wind_dir,
105
+ sensors.wind_impact,
106
+ sensors.wind_speed,
107
+ sensors.sun_irr,
108
+ sensors.soil_temp,
109
+ sensors.water_pot,
110
+ sensors.dendro_circ,
111
+ sensors.dendro_gain,
112
+ calendar.date,
113
+ calendar.sensor_id,
114
+ (seven.air_temp + two.air_temp + 2::double precision * nine.air_temp) / 4::double precision AS avg_temperature,
115
+ (seven.air_hum + two.air_hum + nine.air_hum) / 3::double precision AS avg_air_hum,
116
+ (seven.pressure + two.pressure + nine.pressure) / 3 / 100 AS avg_pressure,
117
+ (seven.wind_speed + two.wind_speed + nine.wind_speed) / 3::double precision AS avg_wind_speed,
118
+ (seven.water_pot + two.water_pot + nine.water_pot) / 3::double precision AS avg_water_pot,
119
+ (seven.soil_temp + two.soil_temp + nine.soil_temp) / 3::double precision AS avg_soil_temp,
120
+ wind.max_wind_speed,
121
+ wind.wind_dir_at_max_speed,
122
+ min_max_daily_temp.max_temperature,
123
+ min_max_daily_temp.min_temperature,
124
+ precip.sum_precip
125
+ FROM calendar
126
+ LEFT JOIN seven ON calendar.sensor_id::text = seven.sensor_id::text AND calendar.date = seven.date
127
+ LEFT JOIN two ON calendar.sensor_id::text = two.sensor_id::text AND calendar.date = two.date
128
+ LEFT JOIN nine ON calendar.sensor_id::text = nine.sensor_id::text AND calendar.date = nine.date
129
+ LEFT JOIN wind ON calendar.sensor_id::text = wind.sensor_id::text AND calendar.date = wind.date
130
+ LEFT JOIN min_max_daily_temp ON calendar.sensor_id::text = min_max_daily_temp.sensor_id::text AND calendar.date = min_max_daily_temp.date
131
+ LEFT JOIN precip ON calendar.sensor_id::text = precip.sensor_id::text AND calendar.date = precip.date
132
+ LEFT JOIN microclimate.sensor_devices_import sensors ON calendar.sensor_id::text = sensors.sensor_id::text
133
+ )
134
+ SELECT calc.address,
135
+ calc.sensor_position_detail,
136
+ calc.date,
137
+ calc.sensor_id,
138
+ calc.point_id,
139
+ unpivot.metrika,
140
+ unpivot.value
141
+ FROM calc,
142
+ LATERAL ( VALUES ('avg_temperature'::text,calc.avg_temperature), ('avg_air_hum'::text,calc.avg_air_hum), ('avg_pressure'::text,calc.avg_pressure), ('avg_wind_speed'::text,calc.avg_wind_speed), ('avg_water_pot'::text,calc.avg_water_pot), ('avg_soil_temp'::text,calc.avg_soil_temp), ('max_wind_speed'::text,calc.max_wind_speed), ('max_temperature'::text,calc.max_temperature), ('min_temperature'::text,calc.min_temperature), ('sum_precip'::text,calc.sum_precip), ('wind_dir_at_max_speed'::text,calc.wind_dir_at_max_speed)) unpivot(metrika, value)
143
+ WHERE unpivot.value IS NOT NULL;
144
+
145
+ CREATE OR REPLACE VIEW analytic.v_microclimate_measurements_daily_w_hights
146
+ AS SELECT m.date,
147
+ m.sensor_id,
148
+ m.address,
149
+ m.sensor_position_detail,
150
+ h.measure,
151
+ m.value,
152
+ h.hight_cm,
153
+ CASE
154
+ WHEN h.measure = 'wind_dir_at_max_speed'::text THEN 'Směr maximální rychlosti větru'::text
155
+ WHEN h.measure = 'sum_precip'::text THEN 'Denní úhrn srážek'::text
156
+ WHEN h.measure = 'avg_temperature'::text THEN 'Průměrná denní teplota vzduchu'::text
157
+ WHEN h.measure = 'max_wind_speed'::text THEN 'Maximální rychlost větru'::text
158
+ WHEN h.measure = 'avg_water_pot'::text THEN 'Průměrná denní vlhkost půdy'::text
159
+ WHEN h.measure = 'avg_wind_speed'::text THEN 'Průměrná denní rychlost větru'::text
160
+ WHEN h.measure = 'avg_air_hum'::text THEN 'Průměrná denní relativní vlhkost vzduchu'::text
161
+ WHEN h.measure = 'avg_pressure'::text THEN 'Průměrný denní tlak vzduchu'::text
162
+ WHEN h.measure = 'max_temperature'::text THEN 'Maximální denní teplota vzduchu'::text
163
+ WHEN h.measure = 'avg_soil_temp'::text THEN 'Průměrná denní teplota půdy'::text
164
+ WHEN h.measure = 'min_temperature'::text THEN 'Minimální denní teplota vzduchu'::text
165
+ ELSE NULL::text
166
+ END AS measure_cz,
167
+ CASE
168
+ WHEN h.measure = 'wind_dir_at_max_speed'::text THEN 'm/s'::text
169
+ WHEN h.measure = 'sum_precip'::text THEN 'mm'::text
170
+ WHEN h.measure = 'avg_temperature'::text THEN '°C'::text
171
+ WHEN h.measure = 'max_wind_speed'::text THEN 'm/s'::text
172
+ WHEN h.measure = 'avg_water_pot'::text THEN 'kPa'::text
173
+ WHEN h.measure = 'avg_wind_speed'::text THEN 'm/s'::text
174
+ WHEN h.measure = 'avg_air_hum'::text THEN '%'::text
175
+ WHEN h.measure = 'avg_pressure'::text THEN 'hPa'::text
176
+ WHEN h.measure = 'max_temperature'::text THEN '°C'::text
177
+ WHEN h.measure = 'avg_soil_temp'::text THEN '°C'::text
178
+ WHEN h.measure = 'min_temperature'::text THEN '°C'::text
179
+ ELSE NULL::text
180
+ END AS unit
181
+ FROM analytic.v_microclimate_measurements_daily m
182
+ LEFT JOIN analytic.v_microclimate_measurement_hights h ON m.sensor_id::text = h.sensor_id::text AND m.metrika = h.measure
183
+ ORDER BY m.sensor_id, m.date;
184
+
185
+ CREATE OR REPLACE VIEW analytic.v_microclimate_wind_dir_at_max_speed
186
+ AS WITH max_wind_speed AS (
187
+ SELECT DISTINCT ON (v_microclimate_measurements_daily_w_hights.sensor_id, (date_trunc('month'::text, v_microclimate_measurements_daily_w_hights.date::timestamp with time zone))) v_microclimate_measurements_daily_w_hights.date,
188
+ v_microclimate_measurements_daily_w_hights.sensor_id,
189
+ v_microclimate_measurements_daily_w_hights.value AS wind_speed
190
+ FROM analytic.v_microclimate_measurements_daily_w_hights
191
+ WHERE v_microclimate_measurements_daily_w_hights.measure = 'max_wind_speed'::text
192
+ ORDER BY v_microclimate_measurements_daily_w_hights.sensor_id, (date_trunc('month'::text, v_microclimate_measurements_daily_w_hights.date::timestamp with time zone)), v_microclimate_measurements_daily_w_hights.value DESC
193
+ ), dir_wind_speed AS (
194
+ SELECT vmma.date,
195
+ vmma.sensor_id,
196
+ vmma.value AS wind_dir
197
+ FROM analytic.v_microclimate_measurements_daily_w_hights vmma
198
+ WHERE vmma.measure = 'wind_dir_at_max_speed'::text AND vmma.value IS NOT NULL
199
+ )
200
+ SELECT max_wind_speed.date,
201
+ max_wind_speed.wind_speed,
202
+ max_wind_speed.sensor_id,
203
+ dir_wind_speed.wind_dir AS dir
204
+ FROM max_wind_speed
205
+ JOIN dir_wind_speed ON max_wind_speed.sensor_id::text = dir_wind_speed.sensor_id::text AND max_wind_speed.date = dir_wind_speed.date
206
+ ORDER BY max_wind_speed.date;
207
+
208
+
@@ -1,20 +1,20 @@
1
- DROP VIEW analytic.v_microclimate_sensor_devices;
2
-
3
- CREATE OR REPLACE VIEW analytic.v_microclimate_sensor_devices
4
- AS SELECT sdi.sensor_id,
5
- sdi.location_id,
6
- sdi.point_id,
7
- sdi.location,
8
- sdi.loc_description,
9
- sdi.loc_orientation,
10
- sdi.loc_surface,
11
- sdi.point_name,
12
- sdi.address,
13
- sdi.sensor_position,
14
- sdi.sensor_position_detail,
15
- sdi.lat,
16
- sdi.lng,
17
- ('https://storage.golemio.cz/oict-mikroklima/'::text || sdi.sensor_id::text) || '.jpg'::text AS url_foto
18
- FROM microclimate.sensor_devices_import sdi;
19
-
20
- DROP VIEW analytic.v_microclimate_raw_data;
1
+ DROP VIEW analytic.v_microclimate_sensor_devices;
2
+
3
+ CREATE OR REPLACE VIEW analytic.v_microclimate_sensor_devices
4
+ AS SELECT sdi.sensor_id,
5
+ sdi.location_id,
6
+ sdi.point_id,
7
+ sdi.location,
8
+ sdi.loc_description,
9
+ sdi.loc_orientation,
10
+ sdi.loc_surface,
11
+ sdi.point_name,
12
+ sdi.address,
13
+ sdi.sensor_position,
14
+ sdi.sensor_position_detail,
15
+ sdi.lat,
16
+ sdi.lng,
17
+ ('https://storage.golemio.cz/oict-mikroklima/'::text || sdi.sensor_id::text) || '.jpg'::text AS url_foto
18
+ FROM microclimate.sensor_devices_import sdi;
19
+
20
+ DROP VIEW analytic.v_microclimate_raw_data;
@@ -1,79 +1,79 @@
1
- DROP VIEW analytic.v_microclimate_sensor_devices;
2
-
3
- CREATE OR REPLACE VIEW analytic.v_microclimate_sensor_devices
4
- AS SELECT sdi.sensor_id,
5
- sdi.location_id,
6
- sdi.point_id,
7
- sdi.location,
8
- sdi.loc_description,
9
- sdi.loc_orientation,
10
- sdi.loc_surface,
11
- sdi.point_name,
12
- sdi.address,
13
- sdi.sensor_position,
14
- sdi.sensor_position_detail,
15
- sdi.lat,
16
- sdi.lng,
17
- ('https://storage.golemio.cz/oict-mikroklima/'::text || sdi.point_id::text) || '.jpg'::text AS url_foto
18
- FROM microclimate.sensor_devices_import sdi;
19
-
20
- CREATE OR REPLACE VIEW analytic.v_microclimate_raw_data
21
- AS WITH tmp_hights AS (
22
- SELECT DISTINCT s.sensor_id,
23
- s.address,
24
- s.sensor_position_detail,
25
- unpivot.measure,
26
- unpivot.hight_cm
27
- FROM microclimate.sensor_devices_import s,
28
- LATERAL ( VALUES ('Teplota vzduchu'::text,s.air_temp), ('Vlhkost vzduchu'::text,s.air_hum), ('Tlak vzduchu'::text,s.pressure), ('Náraz a směr větru'::text,s.wind_impact), ('Rychlost a směr větru'::text,s.wind_speed), ('Úhrn srážek'::text,s.precip), ('Sluneční svit'::text,s.sun_irr), ('Vodní potenciál půdy'::text,s.water_pot), ('Teplota půdy'::text,s.soil_temp), ('Obvod stromu'::text,s.dendro_circ), ('Přírůstek obvodu stromu'::text,s.dendro_gain)) unpivot(measure, hight_cm)
29
- WHERE unpivot.hight_cm IS NOT NULL
30
- ), tmp_measures AS (
31
- SELECT m_1.sensor_id,
32
- m_1.measured_at,
33
- m_1.measured_at::date AS measured_date,
34
- unpivot.measure_name,
35
- unpivot.measure,
36
- CASE
37
- WHEN m_1.wind_dir::text = 'N'::text THEN 0
38
- WHEN m_1.wind_dir::text = 'NE'::text THEN 45
39
- WHEN m_1.wind_dir::text = 'E'::text THEN 90
40
- WHEN m_1.wind_dir::text = 'SE'::text THEN 135
41
- WHEN m_1.wind_dir::text = 'S'::text THEN 180
42
- WHEN m_1.wind_dir::text = 'SW'::text THEN 225
43
- WHEN m_1.wind_dir::text = 'W'::text THEN 270
44
- WHEN m_1.wind_dir::text = 'NW'::text THEN 315
45
- ELSE NULL::integer
46
- END AS wind_dir
47
- FROM microclimate.measurements m_1,
48
- LATERAL ( VALUES ('Teplota vzduchu'::text,m_1.air_temp), ('Vlhkost vzduchu'::text,m_1.air_hum), ('Tlak vzduchu'::text,m_1.pressure), ('Náraz a směr větru'::text,m_1.wind_impact), ('Rychlost a směr větru'::text,m_1.wind_speed), ('Úhrn srážek'::text,m_1.precip), ('Sluneční svit'::text,m_1.sun_irr), ('Vodní potenciál půdy'::text,m_1.water_pot), ('Teplota půdy'::text,m_1.soil_temp), ('Obvod stromu'::text,m_1.dendro_circ), ('Přírůstek obvodu stromu'::text,m_1.dendro_gain)) unpivot(measure_name, measure)
49
- WHERE m_1.measured_at::date >= (CURRENT_DATE - 7)
50
- )
51
- SELECT m.sensor_id,
52
- t.address,
53
- t.sensor_position_detail,
54
- t.hight_cm,
55
- m.measured_at,
56
- m.measured_at::date AS measured_date,
57
- m.measure_name,
58
- CASE
59
- WHEN m.measure_name = 'Teplota vzduchu'::text THEN '°C'::text
60
- WHEN m.measure_name = 'Vlhkost vzduchu'::text THEN '%'::text
61
- WHEN m.measure_name = 'Tlak vzduchu'::text THEN 'Pa'::text
62
- WHEN m.measure_name = 'Náraz a směr větru'::text THEN 'km/h'::text
63
- WHEN m.measure_name = 'Rychlost a směr větru'::text THEN 'km/h'::text
64
- WHEN m.measure_name = 'Úhrn srážek'::text THEN 'mm'::text
65
- WHEN m.measure_name = 'Sluneční svit'::text THEN 'lux'::text
66
- WHEN m.measure_name = 'Vodní potenciál půdy'::text THEN 'kPa'::text
67
- WHEN m.measure_name = 'Teplota půdy'::text THEN '°C'::text
68
- WHEN m.measure_name = 'Obvod stromu'::text THEN 'mm'::text
69
- WHEN m.measure_name = 'Přírůstek obvodu stromu'::text THEN 'µm'::text
70
- ELSE NULL::text
71
- END AS unit,
72
- m.measure,
73
- CASE
74
- WHEN m.measure_name = 'Náraz a směr větru'::text THEN m.wind_dir
75
- WHEN m.measure_name = 'Rychlost a směr větru'::text THEN m.wind_dir
76
- ELSE NULL::integer
77
- END AS measure_wind_dir
78
- FROM tmp_hights t
79
- JOIN tmp_measures m ON t.sensor_id::text = m.sensor_id::text AND t.measure = m.measure_name;
1
+ DROP VIEW analytic.v_microclimate_sensor_devices;
2
+
3
+ CREATE OR REPLACE VIEW analytic.v_microclimate_sensor_devices
4
+ AS SELECT sdi.sensor_id,
5
+ sdi.location_id,
6
+ sdi.point_id,
7
+ sdi.location,
8
+ sdi.loc_description,
9
+ sdi.loc_orientation,
10
+ sdi.loc_surface,
11
+ sdi.point_name,
12
+ sdi.address,
13
+ sdi.sensor_position,
14
+ sdi.sensor_position_detail,
15
+ sdi.lat,
16
+ sdi.lng,
17
+ ('https://storage.golemio.cz/oict-mikroklima/'::text || sdi.point_id::text) || '.jpg'::text AS url_foto
18
+ FROM microclimate.sensor_devices_import sdi;
19
+
20
+ CREATE OR REPLACE VIEW analytic.v_microclimate_raw_data
21
+ AS WITH tmp_hights AS (
22
+ SELECT DISTINCT s.sensor_id,
23
+ s.address,
24
+ s.sensor_position_detail,
25
+ unpivot.measure,
26
+ unpivot.hight_cm
27
+ FROM microclimate.sensor_devices_import s,
28
+ LATERAL ( VALUES ('Teplota vzduchu'::text,s.air_temp), ('Vlhkost vzduchu'::text,s.air_hum), ('Tlak vzduchu'::text,s.pressure), ('Náraz a směr větru'::text,s.wind_impact), ('Rychlost a směr větru'::text,s.wind_speed), ('Úhrn srážek'::text,s.precip), ('Sluneční svit'::text,s.sun_irr), ('Vodní potenciál půdy'::text,s.water_pot), ('Teplota půdy'::text,s.soil_temp), ('Obvod stromu'::text,s.dendro_circ), ('Přírůstek obvodu stromu'::text,s.dendro_gain)) unpivot(measure, hight_cm)
29
+ WHERE unpivot.hight_cm IS NOT NULL
30
+ ), tmp_measures AS (
31
+ SELECT m_1.sensor_id,
32
+ m_1.measured_at,
33
+ m_1.measured_at::date AS measured_date,
34
+ unpivot.measure_name,
35
+ unpivot.measure,
36
+ CASE
37
+ WHEN m_1.wind_dir::text = 'N'::text THEN 0
38
+ WHEN m_1.wind_dir::text = 'NE'::text THEN 45
39
+ WHEN m_1.wind_dir::text = 'E'::text THEN 90
40
+ WHEN m_1.wind_dir::text = 'SE'::text THEN 135
41
+ WHEN m_1.wind_dir::text = 'S'::text THEN 180
42
+ WHEN m_1.wind_dir::text = 'SW'::text THEN 225
43
+ WHEN m_1.wind_dir::text = 'W'::text THEN 270
44
+ WHEN m_1.wind_dir::text = 'NW'::text THEN 315
45
+ ELSE NULL::integer
46
+ END AS wind_dir
47
+ FROM microclimate.measurements m_1,
48
+ LATERAL ( VALUES ('Teplota vzduchu'::text,m_1.air_temp), ('Vlhkost vzduchu'::text,m_1.air_hum), ('Tlak vzduchu'::text,m_1.pressure), ('Náraz a směr větru'::text,m_1.wind_impact), ('Rychlost a směr větru'::text,m_1.wind_speed), ('Úhrn srážek'::text,m_1.precip), ('Sluneční svit'::text,m_1.sun_irr), ('Vodní potenciál půdy'::text,m_1.water_pot), ('Teplota půdy'::text,m_1.soil_temp), ('Obvod stromu'::text,m_1.dendro_circ), ('Přírůstek obvodu stromu'::text,m_1.dendro_gain)) unpivot(measure_name, measure)
49
+ WHERE m_1.measured_at::date >= (CURRENT_DATE - 7)
50
+ )
51
+ SELECT m.sensor_id,
52
+ t.address,
53
+ t.sensor_position_detail,
54
+ t.hight_cm,
55
+ m.measured_at,
56
+ m.measured_at::date AS measured_date,
57
+ m.measure_name,
58
+ CASE
59
+ WHEN m.measure_name = 'Teplota vzduchu'::text THEN '°C'::text
60
+ WHEN m.measure_name = 'Vlhkost vzduchu'::text THEN '%'::text
61
+ WHEN m.measure_name = 'Tlak vzduchu'::text THEN 'Pa'::text
62
+ WHEN m.measure_name = 'Náraz a směr větru'::text THEN 'km/h'::text
63
+ WHEN m.measure_name = 'Rychlost a směr větru'::text THEN 'km/h'::text
64
+ WHEN m.measure_name = 'Úhrn srážek'::text THEN 'mm'::text
65
+ WHEN m.measure_name = 'Sluneční svit'::text THEN 'lux'::text
66
+ WHEN m.measure_name = 'Vodní potenciál půdy'::text THEN 'kPa'::text
67
+ WHEN m.measure_name = 'Teplota půdy'::text THEN '°C'::text
68
+ WHEN m.measure_name = 'Obvod stromu'::text THEN 'mm'::text
69
+ WHEN m.measure_name = 'Přírůstek obvodu stromu'::text THEN 'µm'::text
70
+ ELSE NULL::text
71
+ END AS unit,
72
+ m.measure,
73
+ CASE
74
+ WHEN m.measure_name = 'Náraz a směr větru'::text THEN m.wind_dir
75
+ WHEN m.measure_name = 'Rychlost a směr větru'::text THEN m.wind_dir
76
+ ELSE NULL::integer
77
+ END AS measure_wind_dir
78
+ FROM tmp_hights t
79
+ JOIN tmp_measures m ON t.sensor_id::text = m.sensor_id::text AND t.measure = m.measure_name;