Skip to content

Instantly share code, notes, and snippets.

@BenLubar
Created May 17, 2013 17:48
Show Gist options
  • Save BenLubar/5600720 to your computer and use it in GitHub Desktop.
Save BenLubar/5600720 to your computer and use it in GitHub Desktop.
function (doc, meta) {
if (doc.Type == 'killed') {
emit(dateToArray(doc.Time), {Attacker: doc.Attacker.Class, Victim: doc.Victim.Class, Weapon: doc.Weapon});
}
}
function(key, values, rereduce) {
var result = {};
if (rereduce) {
values.forEach(function(v) {
for (var attacker in v) {
result[attacker] = result[attacker] || {};
for (var victim in v[attacker]) {
result[attacker][victim] = result[attacker][victim] || {};
for (var weapon in v[attacker][victim]) {
result[attacker][victim][weapon] = result[attacker][victim][weapon] || 0;
result[attacker][victim][weapon] += v[attacker][victim][weapon];
}
}
}
});
} else {
values.forEach(function(v) {
result[v.Attacker] = result[v.Attacker] || {};
result[v.Attacker][v.Victim] = result[v.Attacker][v.Victim] || {};
result[v.Attacker][v.Victim][v.Weapon] = result[v.Attacker][v.Victim][v.Weapon] || 0;
++result[v.Attacker][v.Victim][v.Weapon];
});
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment