Created
August 1, 2016 18:36
-
-
Save juniorUsca/5d8ffefb3e893eb83decf82149e814c2 to your computer and use it in GitHub Desktop.
Funciones de map reduce para sumar los intereses de las personas por pais
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
/// SUMA DE INTERESES POR PAIS | |
var mapFun = function () { | |
var intereses = {}; | |
for (var i = this.intereses.length - 1; i >= 0; i--) { | |
intereses[ this.intereses[i] ] = 1; | |
} | |
emit( this.pais, intereses ); | |
}; | |
var reduceFun = function (key, value) { | |
var temp = value[value.length-1]; | |
for (var i = value.length - 2; i >= 0; i--) { | |
var inters = value[i]; | |
for ( var attr in inters) { | |
if (temp.hasOwnProperty(attr)) | |
temp[attr] = temp[attr] + inters[attr]; | |
else | |
temp[attr] = inters[attr]; | |
} | |
} | |
return temp; | |
}; | |
var finalizeFun = function (key, reducedVal) { | |
var intereses = { musica: 0, arte: 0, juegos: 0, peliculas: 0, anime: 0, vida: 0, amanecer: 0, amor: 0, familia: 0, tv: 0, 'medio ambiente': 0, mechanotherapeutic: 0, protectorate: 0, phytopaleontological: 0, springlet: 0, diectasis: 0, sconcheon: 0, noncompetitive: 0, bellonion: 0, hami: 0, accusable: 0, operatable: 0, linitis: 0, hoastman: 0, unlanguid: 0, isokurtic: 0, benchboard: 0, gastroplication: 0, alumiferous: 0, chapterful: 0, yeldrock: 0, axopodia: 0, smokebox: 0, fireworky: 0, semideltaic: 0, intimation: 0, tarsioid: 0, fotui: 0, woft: 0, Mandingo: 0, pretincture: 0, pamper: 0, extraneously: 0, consternation: 0, malleate: 0, thisn: 0, ribbony: 0, Lapland: 0, Monticulipora: 0, cetylene: 0, fie: 0, pluvious: 0, gunl: 0, monsieur: 0, producal: 0, Limnophilidae: 0, daitya: 0, octahedral: 0, pegger: 0 }; | |
for ( var attr in reducedVal) { | |
intereses[attr] = reducedVal[attr]; | |
} | |
return intereses; | |
}; | |
// db.personas.mapReduce(mapFun, reduceFun, {out: "intereses_pais", finalize: finalizeFun, verbose: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment