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", "name": "@vvzvlad/node-red-contrib-rn-combined-nodes",
"version": "0.2.7", "version": "0.2.8",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [

View File

@ -21,9 +21,16 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </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>
<script type="text/html" data-help-name="c-thermostat-analyzer"> <script type="text/html" data-help-name="c-thermostat-analyzer">
<p>c-thermostat/p> <p>c-thermostat/p>
</script> </script>

View File

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