crosscheck with existing library

This commit is contained in:
philippe lhardy
2025-07-03 13:00:00 +02:00
parent 2694ca7165
commit 48649872f4
4 changed files with 49 additions and 17 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/code/lib
/code/bin

9
INSTALL.md Normal file
View File

@@ -0,0 +1,9 @@
Not ready for produciton, still a development feature
dependency on
with python venv installed in code
code/bin/pip3 install git+https://github.com/MieuxVoter/majority-judgment-library-python

View File

@@ -1,11 +1,11 @@
import json
import sys
from majority_judgment import majority_judgment
verbose=False
def collect_votes(votes,candidats,mentions,warnings):
def collect_votes(votes,candidats,default_mention,warnings):
collect={}
default_mention=mentions-1
for vote in votes:
# missing candidat in vote picks the worse one
for candidat in candidats:
@@ -24,9 +24,18 @@ def collect_votes(votes,candidats,mentions,warnings):
else:
collect[candidat]={mention:1}
return collect
def arrange_votes_par_candidat(votes,candidats,default_mention):
vpc={}
for candidat in candidats:
vpc[candidat]=[vote[candidat] if candidat in vote else default_mention for vote in votes]
return vpc
def jugement_majoritaire(poll):
verbose=False
crosscheck=True
votants=poll['votants']['decompte']
candidats=poll['candidats']
nombre_candidats=len(candidats)
@@ -34,6 +43,7 @@ def jugement_majoritaire(poll):
# l'ordre des mentions est de la meilleure à la pire (reject)
nom_mentions=poll['mentions']
mentions=len(nom_mentions)
default_mention=mentions-1
votes=poll["votation"]["votes"]
if verbose:
@@ -42,7 +52,7 @@ def jugement_majoritaire(poll):
warnings=[]
collect=collect_votes(votes,list(candidats),mentions,warnings)
collect=collect_votes(votes,list(candidats),default_mention,warnings)
if verbose:
print(collect)
@@ -57,6 +67,8 @@ def jugement_majoritaire(poll):
mention_mediane={}
merite_pourcent={}
votes_par_candidat=arrange_votes_par_candidat(votes,candidats,mentions-1)
# cumul : du meilleur au pire
# range_mentions = range(len(mentions))
# cumul du pire au meilleur
@@ -98,7 +110,15 @@ def jugement_majoritaire(poll):
print(found)
print(nom_mentions[mention])
# expanded=expand_collect(collect,list(candidats),mentions)
if verbose:
print(votes_par_candidat)
result = {'resultat':{'mention':nom_mentions[mention],'candidats':found},'merite':merite,'profil':merite_pourcent,"warnings":warnings}
if crosscheck:
# cross check with a well known implementation
result["crosscheck"]=majority_judgment(votes_par_candidat, reverse=True)
return result

View File

@@ -24,6 +24,7 @@ https://en.wikipedia.org/wiki/Jugement_majoritaire
|------------------|-----------------------------|-------------|
|https://github.com/MieuxVoter/mieuxvoter.fr||18/20|
|https://github.com/CitoyensDeDemain/JugementMajoritaire|Il y a un algo, mais pas de format de donnée, données hardcodées / API et pas de procédure d'install|11/20|
|https://github.com/flaviencathala/jugement-majoritaire-daml|Smart contract|10/20|
|https://github.com/ostix360/JugementMajoritaire|Où est l'algo ?|2/20|
|https://github.com/AlexJade23/JugementMajoritaire|RAS VIDE|1/20|
|
@@ -72,6 +73,8 @@ Très courte ( ./majority_judgment/__init__.py 145 lignes )
(!) ?
/!\ Attention à l'ordre : par défaut le plus grand est le meilleur , il faut utiliser reverse=True pour l'inverser.
## API REST python
https://github.com/MieuxVoter/majority-judgment-api-python
@@ -455,8 +458,18 @@ if ($sum != 0){
}
```
alghorithme harcodé avec les mentions.
algorithme harcodé avec les mentions.
# https://github.com/flaviencathala/jugement-majoritaire-daml
DAML
langage for smart contracts : blockchain donc.
# https://github.com/jeromeschwaederle/Vote_Jugement_Majoritaire
python simple
# OpenClassRooms Jugement Majoritaire
@@ -477,7 +490,7 @@ https://github.com/s-t-e-v/jugement_majoritaire
python
Il y a une fonciton de deparatage.
Il y a une fonction de deparatage.
## mrflofinou Suffrage_jugement_majoritaire
@@ -488,7 +501,6 @@ https://github.com/mrflofinou/Suffrage_jugement_majoritaire
https://github.com/mrflofinou/Suffrage_jugement_majoritaire/blob/master/jugement_majoritaire.py
## https://github.com/E-Bellec/majoritary-judgment
## https://github.com/mstoure/Algorithme_de_jugement_majoritaire
@@ -502,14 +514,3 @@ Il ne semble pas y avoir de code pour l'algorithme, est-ce une tentative sans ac
https://www.linkedin.com/in/lucile-decrozant-triquenaux/ ?
# https://github.com/flaviencathala/jugement-majoritaire-daml
DAML
langage for smart contracts : blockchain donc.
# https://github.com/jeromeschwaederle/Vote_Jugement_Majoritaire
python simple