@golemio/microclimate 1.1.3-dev.791163543 → 1.1.3-dev.793877555
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.
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dbm;
|
|
4
|
+
var type;
|
|
5
|
+
var seed;
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var Promise;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* We receive the dbmigrate dependency from dbmigrate initially.
|
|
12
|
+
* This enables us to not have to rely on NODE_PATH.
|
|
13
|
+
*/
|
|
14
|
+
exports.setup = function(options, seedLink) {
|
|
15
|
+
dbm = options.dbmigrate;
|
|
16
|
+
type = dbm.dataType;
|
|
17
|
+
seed = seedLink;
|
|
18
|
+
Promise = options.Promise;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.up = function(db) {
|
|
22
|
+
var filePath = path.join(__dirname, 'sqls', '20230302073548-view-raw-data-up.sql');
|
|
23
|
+
return new Promise( function( resolve, reject ) {
|
|
24
|
+
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
25
|
+
if (err) return reject(err);
|
|
26
|
+
console.log('received data: ' + data);
|
|
27
|
+
|
|
28
|
+
resolve(data);
|
|
29
|
+
});
|
|
30
|
+
})
|
|
31
|
+
.then(function(data) {
|
|
32
|
+
return db.runSql(data);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.down = function(db) {
|
|
37
|
+
var filePath = path.join(__dirname, 'sqls', '20230302073548-view-raw-data-down.sql');
|
|
38
|
+
return new Promise( function( resolve, reject ) {
|
|
39
|
+
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
40
|
+
if (err) return reject(err);
|
|
41
|
+
console.log('received data: ' + data);
|
|
42
|
+
|
|
43
|
+
resolve(data);
|
|
44
|
+
});
|
|
45
|
+
})
|
|
46
|
+
.then(function(data) {
|
|
47
|
+
return db.runSql(data);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports._meta = {
|
|
52
|
+
"version": 1
|
|
53
|
+
};
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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;
|