Bump version to 0.2.8

This commit is contained in:
vvzvlad 2023-10-04 22:16:43 +03:00
parent 0fd4bedd6b
commit 4e3112de16
3 changed files with 21 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@vvzvlad/node-red-contrib-rn-combined-nodes",
"version": "0.2.7",
"version": "0.2.8",
"description": "",
"main": "index.js",
"keywords": [

View File

@ -21,9 +21,16 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-status_window"><i class="fa fa-tag"></i> Status window (in hours)</label>
<input type="text" id="node-input-status_window" placeholder="4">
</div>
<div class="form-row">
<label for="node-input-transitions_window"><i class="fa fa-tag"></i> Transitions window (in hours)</label>
<input type="text" id="node-input-transitions_window" placeholder="5">
</div>
</script>
<script type="text/html" data-help-name="c-thermostat-analyzer">
<p>c-thermostat/p>
</script>

View File

@ -1,8 +1,8 @@
module.exports = function(RED) {
function thermostat_analyzer(config) {
RED.nodes.createNode(this,config);
this.room = config.room;
this.zone = config.zone;
this.status_window = config.status_window;
this.transitions_window = config.transitions_window;
var node = this;
var context = node.context();
@ -40,10 +40,14 @@ module.exports = function(RED) {
function analyzer(msg) {
const status_window = 5 * 60 * 60 * 1000
const transitions_window = 5 * 60 * 60 * 1000
const status_window_h = node.status_window || 5
const transitions_window_h = node.transitions_window || 5
const max_temp_diff = 3
const status_window_ms = status_window_h * 60 * 60 * 1000
const transitions_window_ms = transitions_window_h * 60 * 60 * 1000
function round_to_two_decimal_places(num) {
return Math.round((num + Number.EPSILON) * 100) / 100
@ -54,7 +58,7 @@ module.exports = function(RED) {
if (value === null) return
const current_time = new Date().getTime()
status_hist.push({ value, timestamp: current_time })
status_hist = status_hist.filter(item => current_time - item.timestamp <= status_window)
status_hist = status_hist.filter(item => current_time - item.timestamp <= status_window_ms)
let sum = 0
let total_time = 0
for (let i = 1; i < status_hist.length; i++) {
@ -71,7 +75,7 @@ module.exports = function(RED) {
const current_time = new Date().getTime()
const temp_diff = Math.abs(current_temp - target_temp)
diff_hist.push({ value: temp_diff, timestamp: current_time })
diff_hist = diff_hist.filter(item => current_time - item.timestamp <= status_window)
diff_hist = diff_hist.filter(item => current_time - item.timestamp <= status_window_ms)
let sum = 0
let total_time = 0
for (let i = 1; i < diff_hist.length; i++) {
@ -91,12 +95,12 @@ module.exports = function(RED) {
if (new_heater_status !== last_heater_status && new_window_state === last_window_state) {
const current_time = new Date().getTime()
transitions.push({ timestamp: current_time })
transitions = transitions.filter(item => current_time - item.timestamp <= transitions_window)
transitions = transitions.filter(item => current_time - item.timestamp <= transitions_window_ms)
context.set('last_heater_status', new_heater_status)
context.set('transitions', transitions)
}
context.set('last_window_state', new_window_state)
return transitions.length * 8
return transitions.length / transitions_window_h * 24
}
const payload = msg.payload