Public
Edited
Jul 4, 2024
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatCircoForTable = (c) => {
const resEst = resultats[c];

//dernier qualifie
let min = undefined,
dernierQ = undefined;
for (let q of resEst.qualifies) {
const score = resEst.estimation[q];
if (min && score > min) continue;
min = score;
dernierQ = q;
}
return {
circonscription: getCircoLabel(resEur2024[c]),
code: c,
configuration: resEst.qualifies.join(", "),
"Nombre qualifiés": resEst.qualifies.length,
"Bloc sortant": resEst.sortant,
"Parti NFP": accordNFP[c],
Exprimés: Math.round(resEst.exprimes),
Inscrits: Math.round(resEst.inscrits),
"participation (%)": ((resEst.exprimes / resEst.inscrits) * 100).toFixed(1),
"Dernier qualifié": dernierQ,
"Seuil qualif dernier (%)": (
(resEst.estimation[dernierQ] /
(qualifExpr ? resEst.exprimes : resEst.inscrits)) *
100
).toFixed(1),
"Seuil qualif NFP (%)": resEst.estimation.NFP
? (
(resEst.estimation.NFP /
(qualifExpr ? resEst.exprimes : resEst.inscrits)) *
100
).toFixed(1)
: "",
"NFP (%)": resEst.estimationPourcentage.NFP
? resEst.estimationPourcentage.NFP.toFixed(1)
: "",
"MP (%)": resEst.estimationPourcentage.MP
? resEst.estimationPourcentage.MP.toFixed(1)
: "",
"D (%)": resEst.estimationPourcentage.D
? resEst.estimationPourcentage.D.toFixed(1)
: "",
"REC (%)": resEst.estimationPourcentage.REC
? resEst.estimationPourcentage.REC.toFixed(1)
: "",
"RN (%)": resEst.estimationPourcentage.RN
? resEst.estimationPourcentage.RN.toFixed(1)
: "",
"RN+REC+D/2 (%)":
resEst.estimationPourcentage.RN ||
resEst.estimationPourcentage.REC ||
resEst.estimationPourcentage.D
? (
(resEst.estimationPourcentage.RN || 0) +
(resEst.estimationPourcentage.REC || 0) +
0.5 * (resEst.estimationPourcentage.D || 0)
).toFixed(1)
: "",

"MP+D/2 (%)":
resEst.estimationPourcentage.MP || resEst.estimationPourcentage.D
? (
(resEst.estimationPourcentage.MP || 0) +
0.5 * (resEst.estimationPourcentage.D || 0)
).toFixed(1)
: "",
"NFP+MP*2/3 (%)":
resEst.estimationPourcentage.NFP || resEst.estimationPourcentage.MP
? (
(resEst.estimationPourcentage.NFP || 0) +
((resEst.estimationPourcentage.MP || 0) * 2) / 3
).toFixed(1)
: ""
};
}
Insert cell
Insert cell
Insert cell
resultats.resNat
Insert cell
resultats = {
const out = {};

//calcule les estimations pour toutes les circos
for (let c of codesCircos) {
out[c] = getResultatsEstimes(c);
}

//calcule les résultats niveau national
const resNat = { NFP: 0, D: 0, MP: 0, RN: 0, REC: 0, exprimes: 0 };
//aggrege résultats des circos
for (let circo of codesCircos) {
const res = out[circo];
//aggrege les voix des blocs
for (let bloc of res.circoBlocs) {
resNat[bloc] += +res.estimation[bloc];
resNat.exprimes += +res.estimation[bloc];
}
}
//en pourcentages
for (let bloc of Object.keys(resNat))
resNat[bloc] = +((100 * resNat[bloc]) / resNat.exprimes).toFixed(2);

//calcul des coefficients de redressement, à appliquer au résultat de chacun des blocs
let sommePoids = 0;
for (let bloc of Object.keys(sondagesNationauxParBloc))
sommePoids += +sondagesNationauxParBloc[bloc];
const coeffsRedressement = {};
for (let bloc of Object.keys(resNat))
coeffsRedressement[bloc] =
(sondagesNationauxParBloc[bloc] / resNat[bloc]) * (100 / sommePoids);
//console.log(coeffsRedressement);

//redresse les résultats par circo
for (let circo of codesCircos) {
const res = out[circo];

//redressement
if (redressementFinal)
for (let bloc of res.circoBlocs) {
res.estimation[bloc] *= coeffsRedressement[bloc];
//console.log(res_.estimation[bloc], coeffsRedressement[bloc]);
}

//calcule exprimes
res.exprimes = 0;
for (let bloc of res.circoBlocs) res.exprimes += res.estimation[bloc];

//estimation en pourcentage
//avec detection election premier tour
res.estimationPourcentage = {};
res.elu = undefined;
for (let bloc of res.circoBlocs) {
res.estimationPourcentage[bloc] =
(res.estimation[bloc] * 100) / res.exprimes;
if (res.estimationPourcentage[bloc] > 50) res.elu = bloc;
}

//liste des qualifies au second tour (12.5% des inscrits)
res.qualifies = [];
for (let bloc of res.circoBlocs)
if (
res.estimation[bloc] / (qualifExpr ? res.exprimes : res.inscrits) >=
0.125
)
res.qualifies.push(bloc);

//garde aussi la fonction pour détermine si un bloc est qualifié. Pour le diagramme.
res.qualification = (bloc) =>
res.estimation[bloc] / (qualifExpr ? res.exprimes : res.inscrits) >=
0.125;
}

out.resNat = resNat;
return out;
}
Insert cell
Insert cell
getResultatsEstimes = (circo) => {
//liste des candidats
const candidats = getCandidats(circo);

//resultats européennes 2024
const resEur24 = resEur2024[circo];
const txParticipationEur2024 = +resEur24.Exprimes / +resEur24.Inscrits;

//taux de participation estimé
const participationProjetee =
txParticipationEur2024 * ameliorationParticipation;
//nb nouveaux votes à partager
const nbVoixAPartager =
+resEur24.Inscrits * participationProjetee - +resEur24.Exprimes;

//liste des nuances de la circo
const circoNuances = candidats.map((c) => c.CodNuaCand);

//récupère les blocs représentés en fonction de ces nuances
const circoBlocs = nuancesVersBlocs(circoNuances);

//ventilation des nouveaux votes
//poids par bloc
const ventAbst = {
NFP: ventAbstVersNFP,
MP: ventAbstVersMP,
D: ventAbstVersD,
REC: ventAbstVersREC,
RN: ventAbstVersRN
};

//somme des poids
let sp = 0;
for (let b of circoBlocs) sp += ventAbst[b];

//recupere les listes des blocs, en fonction de la configuration
const blocsListe = getBlocsListe(circoBlocs.join("_"));

//calcule les estimations par bloc
const estimation = {};
for (let b of circoBlocs) {
let v = 0;

//ajoute voix des listes des européennes
const listes = blocsListe[b];
for (let liste of listes) v += +resEur24["v" + liste];

//ajoute part nouveaux votes
v += (nbVoixAPartager * ventAbst[b]) / sp;

estimation[b] = v;
}

//regle speciale: prime au sortant
if (primeSortant) {
//trouve sortants
let s = candidats.filter((c) => c.sortant == "1");
//garde les nuances
s = s.map((c) => c.CodNuaCand);
//garde nuances sujettes à prime
const an = accordNFP[circo];
s = s.filter(
(n) =>
n == "RN" ||
n == "LR" ||
n == "HOR" ||
n == "ECO" ||
n == "SOC" ||
(n == "UG" && (an == "PS" || an == "EELV" || an == "PCF"))
);
if (s.length > 0) {
//if (s.length > 1) console.log(circo + " " + s);
//nuance sortante
s = s[0];
//bloc correspondant à la nuance du sortant
const blocSortant = nuancesVersBlocs([s])[0];
//ajoute 10%
const mvt = estimation[blocSortant] * 0.1;
estimation[blocSortant] += mvt;
//TODO retirer ces votes aux autres candidats - ceux des 1/2 nuances les plus proches
}
}

//regle spéciale: 20% LR vers MP
if (LRDvMP && circoBlocs.includes("MP") && circoBlocs.includes("D")) {
const mvt = estimation["D"] * 0.2;
estimation["MP"] += mvt;
estimation["D"] -= mvt;
}

//regle spéciale: 40% de PS+EELV vers MP si NFP=LFI
if (
PSEELVvMP &&
circoBlocs.includes("MP") &&
circoBlocs.includes("NFP") &&
accordNFP[circo] === "LFI"
) {
const mvt = (+resEur24["v27"] + +resEur24["v6"]) * 0.4;
estimation["MP"] += mvt;
estimation["NFP"] -= mvt;
}

//recupere bloc du sortant
const sortant = nuancesVersBlocs(
candidats.filter((c) => c.sortant == "1").map((c) => c.CodNuaCand)
).join("_");

return {
estimation: estimation,
inscrits: +resEur24.Inscrits,
circoBlocs: circoBlocs,
nbVoixAPartager: nbVoixAPartager,
candidats: candidats,
sortant: sortant
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more