Created
March 24, 2011 19:39
-
-
Save 9b/885707 to your computer and use it in GitHub Desktop.
Component totals and averages for a PDF set
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 () { | |
this.structure.components.component.forEach( | |
function (z) { | |
emit(z.name, {count: 0, total: z.count, avg:0}); | |
} | |
); | |
} | |
var reduce = function (key, values) { | |
var count = db.malware.count(); | |
var total = 0; | |
for (var i = 0; i < values.length; i++) { | |
total += values[i].total; | |
} | |
avg = total/count; | |
return { count: count, avg: avg, total: total}; | |
} | |
db.malware.mapReduce(map,reduce, {out: "component_totals" }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment