git ssb

0+

cel / ssb-activity



Tree: ff98921335def95aebf4415c69f785dca02cbcc9

Files: ff98921335def95aebf4415c69f785dca02cbcc9 / counts.js

1771 bytesRaw
1var fs = require('fs')
2var path = require('path')
3var pull = require('pull-stream')
4var File = require('pull-file')
5var Split = require('pull-split')
6var common = require('./common')
7
8var start = common.startTime
9var startDay = Math.floor(start / 86400000)
10var startWeek = Math.floor(start / 86400000 / 7)
11var startMonth = Math.floor(start / 86400000 / 30.43666666666666666666)
12var startT
13
14var now = Date.now()
15var nowDay = Math.floor(now / 86400000)
16var nowWeek = Math.floor(now / 86400000 / 7)
17var nowMonth = Math.floor(now / 86400000 / 30.43666666666666666666)
18
19var series = process.argv[2]
20if (!series) throw new TypeError('Missing series argument')
21var unit = 1
22
23if (series === 'day') {
24 startT = startDay
25 unit = 86400e3
26} else if (series === 'week') {
27 startT = startWeek
28 unit = 86400e3*7
29} else if (series === 'month') {
30 startT = startMonth
31 unit = 86400e3*(365.24/12)
32} else {
33 throw new TypeError('Invalid series')
34}
35
36var info = JSON.parse(fs.readFileSync(path.join(__dirname, series + '.json')))
37var info1 = JSON.parse(fs.readFileSync(path.join(__dirname, 'ids-colors.json')))
38var ids = info1.ids
39var userColors = info1.colors
40
41var height = info.max
42
43var last = Date.now() - 86400e3
44
45function toISODateString(d) {
46 return d.toISOString().replace(/T.*/, '')
47}
48
49var max = 0
50var maxDate
51
52pull(
53 File(path.join(__dirname, series + '.jsonp')),
54 Split(),
55 pull.filter(Boolean),
56 pull.map(JSON.parse),
57 pull.drain(function (interval) {
58 var ms = interval.time * unit
59 if (ms > last) return
60 var d = new Date(ms)
61 var count = interval.ids.length
62 if (count > max) max = count, maxDate = d
63 console.log(toISODateString(d), count)
64 }, function (err) {
65 if (err) throw err
66 console.log(toISODateString(maxDate), max, 'max')
67 })
68)
69

Built with git-ssb-web