mapPuestos = {
data.map((d) => {
d.id = d.codigo;
const candidatesVotes = candidates
.map((c, i) => ({
pct: d[c.replace("_vot", "_pvot")],
iCand: i
}))
.sort((a, b) => d3.descending(a.pct, b.pct));
for (let c of candidates) {
d[c.replace("_vot", "_pct")] = d[c.replace("_vot", "_pvot")];
d[c + "_pct_cand"] = d[c] / mapTotalCands.get(c);
}
d.iWinner = candidatesVotes[0].iCand;
d.Ganador = candidatesVotes[0].pct;
d.candidatesVotes = candidatesVotes;
d.candidatesRanking = candidatesVotes.map((d) => d.iCand).join(",");
return d;
});
return new Map(data.map((d) => [d.id, d]));
}