@golemio/microclimate 1.1.8 → 1.1.9-dev.901225675

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', '20230613125038-pp20230613-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', '20230613125038-pp20230613-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,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', '20230615113019-pp20230615-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', '20230615113019-pp20230615-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,2 @@
1
+ ALTER TABLE sensor_devices_import ALTER COLUMN data_relevance TYPE varchar(50);
2
+ ALTER TABLE sensor_devices_import ALTER COLUMN data_until TYPE varchar(50);
@@ -0,0 +1,2 @@
1
+ ALTER TABLE sensor_devices_import ALTER COLUMN data_relevance TYPE date USING data_relevance::date;
2
+ ALTER TABLE sensor_devices_import ALTER COLUMN data_until TYPE date USING data_until::date;
@@ -0,0 +1,66 @@
1
+ -- microclimate.v_sensor_measurements source
2
+
3
+ CREATE OR REPLACE VIEW v_sensor_measurements
4
+ AS WITH points_heights AS (
5
+ SELECT s.sensor_id,
6
+ s.point_id,
7
+ s.location_id,
8
+ unpivot.measure,
9
+ unpivot.height_cm,
10
+ CASE
11
+ WHEN unpivot.measure = 'air_temp'::text THEN '°C'::text
12
+ WHEN unpivot.measure = 'air_hum'::text THEN '%'::text
13
+ WHEN unpivot.measure = 'pressure'::text THEN 'Pa'::text
14
+ WHEN unpivot.measure = 'wind_dir'::text THEN '°'::text
15
+ WHEN unpivot.measure = 'wind_impact'::text THEN 'km/h'::text
16
+ WHEN unpivot.measure = 'wind_speed'::text THEN 'km/h'::text
17
+ WHEN unpivot.measure = 'precip'::text THEN 'mm'::text
18
+ WHEN unpivot.measure = 'sun_irr'::text THEN 'lux'::text
19
+ WHEN unpivot.measure = 'soil_temp'::text THEN '°C'::text
20
+ WHEN unpivot.measure = 'water_pot'::text THEN 'kPa'::text
21
+ WHEN unpivot.measure = 'dendro_circ'::text THEN 'mm'::text
22
+ WHEN unpivot.measure = 'dendro_gain'::text THEN 'µm'::text
23
+ ELSE NULL::text
24
+ END AS unit
25
+ FROM sensor_devices_import s,
26
+ LATERAL ( VALUES ('air_temp'::text,s.air_temp), ('air_hum'::text,s.air_hum), ('pressure'::text,s.pressure), ('wind_dir'::text,s.wind_dir), ('wind_impact'::text,s.wind_impact), ('wind_speed'::text,s.wind_speed), ('precip'::text,s.precip), ('sun_irr'::text,s.sun_irr), ('soil_temp'::text,s.soil_temp), ('water_pot'::text,s.water_pot), ('dendro_circ'::text,s.dendro_circ), ('dendro_gain'::text,s.dendro_gain)) unpivot(measure, height_cm)
27
+ WHERE unpivot.height_cm IS NOT NULL
28
+ ), measurements AS (
29
+ SELECT m.sensor_id,
30
+ m.measured_at,
31
+ unpivot.measure,
32
+ unpivot.value
33
+ FROM measurements m,
34
+ LATERAL ( VALUES ('air_temp'::text,m.air_temp), ('air_hum'::text,m.air_hum), ('pressure'::text,m.pressure), ('wind_dir'::text,
35
+ CASE
36
+ WHEN m.wind_dir::text = 'N'::text THEN 0
37
+ WHEN m.wind_dir::text = 'NE'::text THEN 45
38
+ WHEN m.wind_dir::text = 'E'::text THEN 90
39
+ WHEN m.wind_dir::text = 'SE'::text THEN 135
40
+ WHEN m.wind_dir::text = 'S'::text THEN 180
41
+ WHEN m.wind_dir::text = 'SW'::text THEN 225
42
+ WHEN m.wind_dir::text = 'W'::text THEN 270
43
+ WHEN m.wind_dir::text = 'NW'::text THEN 315
44
+ ELSE NULL::integer
45
+ END), ('wind_impact'::text,m.wind_impact), ('wind_speed'::text,m.wind_speed), ('precip'::text,m.precip), ('sun_irr'::text,m.sun_irr), ('soil_temp'::text,m.soil_temp), ('water_pot'::text,m.water_pot), ('dendro_circ'::text,m.dendro_circ), ('dendro_gain'::text,m.dendro_gain)) unpivot(measure, value)
46
+ WHERE unpivot.value IS NOT NULL
47
+ )
48
+ SELECT q.sensor_id,
49
+ q.measured_at,
50
+ q.point_id,
51
+ q.location_id,
52
+ q.measure,
53
+ q.value,
54
+ q.unit,
55
+ row_number() OVER (PARTITION BY q.point_id, q.measure ORDER BY q.point_id, q.measure, q.measured_at DESC) AS rn
56
+ FROM ( SELECT measurements.sensor_id,
57
+ measurements.measured_at,
58
+ points_heights.point_id,
59
+ points_heights.location_id,
60
+ concat(measurements.measure, points_heights.height_cm) AS measure,
61
+ measurements.value,
62
+ points_heights.unit
63
+ FROM measurements
64
+ JOIN points_heights ON points_heights.sensor_id::text = measurements.sensor_id::text AND points_heights.measure = measurements.measure) q
65
+ ORDER BY q.point_id, q.measure, q.measured_at DESC;
66
+
@@ -0,0 +1,69 @@
1
+ CREATE OR REPLACE VIEW v_sensor_measurements
2
+ AS
3
+ WITH points_heights AS (
4
+ SELECT s.sensor_id,
5
+ s.point_id,
6
+ s.location_id,
7
+ unpivot.measure,
8
+ unpivot.height_cm,
9
+ CASE
10
+ WHEN unpivot.measure = 'air_temp'::text THEN '°C'::text
11
+ WHEN unpivot.measure = 'air_hum'::text THEN '%'::text
12
+ WHEN unpivot.measure = 'pressure'::text THEN 'Pa'::text
13
+ WHEN unpivot.measure = 'wind_dir'::text THEN '°'::text
14
+ WHEN unpivot.measure = 'wind_impact'::text THEN 'km/h'::text
15
+ WHEN unpivot.measure = 'wind_speed'::text THEN 'km/h'::text
16
+ WHEN unpivot.measure = 'precip'::text THEN 'mm'::text
17
+ WHEN unpivot.measure = 'sun_irr'::text THEN 'lux'::text
18
+ WHEN unpivot.measure = 'soil_temp'::text THEN '°C'::text
19
+ WHEN unpivot.measure = 'water_pot'::text THEN 'kPa'::text
20
+ WHEN unpivot.measure = 'dendro_circ'::text THEN 'mm'::text
21
+ WHEN unpivot.measure = 'dendro_gain'::text THEN 'µm'::text
22
+ ELSE NULL::text
23
+ END AS unit
24
+ FROM sensor_devices_import s,
25
+ LATERAL ( VALUES ('air_temp'::text,s.air_temp), ('air_hum'::text,s.air_hum), ('pressure'::text,s.pressure), ('wind_dir'::text,s.wind_dir), ('wind_impact'::text,s.wind_impact), ('wind_speed'::text,s.wind_speed), ('precip'::text,s.precip), ('sun_irr'::text,s.sun_irr), ('soil_temp'::text,s.soil_temp), ('water_pot'::text,s.water_pot), ('dendro_circ'::text,s.dendro_circ), ('dendro_gain'::text,s.dendro_gain)) unpivot(measure, height_cm)
26
+ WHERE unpivot.height_cm IS NOT NULL
27
+ ), measurements AS (
28
+ SELECT m.sensor_id,
29
+ m.measured_at,
30
+ unpivot.measure,
31
+ unpivot.value
32
+ FROM measurements m
33
+ join sensor_devices_import sdi
34
+ on sdi.sensor_id = m.sensor_id
35
+ and m.measured_at::date >= sdi.data_relevance::date
36
+ and m.measured_at::date <= coalesce(sdi.data_until::date,current_date)
37
+ ,
38
+ LATERAL ( VALUES ('air_temp'::text,m.air_temp), ('air_hum'::text,m.air_hum), ('pressure'::text,m.pressure), ('wind_dir'::text,
39
+ CASE
40
+ WHEN m.wind_dir::text = 'N'::text THEN 0
41
+ WHEN m.wind_dir::text = 'NE'::text THEN 45
42
+ WHEN m.wind_dir::text = 'E'::text THEN 90
43
+ WHEN m.wind_dir::text = 'SE'::text THEN 135
44
+ WHEN m.wind_dir::text = 'S'::text THEN 180
45
+ WHEN m.wind_dir::text = 'SW'::text THEN 225
46
+ WHEN m.wind_dir::text = 'W'::text THEN 270
47
+ WHEN m.wind_dir::text = 'NW'::text THEN 315
48
+ ELSE NULL::integer
49
+ END), ('wind_impact'::text,m.wind_impact), ('wind_speed'::text,m.wind_speed), ('precip'::text,m.precip), ('sun_irr'::text,m.sun_irr), ('soil_temp'::text,m.soil_temp), ('water_pot'::text,m.water_pot), ('dendro_circ'::text,m.dendro_circ), ('dendro_gain'::text,m.dendro_gain)) unpivot(measure, value)
50
+ WHERE unpivot.value IS NOT NULL
51
+ )
52
+ SELECT q.sensor_id,
53
+ q.measured_at,
54
+ q.point_id,
55
+ q.location_id,
56
+ q.measure,
57
+ q.value,
58
+ q.unit,
59
+ row_number() OVER (PARTITION BY q.point_id, q.measure ORDER BY q.point_id, q.measure, q.measured_at DESC) AS rn
60
+ FROM ( SELECT measurements.sensor_id,
61
+ measurements.measured_at,
62
+ points_heights.point_id,
63
+ points_heights.location_id,
64
+ concat(measurements.measure, points_heights.height_cm) AS measure,
65
+ measurements.value,
66
+ points_heights.unit
67
+ FROM measurements
68
+ JOIN points_heights ON points_heights.sensor_id::text = measurements.sensor_id::text AND points_heights.measure = measurements.measure) q
69
+ ORDER BY q.point_id, q.measure, q.measured_at DESC;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/microclimate",
3
- "version": "1.1.8",
3
+ "version": "1.1.9-dev.901225675",
4
4
  "description": "Golemio Microclimate Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",