@golemio/microclimate 1.1.2 → 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.
Files changed (55) hide show
  1. package/db/example/00_truncate_tables.sql +2 -2
  2. package/db/example/01_microclimate.sql +44 -2
  3. package/db/migrations/postgresql/20230215185618-og-api.js +53 -0
  4. package/db/migrations/postgresql/20230302073548-view-raw-data.js +53 -0
  5. package/db/migrations/postgresql/sqls/20230215185618-og-api-down.sql +5 -0
  6. package/db/migrations/postgresql/sqls/20230215185618-og-api-up.sql +167 -0
  7. package/db/migrations/postgresql/sqls/20230302073548-view-raw-data-down.sql +20 -0
  8. package/db/migrations/postgresql/sqls/20230302073548-view-raw-data-up.sql +79 -0
  9. package/dist/output-gateway/MicroclimateRouter.d.ts +4 -0
  10. package/dist/output-gateway/MicroclimateRouter.js +85 -0
  11. package/dist/output-gateway/MicroclimateRouter.js.map +1 -0
  12. package/dist/output-gateway/helpers/LocationsOutputMapper.d.ts +18 -0
  13. package/dist/output-gateway/helpers/LocationsOutputMapper.js +35 -0
  14. package/dist/output-gateway/helpers/LocationsOutputMapper.js.map +1 -0
  15. package/dist/output-gateway/helpers/PointsOutputMapper.d.ts +27 -0
  16. package/dist/output-gateway/helpers/PointsOutputMapper.js +45 -0
  17. package/dist/output-gateway/helpers/PointsOutputMapper.js.map +1 -0
  18. package/dist/output-gateway/index.d.ts +1 -0
  19. package/dist/output-gateway/index.js +18 -0
  20. package/dist/output-gateway/index.js.map +1 -0
  21. package/dist/output-gateway/repositories/SensorDevicesImportRepository.d.ts +19 -0
  22. package/dist/output-gateway/repositories/SensorDevicesImportRepository.js +55 -0
  23. package/dist/output-gateway/repositories/SensorDevicesImportRepository.js.map +1 -0
  24. package/dist/output-gateway/repositories/SensorMeasurementsViewRepository.d.ts +16 -0
  25. package/dist/output-gateway/repositories/SensorMeasurementsViewRepository.js +49 -0
  26. package/dist/output-gateway/repositories/SensorMeasurementsViewRepository.js.map +1 -0
  27. package/dist/output-gateway/repositories/SensorPointsViewRepository.d.ts +11 -0
  28. package/dist/output-gateway/repositories/SensorPointsViewRepository.js +43 -0
  29. package/dist/output-gateway/repositories/SensorPointsViewRepository.js.map +1 -0
  30. package/dist/output-gateway/repositories/index.d.ts +3 -0
  31. package/dist/output-gateway/repositories/index.js +20 -0
  32. package/dist/output-gateway/repositories/index.js.map +1 -0
  33. package/dist/schema-definitions/SensorDevicesImport.d.ts +33 -0
  34. package/dist/schema-definitions/SensorDevicesImport.js +8 -0
  35. package/dist/schema-definitions/SensorDevicesImport.js.map +1 -0
  36. package/dist/schema-definitions/SensorMeasurementsView.d.ts +13 -0
  37. package/dist/schema-definitions/SensorMeasurementsView.js +8 -0
  38. package/dist/schema-definitions/SensorMeasurementsView.js.map +1 -0
  39. package/dist/schema-definitions/SensorPointsView.d.ts +23 -0
  40. package/dist/schema-definitions/SensorPointsView.js +8 -0
  41. package/dist/schema-definitions/SensorPointsView.js.map +1 -0
  42. package/dist/schema-definitions/index.js +6 -0
  43. package/dist/schema-definitions/index.js.map +1 -1
  44. package/dist/schema-definitions/models/SensorDevicesImportModel.d.ts +32 -0
  45. package/dist/schema-definitions/models/SensorDevicesImportModel.js +37 -0
  46. package/dist/schema-definitions/models/SensorDevicesImportModel.js.map +1 -0
  47. package/dist/schema-definitions/models/SensorMeasurementsViewModel.d.ts +12 -0
  48. package/dist/schema-definitions/models/SensorMeasurementsViewModel.js +17 -0
  49. package/dist/schema-definitions/models/SensorMeasurementsViewModel.js.map +1 -0
  50. package/dist/schema-definitions/models/SensorPointsViewModel.d.ts +22 -0
  51. package/dist/schema-definitions/models/SensorPointsViewModel.js +27 -0
  52. package/dist/schema-definitions/models/SensorPointsViewModel.js.map +1 -0
  53. package/docs/implementation_documentation.md +20 -1
  54. package/docs/openapi.yaml +298 -0
  55. package/package.json +2 -2
@@ -1,2 +1,2 @@
1
- -- TRUNCATE "sensor_devices";
2
- -- TRUNCATE "measurements";
1
+ TRUNCATE "sensor_devices_import";
2
+ TRUNCATE "measurements";
@@ -1,2 +1,44 @@
1
- -- INSERT INTO sensor_devices ...
2
- -- INSERT INTO measurements ...
1
+ INSERT INTO sensor_devices_import (location_id, point_id, location, loc_description, loc_orientation, loc_surface, point_name, point_whole_name, address, sensor_position, sensor_position_detail, sensor_id, data_relevance, lat, lng, air_temp, air_hum, pressure, wind_dir, wind_impact, wind_speed, precip, sun_irr, soil_temp, water_pot, dendro_circ, dendro_gain) VALUES
2
+ (130, 131, 'Pražská Holešovická tržnice', 'areál bez zeleně', 'východ-západ', 'asfalt/beton', 'Pražská tržnice osvětlení', 'Tržnice | sloup VO | 0,5m | #063', 'Pražská tržnice', 'veřejné osvětlení', 'veřejné osvětlení ve středu Tržnice', '323434316F317A18', '2022-08-11', 50.098934, 14.445023, 50, 50, 50, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
3
+ (130, 131, 'Pražská Holešovická tržnice', 'areál bez zeleně', 'východ-západ', 'asfalt/beton', 'Pražská tržnice osvětlení', 'Tržnice | sloup VO | 2m | #0190', 'Pražská tržnice', 'veřejné osvětlení', 'veřejné osvětlení ve středu Tržnice', '323434317F317F18', '2022-08-11', 50.098934, 14.445023, 200, 200, 200, 300, 300, 300, 300, 200, NULL, NULL, NULL, NULL),
4
+ (130, 132, 'Pražská Holešovická tržnice', 'areál bez zeleně', 'východ-západ', 'asfalt/beton', 'Pražská tržnice jižní strom', 'Tržnice | jižní strom | -0,3cm | #046', 'Pražská tržnice', 'strom', 'jižní strom', '323434316A317519', '2022-08-11', 50.098816, 14.445016, 50, 50, 50, NULL, NULL, NULL, NULL, NULL, -30, -30, 200, 200),
5
+ (130, 132, 'Pražská Holešovická tržnice', 'areál bez zeleně', 'východ-západ', 'asfalt/beton', 'Pražská tržnice jižní strom', 'Tržnice | jižní strom | -0,1cm | #080', 'Pražská tržnice', 'strom', 'jižní strom', '3234343178318318', '2022-08-11', 50.098816, 14.445016, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -10, -10, NULL, NULL),
6
+ (130, 133, 'Pražská Holešovická tržnice', 'areál bez zeleně', 'východ-západ', 'asfalt/beton', 'Pražská tržnice severní strom', 'Tržnice | severní strom | -0,3cm | #097', 'Pražská tržnice', 'strom', 'severní strom', '3234343177317318', '2022-08-11', 50.099163, 14.444832, 50, 50, 50, NULL, NULL, NULL, NULL, NULL, -30, -30, 200, 200),
7
+ (130, 133, 'Pražská Holešovická tržnice', 'areál bez zeleně', 'východ-západ', 'asfalt/beton', 'Pražská tržnice severní strom', 'Tržnice | severní strom | -0,1cm | #0102', 'Pražská tržnice', 'strom', 'severní strom', '3234343176317918', '2022-08-11', 50.099163, 14.444832, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -10, -10, NULL, NULL);
8
+
9
+ INSERT INTO measurements (sensor_id, measurement_id, measured_at, air_temp, air_hum, pressure, wind_dir, wind_speed, wind_impact, precip, sun_irr, dendro_circ, dendro_gain, water_pot, soil_temp) VALUES
10
+ ('323434316F317A18', '63edfacd96553b2cde597624', '2023-02-16 10:43:41.682+01', 4, 73.4, 100470, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
11
+ ('3234343177317318', '63edfba096553b2cde59774d', '2023-02-16 10:47:12.006+01', 4.9, 67, 100470, NULL, NULL, NULL, NULL, NULL, 988.662532552085, -1.33746744791533, -9.039, 3.2),
12
+ ('3234343178318318', '63edfb0d96553b2cde597674', '2023-02-16 10:44:45.053+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -9.8572, 0.5),
13
+ ('3234343176317918', '63edfb1796553b2cde597688', '2023-02-16 10:44:55.455+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -4.62828, 2.7),
14
+ ('323434317F317F18', '63edfc1c96553b2cde5977fe', '2023-02-16 10:49:15.914+01', 2.2, 78.5, 100470, 'N', 1.42795716128516, 7.2405, 0, 11382, NULL, NULL, NULL, NULL),
15
+ ('323434316A317519', '63edfc1696553b2cde5977f4', '2023-02-16 10:49:10.307+01', 1.9, 77.2, 100470, NULL, NULL, NULL, NULL, NULL, 548.06648763021, -1.93351236978973, -13.013, 2.7),
16
+ ('323434316F317A18', '63edfd2596553b2cde597975', '2023-02-16 10:53:41.695+01', 2.8, 77.4, 100480, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
17
+ ('3234343176317918', '63edfd6f96553b2cde5979e8', '2023-02-16 10:54:55.462+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -4.62828, 2.8),
18
+ ('3234343178318318', '63edfd6596553b2cde5979d2', '2023-02-16 10:54:45.064+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -9.8572, 0.5),
19
+ ('323434316A317519', '63edfe6e96553b2cde597b49', '2023-02-16 10:59:10.325+01', 2.2, 76.4, 100460, NULL, NULL, NULL, NULL, NULL, 548.077473958335, -1.92252604166475, -13.013, 2.7),
20
+ ('323434317F317F18', '63edfe7496553b2cde597b53', '2023-02-16 10:59:15.92+01', 2.5, 77.6, 100460, 'N', 2.1519784802152, 6.51645, 0, 11127, NULL, NULL, NULL, NULL),
21
+ ('3234343178318318', '63edf1ad96553b2cde5968e5', '2023-02-16 10:04:44.999+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -9.8572, 0.5),
22
+ ('3234343176317918', '63edf1b796553b2cde5968f1', '2023-02-16 10:04:55.417+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -4.62828, 2.3),
23
+ ('323434316F317A18', '63edf16d96553b2cde596883', '2023-02-16 10:03:41.636+01', 2.3, 80.8, 100480, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
24
+ ('323434317F317F18', '63edf2bc96553b2cde596a5f', '2023-02-16 10:09:15.875+01', 1.9, 80.1, 100470, 'E', 0.983975400614985, 5.06835, 0, 10383, NULL, NULL, NULL, NULL),
25
+ ('323434316A317519', '63edf2b696553b2cde596a5b', '2023-02-16 10:09:10.267+01', 0.7, 82.7, 100470, NULL, NULL, NULL, NULL, NULL, 548.062825520835, -1.93717447916473, -13.013, 2.7),
26
+ ('3234343177317318', '63edf24096553b2cde5969b8', '2023-02-16 10:07:11.976+01', 2.5, 76.7, 100480, NULL, NULL, NULL, NULL, NULL, 988.625911458335, -1.37408854166529, -9.94292, 3.2),
27
+ ('323434316F317A18', '63edf3c596553b2cde596be1', '2023-02-16 10:13:41.643+01', 1.9, 81.9, 100490, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
28
+ ('3234343176317918', '63edf40f96553b2cde596c4b', '2023-02-16 10:14:55.484+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -4.54256, 2.4),
29
+ ('3234343178318318', '63edf40596553b2cde596c36', '2023-02-16 10:14:45.016+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -9.8572, 0.5),
30
+ ('3234343177317318', '63edf49896553b2cde596d18', '2023-02-16 10:17:11.979+01', 2.7, 73.9, 100480, NULL, NULL, NULL, NULL, NULL, 988.62224934896, -1.37775065104029, -10.02864, 3.2),
31
+ ('323434316A317519', '63edf50e96553b2cde596dca', '2023-02-16 10:19:10.267+01', 1, 81.4, 100470, NULL, NULL, NULL, NULL, NULL, 548.062825520835, -1.93717447916473, -13.013, 2.7),
32
+ ('323434317F317F18', '63edf51496553b2cde596dd0', '2023-02-16 10:19:15.882+01', 1.4, 82.1, 100470, 'S', 1.30798474017803, 4.3443, 0, 10680, NULL, NULL, NULL, NULL),
33
+ ('3234343177317318', '63edf6f096553b2cde597098', '2023-02-16 10:27:11.99+01', 2.4, 76, 100480, NULL, NULL, NULL, NULL, NULL, 988.625911458335, -1.37408854166529, -10.11436, 3.2),
34
+ ('323434316F317A18', '63edf61d96553b2cde596f57', '2023-02-16 10:23:41.655+01', 2.3, 81.1, 100480, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
35
+ ('3234343178318318', '63edf65d96553b2cde596fb4', '2023-02-16 10:24:45.037+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -9.8572, 0.5),
36
+ ('3234343176317918', '63edf66796553b2cde596fcb', '2023-02-16 10:24:55.442+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -4.714, 2.4),
37
+ ('323434317F317F18', '63edf76c96553b2cde597134', '2023-02-16 10:29:15.889+01', 2.1, 80.2, 100470, 'SE', 1.20798590683109, 4.3443, 0, 11099, NULL, NULL, NULL, NULL),
38
+ ('323434316A317519', '63edf76696553b2cde59712d', '2023-02-16 10:29:10.286+01', 1.3, 80.5, 100470, NULL, NULL, NULL, NULL, NULL, 548.06648763021, -1.93351236978973, -13.013, 2.7),
39
+ ('3234343176317918', '63edf8bf96553b2cde597326', '2023-02-16 10:34:55.45+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -4.62828, 2.5),
40
+ ('3234343178318318', '63edf8b596553b2cde597318', '2023-02-16 10:34:45.036+01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -9.8572, 0.5),
41
+ ('323434316F317A18', '63edf87596553b2cde5972b6', '2023-02-16 10:33:41.668+01', 2.8, 79.3, 100470, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
42
+ ('323434316A317519', '63edf9be96553b2cde597491', '2023-02-16 10:39:10.302+01', 1.7, 79.2, 100470, NULL, NULL, NULL, NULL, NULL, 548.06648763021, -1.93351236978973, -13.013, 2.7),
43
+ ('323434317F317F18', '63edf9c496553b2cde597499', '2023-02-16 10:39:15.896+01', 3.2, 76.3, 100460, 'N', 0.487994306733088, 2.17215, 0, 11286, NULL, NULL, NULL, NULL),
44
+ ('3234343177317318', '63edf94896553b2cde5973ee', '2023-02-16 10:37:11.994+01', 3.9, 71.5, 100470, NULL, NULL, NULL, NULL, NULL, 988.63689778646, -1.3631022135403, -10.11436, 3.2);
@@ -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', '20230215185618-og-api-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', '20230215185618-og-api-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', '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,5 @@
1
+ DROP VIEW IF EXISTS v_sensor_points;
2
+ DROP VIEW IF EXISTS v_sensor_measurements;
3
+
4
+ DROP INDEX measured_at_idx;
5
+ DROP INDEX sensor_id_idx;
@@ -0,0 +1,167 @@
1
+ /**
2
+ v_sensor_points view for output api
3
+ **/
4
+ CREATE OR REPLACE VIEW v_sensor_points AS
5
+ SELECT DISTINCT
6
+ s.point_id,
7
+ s.point_name,
8
+ s.location_id,
9
+ s.location,
10
+ s.loc_description,
11
+ s.loc_orientation,
12
+ s.loc_surface,
13
+ s.lat,
14
+ s.lng,
15
+ null AS x_jtsk, -- bude doplneno na s.x_jtsk
16
+ null AS y_jtsk, -- bude doplneno
17
+ null AS elevation_m, -- bude doplneno
18
+ s.sensor_position,
19
+ s.sensor_position_detail,
20
+ CONCAT(unpivot.measure, unpivot.height_cm) AS measure,
21
+ CASE
22
+ WHEN unpivot.measure = 'air_temp' THEN 'Teplota vzduchu'
23
+ WHEN unpivot.measure = 'air_hum' THEN 'Vlhkost vzduchu'
24
+ WHEN unpivot.measure = 'pressure' THEN 'Atmosférický tlak'
25
+ WHEN unpivot.measure = 'wind_dir' THEN 'Směr větru'
26
+ WHEN unpivot.measure = 'wind_impact' THEN 'Náraz větru'
27
+ WHEN unpivot.measure = 'wind_speed' THEN 'Rychlost větru'
28
+ WHEN unpivot.measure = 'precip' THEN 'Úhrn srážek'
29
+ WHEN unpivot.measure = 'sun_irr' THEN 'Sluneční záření'
30
+ WHEN unpivot.measure = 'soil_temp' THEN 'Teplota půdy'
31
+ WHEN unpivot.measure = 'water_pot' THEN 'Vodní potenciál půdy'
32
+ WHEN unpivot.measure = 'dendro_circ' THEN 'Obvod stromu'
33
+ WHEN unpivot.measure = 'dendro_gain' THEN 'Přírůstek obvodu stromu'
34
+ ELSE NULL
35
+ END AS measure_cz,
36
+ CASE
37
+ WHEN unpivot.measure = 'air_temp' THEN '°C'
38
+ WHEN unpivot.measure = 'air_hum' THEN '%'
39
+ WHEN unpivot.measure = 'pressure' THEN 'Pa'
40
+ WHEN unpivot.measure = 'wind_dir' THEN '°'
41
+ WHEN unpivot.measure = 'wind_impact' THEN 'km/h'
42
+ WHEN unpivot.measure = 'wind_speed' THEN 'km/h'
43
+ WHEN unpivot.measure = 'precip' THEN 'mm'
44
+ WHEN unpivot.measure = 'sun_irr' THEN 'lux'
45
+ WHEN unpivot.measure = 'soil_temp' THEN '°C'
46
+ WHEN unpivot.measure = 'water_pot' THEN 'kPa'
47
+ WHEN unpivot.measure = 'dendro_circ' THEN 'mm'
48
+ WHEN unpivot.measure = 'dendro_gain' THEN 'µm'
49
+ ELSE NULL
50
+ END AS unit
51
+ FROM
52
+ sensor_devices_import s,
53
+ LATERAL (
54
+ VALUES ('air_temp',s.air_temp),
55
+ ('air_hum',s.air_hum),
56
+ ('pressure',s.pressure),
57
+ ('wind_dir',s.wind_dir),
58
+ ('wind_impact',s.wind_impact),
59
+ ('wind_speed',s.wind_speed),
60
+ ('precip',s.precip),
61
+ ('sun_irr',s.sun_irr),
62
+ ('soil_temp',s.soil_temp),
63
+ ('water_pot',s.water_pot),
64
+ ('dendro_circ',s.dendro_circ),
65
+ ('dendro_gain',s.dendro_gain)
66
+ )
67
+ unpivot(measure, height_cm)
68
+ WHERE height_cm is not null
69
+ ORDER BY point_id ASC;
70
+
71
+
72
+ /**
73
+ v_sensor_measurements view for output api
74
+ **/
75
+ CREATE OR REPLACE VIEW v_sensor_measurements AS
76
+ WITH points_heights AS (
77
+ SELECT
78
+ s.sensor_id,
79
+ s.point_id,
80
+ s.location_id,
81
+ unpivot.measure,
82
+ unpivot.height_cm,
83
+ CASE
84
+ WHEN unpivot.measure = 'air_temp' THEN '°C'
85
+ WHEN unpivot.measure = 'air_hum' THEN '%'
86
+ WHEN unpivot.measure = 'pressure' THEN 'Pa'
87
+ WHEN unpivot.measure = 'wind_dir' THEN '°'
88
+ WHEN unpivot.measure = 'wind_impact' THEN 'km/h'
89
+ WHEN unpivot.measure = 'wind_speed' THEN 'km/h'
90
+ WHEN unpivot.measure = 'precip' THEN 'mm'
91
+ WHEN unpivot.measure = 'sun_irr' THEN 'lux'
92
+ WHEN unpivot.measure = 'soil_temp' THEN '°C'
93
+ WHEN unpivot.measure = 'water_pot' THEN 'kPa'
94
+ WHEN unpivot.measure = 'dendro_circ' THEN 'mm'
95
+ WHEN unpivot.measure = 'dendro_gain' THEN 'µm'
96
+ ELSE NULL
97
+ END AS unit
98
+ FROM
99
+ sensor_devices_import s,
100
+ LATERAL (
101
+ VALUES ('air_temp',s.air_temp),
102
+ ('air_hum',s.air_hum),
103
+ ('pressure',s.pressure),
104
+ ('wind_dir',s.wind_dir),
105
+ ('wind_impact',s.wind_impact),
106
+ ('wind_speed',s.wind_speed),
107
+ ('precip',s.precip),
108
+ ('sun_irr',s.sun_irr),
109
+ ('soil_temp',s.soil_temp),
110
+ ('water_pot',s.water_pot),
111
+ ('dendro_circ',s.dendro_circ),
112
+ ('dendro_gain',s.dendro_gain)
113
+ )
114
+ unpivot(measure, height_cm)
115
+ WHERE height_cm IS NOT NULL
116
+ ),
117
+ measurements AS (
118
+ SELECT
119
+ m.sensor_id,
120
+ m.measured_at,
121
+ unpivot.measure,
122
+ unpivot.value
123
+ FROM
124
+ measurements m,
125
+ LATERAL (
126
+ VALUES
127
+ ('air_temp',m.air_temp),
128
+ ('air_hum',m.air_hum),
129
+ ('pressure',m.pressure),
130
+ ('wind_dir', CASE
131
+ WHEN m.wind_dir = 'N' THEN 0
132
+ WHEN m.wind_dir = 'NE' THEN 45
133
+ WHEN m.wind_dir = 'E' THEN 90
134
+ WHEN m.wind_dir = 'SE' THEN 135
135
+ WHEN m.wind_dir = 'S' THEN 180
136
+ WHEN m.wind_dir = 'SW' THEN 225
137
+ WHEN m.wind_dir = 'W' THEN 270
138
+ WHEN m.wind_dir = 'NW' THEN 315
139
+ ELSE NULL END),
140
+ ('wind_impact',m.wind_impact),
141
+ ('wind_speed',m.wind_speed),
142
+ ('precip',m.precip),
143
+ ('sun_irr',m.sun_irr),
144
+ ('soil_temp',m.soil_temp),
145
+ ('water_pot',m.water_pot),
146
+ ('dendro_circ',m.dendro_circ),
147
+ ('dendro_gain',m.dendro_gain)
148
+ )
149
+ unpivot(measure, value)
150
+ WHERE value IS NOT NULL
151
+ )
152
+ SELECT
153
+ measurements.sensor_id,
154
+ measurements.measured_at,
155
+ points_heights.point_id,
156
+ points_heights.location_id,
157
+ CONCAT(measurements.measure, points_heights.height_cm) AS measure,
158
+ measurements.value,
159
+ points_heights.unit
160
+ FROM measurements
161
+ JOIN points_heights
162
+ ON points_heights.sensor_id = measurements.sensor_id
163
+ AND points_heights.measure = measurements.measure
164
+ ORDER BY measured_at DESC, point_id ASC;
165
+
166
+ CREATE INDEX measured_at_idx ON measurements (measured_at DESC);
167
+ CREATE INDEX sensor_id_idx ON measurements (sensor_id);
@@ -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;
@@ -0,0 +1,4 @@
1
+ /// <reference types="express" />
2
+ import { Router } from "@golemio/core/dist/shared/express";
3
+ declare const microclimateRouter: Router;
4
+ export { microclimateRouter };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.microclimateRouter = void 0;
13
+ const express_1 = require("@golemio/core/dist/shared/express");
14
+ const express_validator_1 = require("@golemio/core/dist/shared/express-validator");
15
+ const BaseRouter_1 = require("@golemio/core/dist/output-gateway/routes/BaseRouter");
16
+ const output_gateway_1 = require("@golemio/core/dist/output-gateway");
17
+ const repositories_1 = require("./repositories");
18
+ const LocationsOutputMapper_1 = require("./helpers/LocationsOutputMapper");
19
+ const SensorPointsViewRepository_1 = require("./repositories/SensorPointsViewRepository");
20
+ const SensorMeasurementsViewRepository_1 = require("./repositories/SensorMeasurementsViewRepository");
21
+ const PointsOutputMapper_1 = require("./helpers/PointsOutputMapper");
22
+ class MicroclimateRouter extends BaseRouter_1.BaseRouter {
23
+ constructor() {
24
+ super();
25
+ this.router = (0, express_1.Router)();
26
+ this.getLocations = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
27
+ try {
28
+ const data = yield this.sensorDevicesImportRepository.GetAllDistinctLocations({
29
+ locationId: req.query.locationId ? Number(req.query.locationId) : undefined,
30
+ });
31
+ res.status(200).send(LocationsOutputMapper_1.LocationsOutputMapper.locationsMapper(data));
32
+ }
33
+ catch (err) {
34
+ next(err);
35
+ }
36
+ });
37
+ this.getPoints = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
38
+ try {
39
+ const data = yield this.sensorPointsViewRepository.GetAllPoints({
40
+ locationId: req.query.locationId ? Number(req.query.locationId) : undefined,
41
+ pointId: req.query.pointId ? Number(req.query.pointId) : undefined,
42
+ });
43
+ res.status(200).send(PointsOutputMapper_1.PointsOutputMapper.pointsMapper(data));
44
+ }
45
+ catch (err) {
46
+ next(err);
47
+ }
48
+ });
49
+ this.getMeasurements = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ const data = yield this.sensorMeasurementsViewRepository.GetAllMeasurements({
52
+ locationId: req.query.locationId ? Number(req.query.locationId) : undefined,
53
+ pointId: req.query.pointId ? Number(req.query.pointId) : undefined,
54
+ measure: req.query.measure,
55
+ from: req.query.from,
56
+ to: req.query.to,
57
+ limit: req.query.limit ? Number(req.query.limit) : undefined,
58
+ offset: req.query.offset ? Number(req.query.offset) : undefined,
59
+ });
60
+ res.status(200).send(data);
61
+ }
62
+ catch (err) {
63
+ next(err);
64
+ }
65
+ });
66
+ this.initRoutes = () => {
67
+ this.router.get("/locations", [(0, express_validator_1.query)("locationId'").optional().isInt()], output_gateway_1.checkErrors, (0, output_gateway_1.useCacheMiddleware)(), this.getLocations);
68
+ this.router.get("/points", [(0, express_validator_1.query)("locationId'").optional().isInt(), (0, express_validator_1.query)("pointId").optional().isInt()], output_gateway_1.checkErrors, (0, output_gateway_1.useCacheMiddleware)(), this.getPoints);
69
+ this.router.get("/measurements", [
70
+ (0, express_validator_1.query)("locationId'").optional().isInt(),
71
+ (0, express_validator_1.query)("pointId").optional().isInt(),
72
+ (0, express_validator_1.query)("measure").optional().isString(),
73
+ (0, express_validator_1.query)("from").optional().isISO8601(),
74
+ (0, express_validator_1.query)("to").optional().isISO8601(),
75
+ ], output_gateway_1.pagination, output_gateway_1.checkErrors, (0, output_gateway_1.useCacheMiddleware)(), this.getMeasurements);
76
+ };
77
+ this.sensorDevicesImportRepository = new repositories_1.SensorDevicesImportRepository();
78
+ this.sensorPointsViewRepository = new SensorPointsViewRepository_1.SensorPointsViewRepository();
79
+ this.sensorMeasurementsViewRepository = new SensorMeasurementsViewRepository_1.SensorMeasurementsViewRepository();
80
+ this.initRoutes();
81
+ }
82
+ }
83
+ const microclimateRouter = new MicroclimateRouter().router;
84
+ exports.microclimateRouter = microclimateRouter;
85
+ //# sourceMappingURL=MicroclimateRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicroclimateRouter.js","sourceRoot":"","sources":["../../src/output-gateway/MicroclimateRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA4F;AAC5F,mFAAoE;AACpE,oFAAiF;AACjF,sEAAgG;AAChG,iDAAiE;AACjE,2EAA0E;AAC1E,0FAAyF;AACzF,sGAAqG;AACrG,qEAAoE;AAEpE,MAAM,kBAAmB,SAAQ,u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0 +1,18 @@
1
+ import { ILocationRecord } from "../repositories";
2
+ interface IPointOutput {
3
+ point_id: number;
4
+ point_name: string;
5
+ }
6
+ export interface ILocationOutput {
7
+ location_id: number;
8
+ location: string;
9
+ loc_description: string;
10
+ loc_orientation: string;
11
+ loc_surface: string;
12
+ address: string;
13
+ points: IPointOutput[];
14
+ }
15
+ export declare class LocationsOutputMapper {
16
+ static locationsMapper: (records: ILocationRecord[]) => ILocationOutput[];
17
+ }
18
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocationsOutputMapper = void 0;
4
+ class LocationsOutputMapper {
5
+ }
6
+ exports.LocationsOutputMapper = LocationsOutputMapper;
7
+ LocationsOutputMapper.locationsMapper = (records) => {
8
+ const locationMap = {};
9
+ for (const record of records) {
10
+ if (locationMap[record.location_id]) {
11
+ locationMap[record.location_id].points.push({
12
+ point_id: record.point_id,
13
+ point_name: record.point_name,
14
+ });
15
+ }
16
+ else {
17
+ locationMap[record.location_id] = {
18
+ location_id: record.location_id,
19
+ location: record.location,
20
+ loc_description: record.loc_description,
21
+ loc_orientation: record.loc_orientation,
22
+ loc_surface: record.loc_surface,
23
+ address: record.address,
24
+ points: [
25
+ {
26
+ point_id: record.point_id,
27
+ point_name: record.point_name,
28
+ },
29
+ ],
30
+ };
31
+ }
32
+ }
33
+ return Object.values(locationMap);
34
+ };
35
+ //# sourceMappingURL=LocationsOutputMapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocationsOutputMapper.js","sourceRoot":"","sources":["../../../src/output-gateway/helpers/LocationsOutputMapper.ts"],"names":[],"mappings":";;;AAiBA,MAAa,qBAAqB;;AAAlC,sDA6BC;AA5BiB,qCAAe,GAAG,CAAC,OAA0B,EAAqB,EAAE;IAC9E,MAAM,WAAW,GAAoC,EAAE,CAAC;IACxD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC1B,IAAI,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;YACjC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBACxC,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,UAAU,EAAE,MAAM,CAAC,UAAU;aAChC,CAAC,CAAC;SACN;aAAM;YACH,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG;gBAC9B,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,eAAe,EAAE,MAAM,CAAC,eAAe;gBACvC,eAAe,EAAE,MAAM,CAAC,eAAe;gBACvC,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,MAAM,EAAE;oBACJ;wBACI,QAAQ,EAAE,MAAM,CAAC,QAAQ;wBACzB,UAAU,EAAE,MAAM,CAAC,UAAU;qBAChC;iBACJ;aACJ,CAAC;SACL;KACJ;IAED,OAAO,MAAM,CAAC,MAAM,CAAkB,WAAW,CAAC,CAAC;AACvD,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { ISensorPointsView } from "../../schema-definitions/SensorPointsView";
2
+ interface ISensorPointsViewMeasurementOutput {
3
+ measure: string;
4
+ measure_cz: string;
5
+ unit: string;
6
+ }
7
+ export interface ISensorPointsViewOutput {
8
+ point_id: number;
9
+ location_id: number;
10
+ point_name: string;
11
+ location: string;
12
+ loc_description: string;
13
+ loc_orientation: string;
14
+ loc_surface: string;
15
+ lat: number;
16
+ lng: number;
17
+ x_jtsk: number | null;
18
+ y_jtsk: number | null;
19
+ elevation_m: number | null;
20
+ measures: ISensorPointsViewMeasurementOutput[];
21
+ sensor_position: string;
22
+ sensor_position_detail: string;
23
+ }
24
+ export declare class PointsOutputMapper {
25
+ static pointsMapper: (records: ISensorPointsView[]) => ISensorPointsViewOutput[];
26
+ }
27
+ export {};