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 start = common.startTime var startDay = Math.floor(start / 86400000) var startWeek = Math.floor(start / 86400000 / 7) var startMonth = Math.floor(start / 86400000 / 30.43666666666666666666) var startT var now = Date.now() var nowDay = Math.floor(now / 86400000) var nowWeek = Math.floor(now / 86400000 / 7) var nowMonth = Math.floor(now / 86400000 / 30.43666666666666666666) var series = process.argv[2] if (!series) throw new TypeError('Missing series argument') var unit = 1 if (series === 'day') { startT = startDay unit = 86400e3 } else if (series === 'week') { startT = startWeek unit = 86400e3*7 } else if (series === 'month') { startT = startMonth unit = 86400e3*(365.24/12) } else { throw new TypeError('Invalid series') } var info = JSON.parse(fs.readFileSync(path.join(__dirname, series + '.json'))) var info1 = JSON.parse(fs.readFileSync(path.join(__dirname, 'ids-colors.json'))) var ids = info1.ids var userColors = info1.colors var height = info.max var last = Date.now() - 86400e3 function toDateString(ms) { var d if (series === 'month') { // Pick a date in the middle of the month, to correct for variations in // month length. ms += 3*86400e3 d = new Date(ms) return d.toISOString().replace(/-..T.*/, '') } else { d = new Date(ms) return d.toISOString().replace(/T.*/, '') } } var max = 0 var maxTs pull( File(path.join(__dirname, series + '.jsonp')), Split(), pull.filter(Boolean), pull.map(JSON.parse), pull.drain(function (interval) { var ms = interval.time * unit if (ms > last) return var count = interval.ids.length if (count > max) max = count, maxTs = ms console.log(toDateString(ms), count) }, function (err) { if (err) throw err console.log(toDateString(maxTs), max, 'max') }) )