Files: ff98921335def95aebf4415c69f785dca02cbcc9 / counts.js
1771 bytesRaw
1 | var fs = require('fs') |
2 | var path = require('path') |
3 | var pull = require('pull-stream') |
4 | var File = require('pull-file') |
5 | var Split = require('pull-split') |
6 | var common = require('./common') |
7 | |
8 | var start = common.startTime |
9 | var startDay = Math.floor(start / 86400000) |
10 | var startWeek = Math.floor(start / 86400000 / 7) |
11 | var startMonth = Math.floor(start / 86400000 / 30.43666666666666666666) |
12 | var startT |
13 | |
14 | var now = Date.now() |
15 | var nowDay = Math.floor(now / 86400000) |
16 | var nowWeek = Math.floor(now / 86400000 / 7) |
17 | var nowMonth = Math.floor(now / 86400000 / 30.43666666666666666666) |
18 | |
19 | var series = process.argv[2] |
20 | if (!series) throw new TypeError('Missing series argument') |
21 | var unit = 1 |
22 | |
23 | if (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 | |
36 | var info = JSON.parse(fs.readFileSync(path.join(__dirname, series + '.json'))) |
37 | var info1 = JSON.parse(fs.readFileSync(path.join(__dirname, 'ids-colors.json'))) |
38 | var ids = info1.ids |
39 | var userColors = info1.colors |
40 | |
41 | var height = info.max |
42 | |
43 | var last = Date.now() - 86400e3 |
44 | |
45 | function toISODateString(d) { |
46 | return d.toISOString().replace(/T.*/, '') |
47 | } |
48 | |
49 | var max = 0 |
50 | var maxDate |
51 | |
52 | pull( |
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