@golemio/energetics 1.4.1-dev.1383182214 → 1.4.1-dev.1388903132

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.
@@ -24,4 +24,5 @@ INSERT INTO consumption_energy_measurements ("timestamp", value, addr, var, "typ
24
24
  ('2023-05-01 04:00:00.000+02', 2709691.000000000000000, '/2.9/PF1', 'core', 'provider_value', '27ZG100Z0000521V', NULL, NULL, NULL, '2023-05-02 00:30:44.263', NULL, NULL, '2023-05-02 00:30:44.263', NULL),
25
25
  ('2023-05-01 04:00:00.001+02', 18.000000000000000, '/2.9/PF1', 'core2', 'provider_value', '27ZG100Z0000521V', NULL, NULL, NULL, '2023-05-02 00:30:44.263', NULL, NULL, '2023-05-02 00:30:44.263', NULL),
26
26
  ('2023-05-01 03:00:00.000+02', 2709680.000000000000000, '/2.9/PF1', 'core', 'provider_value', '27ZG100Z0000521V', NULL, NULL, NULL, '2023-05-02 00:30:44.263', NULL, NULL, '2023-05-02 00:30:44.263', NULL),
27
- ('2023-05-01 03:00:00.001+02', 14.000000000000000, '/2.9/PF1', 'core2', 'provider_value', '27ZG100Z0000521V', NULL, NULL, NULL, '2023-05-02 00:30:44.263', NULL, NULL, '2023-05-02 00:30:44.263', NULL);
27
+ ('2023-05-01 03:00:00.001+02', 14.000000000000000, '/2.9/PF1', 'core2', 'provider_value', '27ZG100Z0000521V', NULL, NULL, NULL, '2023-05-02 00:30:44.263', NULL, NULL, '2023-05-02 00:30:44.263', NULL),
28
+ ('2023-04-30 23:45:00.001+02', 0.000000000000000, '/2.9/PF1', 'core2', 'provider_value', '27ZG100Z0000521V', NULL, NULL, NULL, '2023-05-02 00:30:44.263', NULL, NULL, '2023-05-02 00:30:44.263', NULL);
@@ -8,39 +8,69 @@ RETURNS TABLE (
8
8
  )
9
9
  SET search_path FROM CURRENT
10
10
  AS $func$
11
- select
12
- case when var in ('EFwActi','EFwActiVT','EFwActiNT') then --special handling for "činná energie"
13
- (max("value")/4) - (min("value")/4)
14
- else
15
- max("value") - min("value")
16
- end as "value",
11
+ with previousMonth as (
12
+ select
13
+ max("value") as maxPrevious
14
+ from
15
+ "consumption_energy_measurements" as "consumption_energy_measurements"
16
+ where
17
+ ("consumption_energy_measurements"."var" = $2
18
+ and "consumption_energy_measurements"."addr" = $1
19
+ and "consumption_energy_measurements"."timestamp" > ($3::timestamptz - interval '1 month') and "consumption_energy_measurements"."timestamp" < $3
20
+ ) and
21
+ case -- limit access according to allowed organizations for the role
22
+ when $5 is null then 1
23
+ when
24
+ "consumption_energy_measurements"."addr" in (
25
+ select distinct
26
+ d.addr
27
+ from organizations_buildings b
28
+ inner join consumption_energy_devices d on b.building_id = d.building_id
29
+ where b.organization_id = any(('{' || $5 || '}')::integer[])
30
+ ) then 1
31
+ else 0
32
+ end = 1
33
+ ), currentMonth as (
34
+ select
17
35
  "meter",
18
36
  "type",
19
37
  "addr",
20
- "var"
38
+ "var",
39
+ max("value") as maxValue
21
40
  from
22
41
  "consumption_energy_measurements" as "consumption_energy_measurements"
23
42
  where
24
43
  ("consumption_energy_measurements"."var" = $2
25
44
  and "consumption_energy_measurements"."addr" = $1
26
45
  and "consumption_energy_measurements"."timestamp" between $3 and $4
27
- and
28
- case
29
- when $5 is null then 1
30
- when
31
- "consumption_energy_measurements"."addr" in (
32
- select distinct
33
- d.addr
34
- from organizations_buildings b
35
- inner join consumption_energy_devices d on b.building_id = d.building_id
36
- where b.organization_id = any(('{' || $5 || '}')::integer[])
37
- ) then 1
38
- else 0
39
- end = 1
40
- )
46
+ ) and
47
+ case -- limit access according to allowed organizations for the role
48
+ when $5 is null then 1
49
+ when
50
+ "consumption_energy_measurements"."addr" in (
51
+ select distinct
52
+ d.addr
53
+ from organizations_buildings b
54
+ inner join consumption_energy_devices d on b.building_id = d.building_id
55
+ where b.organization_id = any(('{' || $5 || '}')::integer[])
56
+ ) then 1
57
+ else 0
58
+ end = 1
41
59
  group by
42
60
  "meter",
43
61
  "type",
44
62
  "addr",
45
- "var";
63
+ "var"
64
+ ) select
65
+ case when var in ('EFwActi','EFwActiVT','EFwActiNT') then -- special handling for "činná energie"
66
+ ((maxValue/4) - (maxPrevious/4))
67
+ else
68
+ maxValue - maxPrevious
69
+ end as "value",
70
+ "meter",
71
+ "type",
72
+ "addr",
73
+ "var"
74
+ from
75
+ previousMonth, currentMonth;
46
76
  $func$ LANGUAGE sql;
@@ -1017,7 +1017,7 @@ components:
1017
1017
  additionalProperties: false
1018
1018
  EnergeticsVariables:
1019
1019
  type: string
1020
- example: core
1020
+ example: core2
1021
1021
  enum:
1022
1022
  - core
1023
1023
  - core2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/energetics",
3
- "version": "1.4.1-dev.1383182214",
3
+ "version": "1.4.1-dev.1388903132",
4
4
  "description": "Golemio Energetics Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",