Skip to content

Instantly share code, notes, and snippets.

@radmiraal
Created January 9, 2013 14:34
Show Gist options
  • Save radmiraal/4493576 to your computer and use it in GitHub Desktop.
Save radmiraal/4493576 to your computer and use it in GitHub Desktop.
function(doc) { emit(
[
doc.city,
'indicator_beroepsbevolking',
parseInt(doc.date.substr(0, 4))
],
Math.round((100 / doc.data.inwoners) * doc.data.beroepsbevolking)
);
emit(
[
doc.city,
'indicator_werkloosheidoptotaal',
parseInt(doc.date.substr(0, 4))
],
Math.round((100 / doc.data.inwoners) * doc.data.werklozen)
);
emit(
[
doc.city,
'indicator_werkloosheidopberoepsbevolking',
parseInt(doc.date.substr(0, 4))
],
Math.round((100 / doc.data.beroepsbevolking) * doc.data.werklozen)
);
}
reduce
function(keys, values, rereduce) {
if (!rereduce){
var length = values.length
return [sum(values) / length, length]
}else{
var length = sum(values.map(function(v){return v[1]}))
var avg = sum(values.map(function(v){
return v[0] * (v[1] / length)
}))
return [avg, length]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment