UNPKG

1.5 kBtext/coffeescriptView Raw
1aggregator = require('./interface')
2
3agg = aggregator.createBucketedAggregator()
4
5agg.track 'mean', aggregator: aggregator.mean.timeboxed, field: ((o) -> if o.isBot then 100 else 0)
6agg.track 'max', aggregator: aggregator.max.timeboxed, field: ((o) -> if o.isBot then 100 else 0)
7agg.track 'min', aggregator: aggregator.min.timeboxed, field: ((o) -> if o.isBot then 100 else 0)
8agg.track 'total', aggregator: aggregator.total.timeboxed, field: ((o) -> if o.isBot then 100 else 0)
9agg.track 'count', aggregator: aggregator.count.timeboxed, field: ((o) -> if o.isBot then 100 else 0)
10agg.track 'alltime mean', aggregator: aggregator.mean.alltime, field: ((o) -> if o.isBot then 100 else 0)
11agg.track 'alltime max', aggregator: aggregator.max.alltime, field: ((o) -> if o.isBot then 100 else 0)
12agg.track 'alltime min', aggregator: aggregator.min.alltime, field: ((o) -> if o.isBot then 100 else 0)
13agg.track 'alltime total', aggregator: aggregator.total.alltime, field: ((o) -> if o.isBot then 100 else 0)
14agg.track 'alltime count', aggregator: aggregator.count.alltime, field: ((o) -> if o.isBot then 100 else 0)
15
16# agg.on 'alltime mean', 'change', (bucket, newValue, oldValue) ->
17# console.log("#{bucket} changed from #{oldValue} to #{newValue}")
18
19process.on 'exit', -> console.log(agg.value())
20
21jsonStream = require('./json-stream')
22jsonStream.eachRecord (record) ->
23 agg.push(record.site, new Date(record.timestamp), record)