crosscheck with existing library
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user