Skip to content

Instantly share code, notes, and snippets.

@rinsuki
Created December 11, 2017 18:25
Show Gist options
  • Save rinsuki/0fd7c9fd3716b413cd9cdf34c54cbe75 to your computer and use it in GitHub Desktop.
Save rinsuki/0fd7c9fd3716b413cd9cdf34c54cbe75 to your computer and use it in GitHub Desktop.
var a = []
var b = db.getCollection('questions').mapReduce(function(){
var date = new Date(this.answeredAt - 0)
emit(Math.floor((date-0)/60/60/1000),{count: 1})
}, function(key, values) {
var count = 0
values.forEach(v =>count += v.count)
return {count}
}, {out: {inline:1}, query: {answeredAt: {$ne: null}}} ).results
.map(a => [a._id, a.value.count])
var min = b[0][0]
a.push(b.shift())
b.forEach(q => {
min++
while(min < q[0]) {
a.push([min, 0])
min++
}
a.push(q)
})
a.map(a => {
var date = new Date(a[0]*60*60*1000)
a[0] = date.getFullYear() + "/" + date.getMonth() + "/" + ("0"+date.getDate()).substr(-2) + " " + ("0"+date.getHours()).substr(-2)+"h"
return a
}).map(a => a[0]+"\t"+a[1]).join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment