git ssb

0+

cel / ssb-activity



Tree: cec705118d65476d8ba5b903fb836cae42f2f1dd

Files: cec705118d65476d8ba5b903fb836cae42f2f1dd / process-ids.js

1935 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)
32 }))
33 var data = JSON.stringify({
34 max: dayMax
35 })
36 fs.writeFileSync(path.join(__dirname, 'day.json'), data)
37 })
38)
39
40else if (series === 'week') pull(
41 File(path.join(__dirname, 'week.jsonp')),
42 Split(),
43 pull.filter(Boolean),
44 pull.map(JSON.parse),
45 pull.through(function (week) {
46 var count = week.ids.length
47 if (count > weekMax) weekMax = count
48 }),
49 pull.map('ids'),
50 pull.flatten(),
51 pull.unique(),
52 pull.collect(function (err, ids) {
53 if (err) throw err
54 var data = JSON.stringify({
55 max: weekMax
56 })
57 fs.writeFileSync(path.join(__dirname, 'week.json'), data)
58 })
59)
60
61else if (series === 'month') pull(
62 File(path.join(__dirname, 'month.jsonp')),
63 Split(),
64 pull.filter(Boolean),
65 pull.map(JSON.parse),
66 pull.through(function (month) {
67 var count = month.ids.length
68 if (count > monthMax) monthMax = count
69 }),
70 pull.map('ids'),
71 pull.flatten(),
72 pull.unique(),
73 pull.collect(function (err, ids) {
74 if (err) throw err
75 var data = JSON.stringify({
76 max: monthMax
77 })
78 fs.writeFileSync(path.join(__dirname, 'month.json'), data)
79 })
80)
81

Built with git-ssb-web