stupid average

This commit is contained in:
Iuri Matias 2019-05-31 15:56:08 -04:00
parent 4f21c16f62
commit 078332be85
1 changed files with 12 additions and 2 deletions

View File

@ -3,7 +3,7 @@ const Events = require('events')
const events = new Events()
const { Observable, fromEvent, interval, Subject } = require('rxjs');
const { throttle, map, distinctUntilChanged, filter, average, reduce, count} = require('rxjs/operators');
const { throttle, map, distinctUntilChanged, filter, average, reduce, count, scan} = require('rxjs/operators');
var loki = require('lokijs')
var db = new loki('loki.json')
@ -56,7 +56,17 @@ function trackEvent(eventName, filterConditions) {
return sub;
}
trackEvent('contractEvent', ((x) => x.from === "0x123")).pipe(map(x => x.rating)).subscribe((v) => {
let myscan = scan((acc, curr) => {
acc.push(curr);
if (acc.length > 4) {
acc.shift();
}
return acc;
}, [])
let mymap = map(arr => arr.reduce((acc, current) => acc + current, 0) / arr.length)
trackEvent('contractEvent', ((x) => x.from === "0x123")).pipe(map(x => x.rating), myscan, mymap).subscribe((v) => {
console.dir("current value is " + v)
})