@golemio/energetics 1.1.0 → 1.1.1-dev.749143389
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.
- package/README.md +2 -2
- package/db/migrations/postgresql/20230116095151-correct_v_energetis_upadate.js +53 -0
- package/db/migrations/postgresql/sqls/20230116095151-correct_v_energetis_upadate-down.sql +27 -0
- package/db/migrations/postgresql/sqls/20230116095151-correct_v_energetis_upadate-up.sql +28 -0
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -35,10 +35,10 @@ The APIs may be unstable. Therefore, we recommend to install this module as an e
|
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
37
|
# Latest version
|
|
38
|
-
|
|
38
|
+
npm install --save-exact @golemio/energetics@latest
|
|
39
39
|
|
|
40
40
|
# Development version
|
|
41
|
-
|
|
41
|
+
npm install --save-exact @golemio/energetics@dev
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
<!-- ## Description -->
|
|
@@ -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', '20230116095151-correct_v_energetis_upadate-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', '20230116095151-correct_v_energetis_upadate-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,27 @@
|
|
|
1
|
+
DROP VIEW v_consumption_energy_last_update;
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE VIEW v_consumption_energy_last_update
|
|
4
|
+
AS WITH last_update AS (
|
|
5
|
+
SELECT b.building_name,
|
|
6
|
+
c.addr,
|
|
7
|
+
max(c.time_utc) AS last_update
|
|
8
|
+
FROM energetics.consumption_energy_consumption c
|
|
9
|
+
JOIN energetics.consumption_energy_devices d ON c.addr::text = d.addr::text
|
|
10
|
+
JOIN energetics.consumption_energy_buildings b ON d.building_id = b.id
|
|
11
|
+
GROUP BY b.building_name, c.addr
|
|
12
|
+
), last_not_zero AS (
|
|
13
|
+
SELECT consumption_energy_consumption.addr,
|
|
14
|
+
max(consumption_energy_consumption.time_utc) AS last_not_zero_value
|
|
15
|
+
FROM energetics.consumption_energy_consumption
|
|
16
|
+
WHERE consumption_energy_consumption.value > 0::numeric
|
|
17
|
+
GROUP BY consumption_energy_consumption.addr
|
|
18
|
+
)
|
|
19
|
+
SELECT lu.building_name,
|
|
20
|
+
lu.last_update,
|
|
21
|
+
lu.addr,
|
|
22
|
+
CASE
|
|
23
|
+
WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
|
|
24
|
+
ELSE lnz.last_not_zero_value
|
|
25
|
+
END AS zero_values_after
|
|
26
|
+
FROM last_update lu
|
|
27
|
+
LEFT JOIN last_not_zero lnz ON lu.addr::text = lnz.addr::text;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
DROP VIEW v_consumption_energy_last_update;
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE VIEW v_consumption_energy_last_update
|
|
4
|
+
AS WITH last_update AS (
|
|
5
|
+
SELECT b.building_name,
|
|
6
|
+
replace(c.addr, concat('/', c.var), '') as addr,
|
|
7
|
+
max(c.time_utc) AS last_update
|
|
8
|
+
FROM energetics.consumption_energy_consumption c
|
|
9
|
+
JOIN energetics.consumption_energy_devices d ON replace(c.addr, concat('/', c.var), '') = d.addr::text
|
|
10
|
+
JOIN energetics.consumption_energy_buildings b ON d.building_id = b.id
|
|
11
|
+
GROUP BY b.building_name, replace(c.addr, concat('/', c.var), '')
|
|
12
|
+
), last_not_zero AS (
|
|
13
|
+
SELECT replace(addr, concat('/', var), '') as addr,
|
|
14
|
+
max(time_utc) AS last_not_zero_value
|
|
15
|
+
FROM consumption_energy_consumption
|
|
16
|
+
WHERE value > 0::numeric
|
|
17
|
+
GROUP BY replace(addr, concat('/', var), '')
|
|
18
|
+
)
|
|
19
|
+
SELECT lu.building_name,
|
|
20
|
+
lu.last_update,
|
|
21
|
+
lu.addr,
|
|
22
|
+
CASE
|
|
23
|
+
WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
|
|
24
|
+
ELSE lnz.last_not_zero_value
|
|
25
|
+
END AS zero_values_after
|
|
26
|
+
FROM last_update lu
|
|
27
|
+
LEFT JOIN last_not_zero lnz ON lu.addr::text = lnz.addr::text
|
|
28
|
+
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemio/energetics",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1-dev.749143389",
|
|
4
4
|
"description": "Golemio Energetics Module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rimraf ./dist && ttsc -p ./tsconfig.build.json",
|
|
9
|
-
"build-minimal": "run-s 'build --sourceMap false --declaration false'",
|
|
10
|
-
"build-watch": "run-s 'build --watch --preserveWatchOutput'",
|
|
9
|
+
"build-minimal": "run-s 'build -- --sourceMap false --declaration false'",
|
|
10
|
+
"build-watch": "run-s 'build -- --watch --preserveWatchOutput'",
|
|
11
11
|
"test": "cross-env NODE_ENV=test TS_NODE_COMPILER='ttypescript' mocha --exit --check-leaks --timeout 120000 -r ts-node/register --file 'test/setup.ts' 'test/**/*.test.ts'",
|
|
12
|
-
"test-debug": "run-s 'test --inspect-brk=9230'",
|
|
13
|
-
"code-coverage": "nyc run-s 'test -r source-map-support/register'",
|
|
12
|
+
"test-debug": "run-s 'test -- --inspect-brk=9230'",
|
|
13
|
+
"code-coverage": "nyc run-s 'test -- -r source-map-support/register'",
|
|
14
14
|
"generate-docs": "typedoc --out docs/typedoc src",
|
|
15
15
|
"lint": "eslint \"{src,test}/**/*.ts\""
|
|
16
16
|
},
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://gitlab.com/operator-ict/golemio/code/modules/energetics"
|
|
25
25
|
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16.0.0",
|
|
28
|
+
"npm": ">=8.0.0",
|
|
29
|
+
"yarn": "Use npm!"
|
|
30
|
+
},
|
|
26
31
|
"devDependencies": {
|
|
27
32
|
"@commitlint/cli": "^11.0.0",
|
|
28
33
|
"@commitlint/config-conventional": "^11.0.0",
|
|
@@ -59,7 +64,5 @@
|
|
|
59
64
|
"dependencies": {
|
|
60
65
|
"JSONStream": "^1.3.5"
|
|
61
66
|
},
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
67
|
+
"overrides": {}
|
|
68
|
+
}
|