2014-09-20 10:26:09 +02:00
< script type = "text/x-red" data-template-name = "smooth" >
< div class = "form-row" >
2018-01-30 22:42:14 +01:00
< label for = "node-input-property" > < i class = "fa fa-ellipsis-h" > < / i > < span data-i18n = "node-red:common.label.property" > < / span > < / label >
< input type = "text" id = "node-input-property" style = "width:70%;" / >
< / div >
< div class = "form-row" >
< label for = "node-input-action" > < i class = "fa fa-bolt" > < / i > Action< / label >
2014-10-02 20:35:07 +02:00
< select id = "node-input-action" style = "width:60%; margin-right:5px;" >
2014-09-20 10:26:09 +02:00
< option value = "max" > Return the maximum value seen< / option >
< option value = "min" > Return the minimum value seen< / option >
2015-10-11 18:47:08 +02:00
< option value = "mean" > Return the mean value< / option >
< option value = "sd" > Return the standard deviation< / option >
2014-09-20 10:26:09 +02:00
< option value = "low" > Perform low pass filter< / option >
< option value = "high" > Perform high pass filter< / option >
< / select >
< / div >
< div class = "form-row" >
2014-10-02 20:35:07 +02:00
< label for = "node-input-count" > < / label >
2014-09-20 10:26:09 +02:00
< span id = "node-over" > over the most recent < / span >
2016-02-14 14:47:04 +01:00
< input type = "text" id = "node-input-count" placeholder = "10" style = "width:50px;" / >
< span id = "node-over2" > values< / span >
2014-09-20 10:26:09 +02:00
< / div >
< div class = "form-row" >
2016-02-14 14:47:04 +01:00
< label for = "node-input-round" > (optionally)< / label >
round to < input type = "text" id = "node-input-round" placeholder = "ignore" style = "width:50px;" / > decimal places
2014-09-20 10:26:09 +02:00
< / div >
2017-05-24 20:45:31 +02:00
< div class = "form-row" >
< label for = "node-input-mult" > Treat< / label >
< select id = "node-input-mult" style = "width:60%; margin-right:5px;" >
< option value = "single" > All msg as one stream.< / option >
< option value = "multi" > Different msg.topic as individual streams.< / option >
< / select >
< / div >
2019-09-19 10:11:23 +02:00
< div class = "form-row" id = "row-input-reduce" >
< label for = "node-input-reduce" > < i class = "fa fa-compress" > < / i > Reduce< / label >
< input type = "checkbox" id = "node-input-reduce" style = "display:inline-block; width:20px; vertical-align:baseline;" >
only emit one message per most recent N values
< / div >
2014-09-20 10:26:09 +02:00
< br / >
< div class = "form-row" >
2014-09-21 12:14:57 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2014-09-20 10:26:09 +02:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
< div class = "form-tips" id = "node-tip" > Tip: This node ONLY works with numbers.< / div >
< / script >
< script type = "text/x-red" data-help-name = "smooth" >
< p > A simple node to provide various functions across several previous values, including max, min, mean, high and low pass filters.< / p >
2017-05-24 20:45:31 +02:00
< p > Messages arriving with different < code > msg.topic< / code > can be treated as separate streams if so configured.< / p >
2014-09-20 10:26:09 +02:00
< p > Max, Min and Mean work over a specified number of previous values.< / p >
2019-09-19 10:11:23 +02:00
< p > The High and Low pass filters use a smoothing factor. The higher the number the more the smoothing. E.g. a value of 10 is similar to an α of 0.1. It is analagous to an RC time constant - but there is no time component to this as the time is based on events arriving.< / p >
< p > Enabling the Reduce option causes the node to only emit one message per N values (available for the Max, Min and Mean functions). E.g. if set to Mean over 10 values, there will only be one outgoing message per 10 incoming ones.< / p >
2017-02-07 22:41:18 +01:00
< p > If < code > msg.reset< / code > is received (with any value), all the counters and intermediate values are reset to an initial state.< / p >
2014-09-20 10:26:09 +02:00
< p > < b > Note:< / b > This only operates on < b > numbers< / b > . Anything else will try to be made into a number and rejected if that fails.< / p >
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('smooth', {
color: "#E2D96E",
category: 'function',
defaults: {
2016-02-14 14:47:04 +01:00
name: {value:""},
2018-01-30 22:42:14 +01:00
property: {value:"payload",required:true},
2014-09-20 10:26:09 +02:00
action: {value:"mean"},
2016-02-14 14:47:04 +01:00
count: {value:"10",required:true,validate:RED.validators.number()},
2017-05-24 20:45:31 +02:00
round: {value:""},
2019-09-19 10:11:23 +02:00
mult: {value:"single"},
reduce: {value:false}
2014-09-20 10:26:09 +02:00
},
inputs: 1,
outputs: 1,
icon: "smooth.png",
label: function() {
return this.name || "smooth";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
2019-09-19 10:25:44 +02:00
outputLabels: function() { return this.reduce === true ? (this.action+" of "+this.count) : (this.action); },
2014-09-20 10:26:09 +02:00
oneditprepare: function() {
2018-01-30 22:42:14 +01:00
if (this.property === undefined) {
$("#node-input-property").val("payload");
}
$("#node-input-property").typedInput({default:'msg',types:['msg']});
2014-09-20 10:26:09 +02:00
$("#node-input-count").spinner({
2016-02-14 14:47:04 +01:00
min:1
});
$("#node-input-round").spinner({
2014-09-20 10:26:09 +02:00
});
$("#node-input-action").change( function() {
var a = $("#node-input-action").val();
if ((a === "high") || ( a === "low" )) {
$("#node-over").html("with a smoothing factor of ");
$("#node-over2").html("");
2019-09-19 10:11:23 +02:00
$("#row-input-reduce").hide();
2014-09-20 10:26:09 +02:00
}
else {
$("#node-over").html("over the most recent ");
2016-02-14 14:47:04 +01:00
$("#node-over2").html(" values");
2019-09-19 10:11:23 +02:00
$("#row-input-reduce").show();
2014-09-20 10:26:09 +02:00
}
});
$("#node-input-action").change();
2016-02-14 14:47:04 +01:00
if ($("#node-input-round").val() === "true") {
$("#node-input-round").val(0);
}
2014-09-20 10:26:09 +02:00
}
});
< / script >