node-red-contrib-power-saver 5.0.0-beta.1 → 5.0.0-beta.2
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/.github/FUNDING.yml +1 -1
- package/= +0 -0
- package/README.md +3 -0
- package/docs/.vuepress/config.js +1 -0
- package/docs/changelog/README.md +4 -0
- package/docs/examples/README.md +2 -0
- package/docs/examples/example-reduce-minutes-array.md +23 -0
- package/donation.png +0 -0
- package/package.json +1 -1
- package/src/strategy-best-save-functions.js +25 -7
- package/test/data/best-save-result.json +1 -11
- package/test/data/reconfigResult.js +1 -11
package/.github/FUNDING.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# These are supported funding model platforms
|
|
2
2
|
|
|
3
3
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
-
patreon: ottopaulsen
|
|
4
|
+
patreon: # ottopaulsen
|
|
5
5
|
open_collective: # Replace with a single Open Collective username
|
|
6
6
|
ko_fi: # Replace with a single Ko-fi username
|
|
7
7
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
package/=
ADDED
|
File without changes
|
package/README.md
CHANGED
package/docs/.vuepress/config.js
CHANGED
package/docs/changelog/README.md
CHANGED
package/docs/examples/README.md
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Reduce minutes array
|
|
2
|
+
|
|
3
|
+
If you want to reduce number of entries in the minutes array on output 3, you can send it through a function node with the following code:
|
|
4
|
+
```
|
|
5
|
+
const minutes = []
|
|
6
|
+
let previousHour = ""
|
|
7
|
+
let previousSaving = null
|
|
8
|
+
let previousPrice = null
|
|
9
|
+
msg.payload.minutes.forEach(m => {
|
|
10
|
+
const hour = m.start.substring(0, 13)
|
|
11
|
+
if (hour !== previousHour || m.saving !== previousSaving || m.price !== previousPrice) {
|
|
12
|
+
minutes.push(m)
|
|
13
|
+
previousHour = hour
|
|
14
|
+
previousSaving = m.saving
|
|
15
|
+
previousPrice = m.price
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
msg.payload.minutes = minutes
|
|
20
|
+
|
|
21
|
+
return msg;
|
|
22
|
+
```
|
|
23
|
+
It will remove all entries that are equal to the one before, but still send at least one per hour.
|
package/donation.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -8,7 +8,9 @@ const { fillArray } = require("./utils");
|
|
|
8
8
|
*
|
|
9
9
|
* @param {*} onOff Array of on/off values
|
|
10
10
|
* @param {*} maxMinutesOff Max number of minutes that can be off in a sequence
|
|
11
|
-
* @param {*} minMinutesOff Min number of minutes that must be
|
|
11
|
+
* @param {*} minMinutesOff Min number of minutes that must be off to bother
|
|
12
|
+
* @param {*} recoveryPercentage Percent of off-time that must be on after being off
|
|
13
|
+
* @param {*} recoveryMaxMinutes Maximum recovery time in minutes
|
|
12
14
|
* @returns
|
|
13
15
|
*/
|
|
14
16
|
function isOnOffSequencesOk(
|
|
@@ -16,37 +18,53 @@ function isOnOffSequencesOk(
|
|
|
16
18
|
maxMinutesOff,
|
|
17
19
|
minMinutesOff,
|
|
18
20
|
recoveryPercentage,
|
|
19
|
-
recoveryMaxMinutes = null
|
|
20
|
-
minSaving) {
|
|
21
|
+
recoveryMaxMinutes = null) {
|
|
21
22
|
let offCount = 0;
|
|
22
23
|
let onCount = 0;
|
|
23
24
|
let reachedMaxOff = false;
|
|
24
|
-
let reachedMinOn =
|
|
25
|
-
let
|
|
25
|
+
let reachedMinOn = true;
|
|
26
|
+
let reachedMinOff = null;
|
|
27
|
+
let minOnAfterOff = 0;
|
|
26
28
|
for (let i = 0; i < onOff.length; i++) {
|
|
27
29
|
if (!onOff[i]) {
|
|
28
30
|
if (maxMinutesOff === 0 || reachedMaxOff) {
|
|
29
31
|
return false;
|
|
30
32
|
}
|
|
33
|
+
if(!reachedMinOn) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if(reachedMinOff === null) {
|
|
37
|
+
reachedMinOff = false;
|
|
38
|
+
}
|
|
31
39
|
offCount++;
|
|
32
40
|
onCount = 0;
|
|
33
41
|
if (offCount >= maxMinutesOff) {
|
|
34
42
|
reachedMaxOff = true;
|
|
35
43
|
}
|
|
36
44
|
if (offCount >= minMinutesOff) {
|
|
37
|
-
|
|
45
|
+
reachedMinOff = true;
|
|
38
46
|
}
|
|
39
47
|
const minRounded = Math.max(Math.round(offCount * recoveryPercentage / 100), 1)
|
|
40
48
|
minOnAfterOff = Math.min(minRounded, recoveryMaxMinutes ?? minRounded)
|
|
49
|
+
if(i === onOff.length - 1) {
|
|
50
|
+
// If last minute, consider min reached
|
|
51
|
+
reachedMinOn = true;
|
|
52
|
+
reachedMinOff = true;
|
|
53
|
+
}
|
|
41
54
|
} else {
|
|
55
|
+
if(reachedMinOff === false) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
42
58
|
onCount++;
|
|
43
59
|
if (onCount >= minOnAfterOff) {
|
|
44
60
|
reachedMaxOff = false;
|
|
61
|
+
reachedMinOn = true;
|
|
45
62
|
}
|
|
46
63
|
offCount = 0;
|
|
64
|
+
reachedMinOff = null;
|
|
47
65
|
}
|
|
48
66
|
}
|
|
49
|
-
return reachedMinOn;
|
|
67
|
+
return reachedMinOn && !(reachedMinOff === false);
|
|
50
68
|
}
|
|
51
69
|
|
|
52
70
|
/**
|
|
@@ -58,17 +58,7 @@
|
|
|
58
58
|
{
|
|
59
59
|
"time": "2021-06-20T02:33:00.000+02:00",
|
|
60
60
|
"value": true,
|
|
61
|
-
"countMinutes":
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"time": "2021-06-20T02:36:00.000+02:00",
|
|
65
|
-
"value": false,
|
|
66
|
-
"countMinutes": 1
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"time": "2021-06-20T02:37:00.000+02:00",
|
|
70
|
-
"value": true,
|
|
71
|
-
"countMinutes": 1
|
|
61
|
+
"countMinutes": 5
|
|
72
62
|
},
|
|
73
63
|
{
|
|
74
64
|
"time": "2021-06-20T02:38:00.000+02:00",
|
|
@@ -58,17 +58,7 @@ module.exports = {
|
|
|
58
58
|
{
|
|
59
59
|
time: "2021-06-20T02:33:00.000+02:00",
|
|
60
60
|
value: true,
|
|
61
|
-
countMinutes:
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
time: "2021-06-20T02:36:00.000+02:00",
|
|
65
|
-
value: false,
|
|
66
|
-
countMinutes: 1,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
time: "2021-06-20T02:37:00.000+02:00",
|
|
70
|
-
value: true,
|
|
71
|
-
countMinutes: 1,
|
|
61
|
+
countMinutes: 5,
|
|
72
62
|
},
|
|
73
63
|
{
|
|
74
64
|
time: "2021-06-20T02:38:00.000+02:00",
|