Skip to content
Extraits de code Groupes Projets
Valider 2ab870bd rédigé par Phokopi's avatar Phokopi
Parcourir les fichiers

Premier ajout des fichiers

parent
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
## Préalable
Fonctionne avec la version 2.2 (PHP 7.4 requis) de <https://github.com/julien-boudry/Condorcet/>.
## Instructions
1. Mettre le noms des listes dans candidates.txt, un par ligne, **dans l'ordre d'apparition sur les bulletins de vote**.
Attention, le fichier candidates.txt doit se terminer par une ligne vide (pas automatique avec le bloc-notes Windows par exemple !!).
2. Dans results_raw_full.txt, mettre un bulletin "oral" par ligne. Par exemple, pour 8 candidats, une ligne pourrait ressembler à : 94413929
Attention, le fichier results_raw_full.txt doit se terminer par une ligne vide (pas automatique avec le bloc-notes Windows par exemple !!).
3. Dans toDot.py, mettre les noms complets des candidats (reprendre depuis candidates.txt pour les clés), et leur attribuer une couleur. Dans le même fichier, fixer aussi la position de chaque noeud du graphe. Pour voir à quoi ressemble un polygone régulier de type circulaire, aller sur ce site <https://observablehq.com/@magjac/placing-graphviz-nodes-in-fixed-positions>, et entrer le code suivant (adapter selon le nombre de liste) :
```
dotSrc = `
digraph {
layout="circo";
oneblock=true
graph [pad="0.212,0.055" bgcolor=lightgray]
node [style=filled]
a -> b -> c -> d -> e -> f -> g -> a
}
`
```
4. Exécuter le script : `./script.sh`
\ No newline at end of file
chevaleriie
complotiiste
fiipale
hurriicane
iikea
animalerie
labyriinthe
overdriive
#!/usr/bin/env bash
# suppression des fichiers existants
rm matrice_duels.yaml
rm graph_with_text.png
rm results.dot
rm results.dot.png
rm results_raw_full_shuf.txt
rm results_raw_partial.txt
rm results_raw_partial_out.txt
rm temp.txt
rm winners.txt
rm condorcet.txt
rm *.bak
#!/bin/env python3
"""
This script transforms votes in number form into votes in mathematical form.
For example, given five candidates A, B, C, D, E, and two ballots 12345 and 11222, our output should be "A > B > C > D > E" for the first ballot, and "A = B > C = D = E" for the second ballot.
Input votes should be stored in number form in the file `results_bruts.txt`, one vote per line.
Votes in mathematical form will be written to the file `results_out.txt`, one vote per line.
TODO: mettre à jour : arg1 = fichier candidates, arg2 = fichier des votes bruts
"""
import sys
candidates = []
with open(sys.argv[1], "r") as file_candidates:
for line in file_candidates.readlines():
line = line.strip()
candidates.append(line)
nbCandidates = len(candidates)
# For example, with 8 candidates, the max rank a candidate can be given is 9 (no rank given => below every other rank).
maxRankPossible = nbCandidates + 1
with open(sys.argv[2], "r") as data:
o = open(sys.argv[2][0:-4]+"_out.txt", "w")
# * Read raw data. One line = one vote. Each line is a string with exactly nbCandidates = 8 numbers, each number is in [1, maxRankPossible].
for line in data.readlines():
line = line.strip()
# Store the highest rank for this vote, so that we know when we need to stop putting ">" at the end.
maxRank = int(max(line))
# * For each rank possible, we are going to check if one or several candidates has been given that rank.
for rank in range(1, maxRankPossible + 1):
first = True
found = False
# Check all candidates.
for ind in range(0, nbCandidates):
# If the rank given to that candidate isn't equal to the rank that we are currently checking, do nothing.
if int(line[ind]) != rank:
continue
# If another candidate has already been given that rank
if not first:
o.write(" = ")
o.write(candidates[ind])
first = False
found = True
if found and rank < maxRank:
o.write(" > ")
o.write("\n")
o.close()
46312615
47637521
43413322
57328614
33315524
14444444
31434322
34123999
39412934
45929913
99929919
14349723
51686714
43123657
32434112
45317632
22234511
13343311
53748621
36548721
34114235
57324212
66628813
66718823
13315722
58117848
66537813
94413929
21526431
45215513
55415723
43313312
34523312
14195532
43656612
45315512
23219413
38124278
47316825
44134412
35327848
13334412
14528835
23212236
67154623
12434521
33113655
99314929
14235513
64416823
46888812
94413525
23329512
26648821
35949921
56517735
23349961
45313618
66415523
34419923
48858823
88818823
45515523
99112945
41878812
66314527
44455623
24514631
13225413
24549931
49439912
48517632
23334321
99419412
45837621
45637821
45316712
45638712
13435421
12264312
99939915
14468724
22114522
56317824
24695531
75426138
78416824
54633614
51382271
65918713
39913929
33515324
75164823
44434412
88728816
14324432
44537612
55414423
34863512
76413625
13785531
47515627
34625513
16658842
56428812
56326715
63325412
44422438
39127643
99429913
99919991
56413624
11141156
34725413
55575523
78838821
33323313
11435522
24213413
44124557
51647732
43211528
55535412
33214415
43425512
23112445
77617735
37548612
35628741
46666635
64738581
37648712
67648845
23233321
25636614
48818835
13119924
33312388
56418723
88848811
31244544
99219933
45217638
12538764
54313335
23476531
35212434
56436612
34364521
33314322
63126434
67317735
27158634
32134422
35459611
77515436
99939915
35212246
25437612
83714581
45818823
99999919
76612613
25468713
31518422
18458614
43576612
13133321
88818858
48375612
12638754
#!/usr/bin/env bash
# suppression des fichiers existants
echo "" > results_raw_partial.txt
rm results_raw_partial.txt
echo "" > results_raw_partial_out.txt
rm results_raw_partial_out.txt
# shuffle des bulletins
shuf results_raw_full.txt > results_raw_full_shuf.txt
NB_BULLETIN_TOTAL=$(wc --lines < results_raw_full_shuf.txt)
NUMERO_BULLETIN=0
# une line = un bulletin sous forme oral
cat results_raw_full_shuf.txt | while read line; do
clear
NUMERO_BULLETIN=$((NUMERO_BULLETIN + 1))
# on ajoute la nouvelle ligne aux résultats bruts partiels
echo $line >> results_raw_partial.txt
# on génère le fichier results_raw_partial_out.txt, utilisé dans la suite de la boucle (les bulletins partiels "traduits")
./fill.py candidates.txt results_raw_partial.txt
# affichage du bulletin en cours
BALLOT=$(tail -1 results_raw_partial_out.txt)
echo -e "Bulletin n°${NUMERO_BULLETIN} : ${BALLOT}\n"
# utilisation de l'appli condorcet, on stocke le résultat dans le fichiet condorcet.txt
./vendor/bin/condorcet election --candidates candidates.txt --votes results_raw_partial_out.txt SchulzeWinning -p > condorcet.txt
# On stocke la ligne du ou des gagnants dans winners.txt, à traiter dans toDot.py
sed -e/Schulze/\{ -e:1 -en\;b1 -e\} -ed condorcet.txt > temp.txt && sed 4!d temp.txt > winners.txt
# On extrait la matrice des duels vers matrice_duels.yaml, puis appelle toDot.py pour générer l'image du graphe dans results.dot.png
sed '/For/,$!d' condorcet.txt > temp.txt && sed 1,2d temp.txt -i && sed '/+-/,$d' temp.txt -i && sed -r 's/\|//g' temp.txt > matrice_duels.yaml && ./toDot.py
# création de l'image avec texte numéro bulletin dans graph_with_text.png
convert -fill black -pointsize 60 -draw "text 15,70 '${NUMERO_BULLETIN}/${NB_BULLETIN_TOTAL}'" results.dot.png graph_with_text.png
echo -e "Graphe mis à jour.\n"
# on affiche le classement
sed -e/Schulze/\{ -e:1 -en\;b1 -e\} -ed condorcet.txt
sleep 2
done
#echo "Fin. ${NUMERO_BULLETIN} bulletins ont été comptabilisés."
#!/bin/env python3
import yaml
translate = {
"chevaleriie" : "ChevalerIIE",
"complotiiste" : "ComplotIIstE",
"fiipale" : "FIIPALE",
"hurriicane" : "HURRIICANE",
"iikea" : "IIKEA",
"animalerie" : "L'ANiMALERie",
"overdriive" : "OVERDRIIVE",
"labyriinthe" : "Labyriinthe"
}
colors = {
"chevaleriie" : "#C50000",
"complotiiste" : "#39AA30",
"fiipale" : "#0C631E",
"hurriicane" : "#6AD5CF",
"iikea" : "#1B56D3",
"animalerie" : "#FF00FF",
"overdriive" : "#EF7A37",
"labyriinthe" : "#CF9F00"
}
pos = {
"chevaleriie" : "0,0!",
"complotiiste" : "1,2!",
"fiipale" : "3,3!",
"hurriicane" : "5,2!",
"iikea" : "6,0!",
"animalerie" : "5,-2!",
"overdriive" : "3,-3!",
"labyriinthe" : "1,-2!"
}
# On récupère la liste des gagnants
f = open("winners.txt", "r")
lineWinners = f.readlines()[0]
winners = lineWinners.split(" | ")[1].split("*")[0].split(" ")[0].split(",")
with open('matrice_duels.yaml','r') as data:
dic = yaml.safe_load(data)
o = open("results.dot", "w")
o.write("""
Digraph G {
graph [dpi = 250, oneblock=true, outputorder=edgesfirst];
node [shape="plaintext"];
""")
for liste in dic:
if liste in winners:
o.write(liste + " [style=filled fillcolor=white label=\"" + translate[liste] + "\" fontcolor=\"" + colors[liste] + "\" fontsize=18 pos=\"" + pos[liste] + "\" shape=rectangle]\n")
else:
o.write(liste + " [label=\"" + translate[liste] + "\" fontcolor=\"" + colors[liste] + "\" pos=\"" + pos[liste] + "\"]\n")
o.write("\n")
for liste in dic:
for opp in dic[liste]["win"]:
if dic[liste]["win"][opp] > dic[opp]["win"][liste]:
o.write(liste + " -> " + opp + "[labeldistance=4 labelangle=-15 penwidth=1 headlabel=\"" + str(dic[liste]["win"][opp]) + ";" + str(dic[liste]["lose"][opp]) + "\" fontsize=9 color=\"" + colors[liste] + "\" fontcolor=\"" + colors[liste] + "\"]\n")
o.write("}\n")
o.close()
from graphviz import render
#render('dot', 'png', 'results.dot')
render('neato', 'png', 'results.dot')
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter