This commit is contained in:
andowinger
2025-02-08 16:30:17 +08:00
committed by GitHub
3 changed files with 37 additions and 0 deletions

View File

@@ -14,6 +14,7 @@
<option value="max">Return the maximum value seen</option>
<option value="min">Return the minimum value seen</option>
<option value="mean">Return the mean value</option>
<option value="median">Return the median value</option>
<option value="sd">Return the standard deviation</option>
<option value="low">Perform low pass filter</option>
<option value="high">Perform high pass filter</option>

View File

@@ -54,6 +54,17 @@ module.exports = function(RED) {
v[top].tot = v[top].tot + n - v[top].pop;
value = v[top].tot / v[top].a.length;
}
if (node.action === "median") {
var sortedForMedian = v[top].a.slice().sort((a, b) => a - b);
var medianIndex = Math.floor(v[top].iter / 2);
if (v[top].iter % 2 === 0) {
value = (sortedForMedian[medianIndex - 1] + sortedForMedian[medianIndex]) / 2;
}
else {
value = sortedForMedian[medianIndex]
}
}
if (node.action === "sd") {
v[top].tot = v[top].tot + n - v[top].pop;
v[top].tot2 = v[top].tot2 + (n*n) - (v[top].pop * v[top].pop);