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

Uniformisation noms français pour fichiers

parent 2ab870bd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -8,9 +8,9 @@ Fonctionne avec la version 2.2 (PHP 7.4 requis) de <https://github.com/julien-bo
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
2. Dans resultats_complets_bruts.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 !!).
Attention, le fichier resultats_complets_bruts.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) :
```
......
......@@ -2,13 +2,13 @@
# 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 graphe_partiel_avec_texte.png
rm graphe_partiel.dot
rm graphe_partiel.dot.png
rm resultats_complets_bruts_shuf.txt
rm resultats_partiels_bruts.txt
rm resultats_partiels_out.txt
rm temp.txt
rm winners.txt
rm condorcet.txt
rm ligne_gagnants_partiels.txt
rm condorcet_output.txt
rm *.bak
......@@ -3,8 +3,8 @@
"""
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.
Input votes should be stored in number form in the file `resultats_bruts.txt`, one vote per line.
Votes in mathematical form will be written to the file `resultats_out.txt`, one vote per line.
TODO: mettre à jour : arg1 = fichier candidates, arg2 = fichier des votes bruts
"""
......@@ -21,7 +21,7 @@ nbCandidates = len(candidates)
maxRankPossible = nbCandidates + 1
with open(sys.argv[2], "r") as data:
o = open(sys.argv[2][0:-4]+"_out.txt", "w")
o = open("resultats_partiels_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()
......
Fichier déplacé
#!/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
echo "" > resultats_partiels_bruts.txt
rm resultats_partiels_bruts.txt
echo "" > resultats_partiels_out.txt
rm resultats_partiels_out.txt
# shuffle des bulletins
shuf results_raw_full.txt > results_raw_full_shuf.txt
shuf resultats_complets_bruts.txt > resultats_complets_bruts_shuf.txt
NB_BULLETIN_TOTAL=$(wc --lines < results_raw_full_shuf.txt)
NB_BULLETIN_TOTAL=$(wc --lines < resultats_complets_bruts_shuf.txt)
NUMERO_BULLETIN=0
# une line = un bulletin sous forme oral
cat results_raw_full_shuf.txt | while read line; do
cat resultats_complets_bruts_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
echo $line >> resultats_partiels_bruts.txt
# on génère le fichier resultats_partiels_out.txt, utilisé dans la suite de la boucle (les bulletins partiels "traduits")
./fill.py candidates.txt resultats_partiels_bruts.txt
# affichage du bulletin en cours
BALLOT=$(tail -1 results_raw_partial_out.txt)
BALLOT=$(tail -1 resultats_partiels_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
# utilisation de l'appli condorcet, on stocke le résultat dans le fichiet condorcet_output.txt
./vendor/bin/condorcet election --candidates candidates.txt --votes resultats_partiels_out.txt SchulzeWinning -p > condorcet_output.txt
# On stocke la ligne du ou des gagnants dans ligne_gagnants_partiels.txt, à traiter dans toDot.py
sed -e/Schulze/\{ -e:1 -en\;b1 -e\} -ed condorcet_output.txt > temp.txt && sed 4!d temp.txt > ligne_gagnants_partiels.txt
# On extrait la matrice des duels vers matrice_duels.yaml, puis appelle toDot.py pour générer l'image du graphe dans graphe_partiel.dot.png
sed '/For/,$!d' condorcet_output.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 graphe_partiel_avec_texte.png
convert -fill black -pointsize 60 -draw "text 15,70 '${NUMERO_BULLETIN}/${NB_BULLETIN_TOTAL}'" graphe_partiel.dot.png graphe_partiel_avec_texte.png
echo -e "Graphe mis à jour.\n"
# on affiche le classement
sed -e/Schulze/\{ -e:1 -en\;b1 -e\} -ed condorcet.txt
sed -e/Schulze/\{ -e:1 -en\;b1 -e\} -ed condorcet_output.txt
sleep 2
done
......
......@@ -36,13 +36,13 @@ pos = {
}
# On récupère la liste des gagnants
f = open("winners.txt", "r")
f = open("ligne_gagnants_partiels.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 = open("graphe_partiel.dot", "w")
o.write("""
Digraph G {
graph [dpi = 250, oneblock=true, outputorder=edgesfirst];
......@@ -62,5 +62,5 @@ node [shape="plaintext"];
o.close()
from graphviz import render
#render('dot', 'png', 'results.dot')
render('neato', 'png', 'results.dot')
#render('dot', 'png', 'graphe_partiel.dot')
render('neato', 'png', 'graphe_partiel.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