var fs = require('fs') var path = require('path') var pull = require('pull-stream') var File = require('pull-file') var Split = require('pull-split') var common = require('./common') var dayMax = 0 var weekMax = 0 var monthMax = 0 pull( File(path.join(__dirname, 'day.jsonp')), Split(), pull.filter(Boolean), pull.map(JSON.parse), pull.through(function (day) { var count = day.ids.length if (count > dayMax) dayMax = count }), pull.map('ids'), pull.flatten(), pull.unique(), pull.collect(function (err, ids) { if (err) throw err fs.writeFileSync(path.join(__dirname, 'ids-colors.json'), JSON.stringify({ ids: ids, colors: common.computeIdColors(ids) })) var data = JSON.stringify({ max: dayMax }) fs.writeFileSync(path.join(__dirname, 'day.json'), data) }) ) pull( File(path.join(__dirname, 'week.jsonp')), Split(), pull.filter(Boolean), pull.map(JSON.parse), pull.through(function (week) { var count = week.ids.length if (count > weekMax) weekMax = count }), pull.map('ids'), pull.flatten(), pull.unique(), pull.collect(function (err, ids) { if (err) throw err var data = JSON.stringify({ max: weekMax }) fs.writeFileSync(path.join(__dirname, 'week.json'), data) }) ) pull( File(path.join(__dirname, 'month.jsonp')), Split(), pull.filter(Boolean), pull.map(JSON.parse), pull.through(function (month) { var count = month.ids.length if (count > monthMax) monthMax = count }), pull.map('ids'), pull.flatten(), pull.unique(), pull.collect(function (err, ids) { if (err) throw err var data = JSON.stringify({ max: monthMax }) fs.writeFileSync(path.join(__dirname, 'month.json'), data) }) )