-
-
Save guilhermedecampo/542e30f2c77261dc5378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function agg_session_count(){ | |
db.logs.mapReduce( | |
function(){ | |
var local_zone = new Date().getTimezoneOffset() | |
var br_zone = 3*60; | |
var date_br = parseInt(this.when)+(br_zone-local_zone)*60; | |
var date = new Date(date_br*1000); | |
var date_format = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate(); | |
emit(date_format,{event_ids: [this.event_id], count: 1}); | |
}, | |
function(key,values){ | |
var res = {event_ids: [], count: 0} | |
var uniques = {}; | |
values.forEach(function(value) { | |
value.event_ids.forEach(function(event_id) { | |
uniques[event_id] = 1 | |
}); | |
}) | |
res.event_ids = Object.keys(uniques); | |
res.count = res.event_ids.length; | |
return res; | |
}, | |
{ | |
query: {event: 'created', type: 'stop', event_ids: {$ne: "unspecified"}}, | |
out: 'agg_session_count' | |
}, | |
function(err,res){ | |
if(err){ | |
console.log(err); | |
} else { | |
db.agg_session_count.count(function(err,val){ | |
changes = val; | |
console.log("OK: "+val+" objects"); | |
}); | |
} | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment