Files: cec705118d65476d8ba5b903fb836cae42f2f1dd / process-ids.js
1935 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 dayMax = 0 |
9 | var weekMax = 0 |
10 | var monthMax = 0 |
11 | |
12 | var series = process.argv[2] |
13 | if (!series) throw new TypeError('Missing series argument') |
14 | |
15 | if (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 | |
40 | else 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 | |
61 | else 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