Files: 60bb192e4fd7cd1d216e02babf4182c884bf1b29 / process-ids.js
1664 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 | |
7 | var dayMax = 0 |
8 | var weekMax = 0 |
9 | var monthMax = 0 |
10 | |
11 | pull( |
12 | File(path.join(__dirname, 'day.jsonp')), |
13 | Split(), |
14 | pull.filter(Boolean), |
15 | pull.map(JSON.parse), |
16 | pull.through(function (day) { |
17 | var count = day.ids.length |
18 | if (count > dayMax) dayMax = count |
19 | }), |
20 | pull.map('ids'), |
21 | pull.flatten(), |
22 | pull.unique(), |
23 | pull.collect(function (err, ids) { |
24 | if (err) throw err |
25 | fs.writeFileSync(path.join(__dirname, 'ids.json'), JSON.stringify(ids)) |
26 | var data = JSON.stringify({ |
27 | max: dayMax |
28 | }) |
29 | fs.writeFileSync(path.join(__dirname, 'day.json'), data) |
30 | }) |
31 | ) |
32 | |
33 | pull( |
34 | File(path.join(__dirname, 'week.jsonp')), |
35 | Split(), |
36 | pull.filter(Boolean), |
37 | pull.map(JSON.parse), |
38 | pull.through(function (week) { |
39 | var count = week.ids.length |
40 | if (count > weekMax) weekMax = count |
41 | }), |
42 | pull.map('ids'), |
43 | pull.flatten(), |
44 | pull.unique(), |
45 | pull.collect(function (err, ids) { |
46 | if (err) throw err |
47 | var data = JSON.stringify({ |
48 | max: weekMax |
49 | }) |
50 | fs.writeFileSync(path.join(__dirname, 'week.json'), data) |
51 | }) |
52 | ) |
53 | |
54 | pull( |
55 | File(path.join(__dirname, 'month.jsonp')), |
56 | Split(), |
57 | pull.filter(Boolean), |
58 | pull.map(JSON.parse), |
59 | pull.through(function (month) { |
60 | var count = month.ids.length |
61 | if (count > monthMax) monthMax = count |
62 | }), |
63 | pull.map('ids'), |
64 | pull.flatten(), |
65 | pull.unique(), |
66 | pull.collect(function (err, ids) { |
67 | if (err) throw err |
68 | var data = JSON.stringify({ |
69 | max: monthMax |
70 | }) |
71 | fs.writeFileSync(path.join(__dirname, 'month.json'), data) |
72 | }) |
73 | ) |
74 |
Built with git-ssb-web