@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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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;
|
package/docs/openapi-output.yaml
CHANGED