Created
January 26, 2012 19:07
-
-
Save gerad/1684424 to your computer and use it in GitHub Desktop.
query time spent by domain using tractor
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
var map = function() { | |
var domain = this.info.url.match(/^https?:\/\/([^\/]*)/)[1]; | |
emit(domain, { duration: this.duration }); | |
}; | |
var reduce = function(key, values) { | |
var result = { duration: 0 }; | |
values.forEach(function(value) { | |
result.duration += value.duration | |
}); | |
return result; | |
}; | |
db.items.mapReduce(map, reduce, { | |
query: { app: 'Safari', 'info.url': /^https?:\/\/([^\/]*)/ }, | |
out: 'domain_durations' } | |
); | |
db.domain_durations.find().sort({ 'value.duration': -1 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment