git ssb

0+

cel / ssb-activity



Tree: 8b2bb74986427753f3b1628bd266bcc7bd7693ea

Files: 8b2bb74986427753f3b1628bd266bcc7bd7693ea / counts.js

1995 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 toDateString(ms) {
46 var d
47 if (series === 'month') {
48 // Pick a date in the middle of the month, to correct for variations in
49 // month length.
50 ms += 3*86400e3
51 d = new Date(ms)
52 return d.toISOString().replace(/-..T.*/, '')
53 } else {
54 d = new Date(ms)
55 return d.toISOString().replace(/T.*/, '')
56 }
57}
58
59var max = 0
60var maxTs
61
62pull(
63 File(path.join(__dirname, series + '.jsonp')),
64 Split(),
65 pull.filter(Boolean),
66 pull.map(JSON.parse),
67 pull.drain(function (interval) {
68 var ms = interval.time * unit
69 if (ms > last) return
70 var count = interval.ids.length
71 if (count > max) max = count, maxTs = ms
72 console.log(toDateString(ms), count)
73 }, function (err) {
74 if (err) throw err
75 console.log(toDateString(maxTs), max, 'max')
76 })
77)
78

Built with git-ssb-web