|
|
@@ -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, |
|
|
|