git ssb

0+

cel / ssb-activity



Tree: 751227258275c4e50803a031d8e66f74e3c68892

Files: 751227258275c4e50803a031d8e66f74e3c68892 / process-ids.js

2068 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 dayMax = 0
9var weekMax = 0
10var monthMax = 0
11
12var series = process.argv[2]
13if (!series) throw new TypeError('Missing series argument')
14
15if (series === 'day') pull(
16 File(path.join(__dirname, 'day.jsonp')),
17 Split(),
18 pull.filter(Boolean),
19 pull.map(JSON.parse),
20 pull.through(function (day) {
21 var count = day.ids.length
22 if (count > dayMax) dayMax = count
23 }),
24 pull.map('ids'),
25 pull.flatten(),
26 pull.unique(),
27 pull.collect(function (err, ids) {
28 if (err) throw err
29 fs.writeFileSync(path.join(__dirname, 'ids-colors.json'), JSON.stringify({
30 ids: ids,
31 colors: common.computeIdColors(ids, false)
32 }))
33 fs.writeFileSync(path.join(__dirname, 'colors-flat.json'), JSON.stringify(
34 common.computeIdColors(ids, true)
35 ))
36 var data = JSON.stringify({
37 max: dayMax
38 })
39 fs.writeFileSync(path.join(__dirname, 'day.json'), data)
40 })
41)
42
43else if (series === 'week') pull(
44 File(path.join(__dirname, 'week.jsonp')),
45 Split(),
46 pull.filter(Boolean),
47 pull.map(JSON.parse),
48 pull.through(function (week) {
49 var count = week.ids.length
50 if (count > weekMax) weekMax = count
51 }),
52 pull.map('ids'),
53 pull.flatten(),
54 pull.unique(),
55 pull.collect(function (err, ids) {
56 if (err) throw err
57 var data = JSON.stringify({
58 max: weekMax
59 })
60 fs.writeFileSync(path.join(__dirname, 'week.json'), data)
61 })
62)
63
64else if (series === 'month') pull(
65 File(path.join(__dirname, 'month.jsonp')),
66 Split(),
67 pull.filter(Boolean),
68 pull.map(JSON.parse),
69 pull.through(function (month) {
70 var count = month.ids.length
71 if (count > monthMax) monthMax = count
72 }),
73 pull.map('ids'),
74 pull.flatten(),
75 pull.unique(),
76 pull.collect(function (err, ids) {
77 if (err) throw err
78 var data = JSON.stringify({
79 max: monthMax
80 })
81 fs.writeFileSync(path.join(__dirname, 'month.json'), data)
82 })
83)
84

Built with git-ssb-web