Files: 751227258275c4e50803a031d8e66f74e3c68892 / process-ids.js
2068 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, 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 | |
43 | else 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 | |
64 | else 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