Browse Source

add function to reduce the points, future versions need to calc min/max

of deleted points, but that involves date math I don't want to do yet.
main
John-Mark Gurney 5 years ago
parent
commit
a92e5623dc
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      root/js/solardash.file.jspp

+ 21
- 0
root/js/solardash.file.jspp View File

@@ -24,6 +24,26 @@ Array.prototype.bisect = function (val, lo, hi) {
return lo;
};

// Reduce array ar down to cnt number of points if necesssary
function reducepoints(ar, cnt) {
// If we're already less than cnt, don't do anything.
if (ar.length < cnt)
return ar;

// Just skip points for now
var ret = [];
var x = 0;
for (idx = 0; idx < cnt; idx++) {
ret[idx] = ar[Math.floor(x / cnt)];
x += ar.length;
}

// always include the last point
ret[idx] = ar[ar.length - 1];

return ret;
}

WebSocketTest.prototype.send = function (s) {
console.log("ws send: " + s);
var msg = s.split(" ");
@@ -39,6 +59,7 @@ WebSocketTest.prototype.send = function (s) {
loidx -= 1;
hiidx = fakedata.production.bisect([msg[2], 0]) + 1;
var subar = fakedata.production.slice(loidx, hiidx);
subar = reducepoints(subar, 800);
var data = {
"production": subar,
"consumption": subar,


Loading…
Cancel
Save