Skip to content

Commit

Permalink
Réduction du volume d'information imprimées.
Browse files Browse the repository at this point in the history
Par défaut seulement le détail du calcul du classement du joueur demandé
est affiché, quelle que soit la profondeur du calcul.

Il est possible d'afficher plus de détails en spécifiant l'argument -d N
où N est le nombre de niveaux de profondeur pour lesquels afficher les
détails de calcul (par défaut : 0).
Exemple : -d 1 affichera les détails pour les adversaires du joueur demandé
  • Loading branch information
NicolasP committed Aug 5, 2019
1 parent b1176a9 commit ae1b2ed
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 46 deletions.
71 changes: 40 additions & 31 deletions classement.py
Expand Up @@ -186,8 +186,9 @@
"Top 40/Top 60" : -2}

# affiche le classement calculé d'un joueur
def afficheClassement( origine, calcul, harmonise ):
print(" ==> Classement de sortie :", calcul, "- Harmonisé :" , harmonise, "- classement d\'origine :", origine)
def afficheClassement( origine, calcul, harmonise, impression=True ):
if impression:
print(" ==> Classement de sortie :", calcul, "- Harmonisé :" , harmonise, "- classement d\'origine :", origine)
return


Expand Down Expand Up @@ -247,16 +248,17 @@ def pointsVictoire( myClassement, classementBattu ):
return points[ diff ]

# Retourne le nombre de victoires prises en compte
def nbVictoiresComptant( myClassement, sexe, myVictoires, myDefaites ):
def nbVictoiresComptant( myClassement, sexe, myVictoires, myDefaites, impression=True ):
if( "M" == sexe ):
victoires = victoiresH
else:
victoires = victoiresF

nb = victoires[ myClassement ]
v = VE2I5G( myClassement, myVictoires, myDefaites, impression=True )
v = VE2I5G( myClassement, myVictoires, myDefaites, impression )

print("V - E - 2I - 5G :", v)
if impression:
print("V - E - 2I - 5G :", v)

add = 0
if( 4 == serie[ myClassement ] ):
Expand Down Expand Up @@ -343,12 +345,13 @@ def nbVictoiresComptant( myClassement, sexe, myVictoires, myDefaites ):


# Calcule les points a un classement donne
def calculPoints( myClassement, sexe, myVictoires, myDefaites, nbVicChampIndiv ):
nbV = nbVictoiresComptant( myClassement, sexe, myVictoires, myDefaites )
def calculPoints( myClassement, sexe, myVictoires, myDefaites, nbVicChampIndiv, impression=True ):
nbV = nbVictoiresComptant( myClassement, sexe, myVictoires, myDefaites, impression )
sortedVictoires = sortVictoires( myVictoires )
victoiresComptant = victoiresQuiComptent( sortedVictoires, nbV )

print("Victoires prises en compte ({}) : {}".format(nbV, match_list_str(victoiresComptant)))
if impression:
print("Victoires prises en compte ({}) : {}".format(nbV, match_list_str(victoiresComptant)))

nbPoints = 0

Expand All @@ -372,7 +375,7 @@ def calculPoints( myClassement, sexe, myVictoires, myDefaites, nbVicChampIndiv )
if myClassement == '30/2' or myClassement == '30/1' :
if True == absenceDef( myDefaites, myClassement ):
bonif = 50
if bonif != 0:
if bonif != 0 and impression:
print("Bonif absence de defaite significative:", bonif)

nbPoints = nbPoints + bonif
Expand All @@ -382,7 +385,7 @@ def calculPoints( myClassement, sexe, myVictoires, myDefaites, nbVicChampIndiv )
bonif = nbVicChampIndiv * 15

nbPoints = nbPoints + bonif
if bonif != 0:
if bonif != 0 and impression:
print("Bonif championnat indiv :", bonif)

return int(nbPoints)
Expand All @@ -396,13 +399,14 @@ def sortVictoires( myVictoires ):


# Teste si les points de maintien sont atteints pour le classement
def maintienOK( myClassement, mySexe, myPoints ):
def maintienOK( myClassement, mySexe, myPoints, impression=True ):
if 'M' == mySexe:
maintien = maintienH
else:
maintien = maintienF

print("Points acquis :", myPoints, "- points nécessaires pour le maintien à", myClassement, ":", maintien[ myClassement ])
if impression:
print("Points acquis :", myPoints, "- points nécessaires pour le maintien à", myClassement, ":", maintien[ myClassement ])

return myPoints >= maintien[myClassement]

Expand Down Expand Up @@ -502,7 +506,7 @@ def nbWO( tab ):
return n

# Insertion de la penalite wo : a partir de 3, tout wo compte comme une defaite significative
def penaliteWO( defaites ):
def penaliteWO( defaites, impression=True ):
_def = []
w = 0
for d in defaites:
Expand All @@ -511,7 +515,8 @@ def penaliteWO( defaites ):
if w >= 3:
o = ( 'S', d[1] )
# on insere une defaite qu'on appelle S pour que ca compte comme une def significative
print("Defaite significative ajoutée (wo)")
if impression:
print("Defaite significative ajoutée (wo)")
else:
o = d
else:
Expand All @@ -534,43 +539,44 @@ def victoiresQuiComptent( vic, nb ):
return [v for v in vic if not v[1]][:nb]

# Calcul du classement
def calculClassement( myVictoires, myDefaites, mySexe, myClassement, nbVicChampIndiv ):
def calculClassement( myVictoires, myDefaites, mySexe, myClassement, nbVicChampIndiv, impression ):

ok = False

if estNumerote( myClassement ):
print("Cas particulier : le joueur est numéroté. On le calcule au meme classement.")
afficheClassement( myClassement, myClassement, myClassement )
if impression:
print("Cas particulier : le joueur est numéroté. On le calcule au meme classement.")
afficheClassement( myClassement, myClassement, myClassement )
return ( myClassement, myClassement )

if 0 == len( victoiresQuiComptent( myVictoires, len( myVictoires ) ) ):

if( 'NC' == myClassement ):
if 0 != len( myDefaites ):
afficheClassement( myClassement, '40', '40' )
afficheClassement( myClassement, '40', '40', impression )
return ( '40', '40' )
else:
afficheClassement( myClassement, '40', '40' )
afficheClassement( myClassement, '40', '40', impression )
return ( 'NC', 'NC' )
else:
cl = echelonInferieur( myClassement )
if 'NC' == cl:
if 0 != len( myDefaites ):
afficheClassement( myClassement, '40', '40' )
afficheClassement( myClassement, '40', '40', impression )
return ( '40', '40' )
else:
afficheClassement( myClassement, '40', '40' )
afficheClassement( myClassement, '40', '40', impression )
return ( 'NC', 'NC' )
else:
afficheClassement( myClassement, cl, cl )
afficheClassement( myClassement, cl, cl, impression )
return ( cl, cl )

myVictoires = normalisationTab( myVictoires, mySexe )
myDefaites = normalisationTab( myDefaites, mySexe )

# Insertion de la penalite wo
if nbWO( myDefaites ) >= 3:
myDefaites = penaliteWO( myDefaites )
myDefaites = penaliteWO( myDefaites, impression )

myClassement = normalisation( myClassement, mySexe )

Expand All @@ -579,10 +585,11 @@ def calculClassement( myVictoires, myDefaites, mySexe, myClassement, nbVicChampI

while( ( False == ok ) and ( "NC" != classementPropose ) and not ( classementPropose is borneInf ) ):

print(" ==> Classement proposé :", classementPropose)
if impression:
print(" ==> Classement proposé :", classementPropose)

pt = calculPoints( classementPropose, mySexe, myVictoires, myDefaites, nbVicChampIndiv )
ok = maintienOK( classementPropose, mySexe, pt )
pt = calculPoints( classementPropose, mySexe, myVictoires, myDefaites, nbVicChampIndiv, impression )
ok = maintienOK( classementPropose, mySexe, pt, impression )
if( True != ok ):
classementPropose = echelonInferieur( classementPropose )

Expand All @@ -591,14 +598,16 @@ def calculClassement( myVictoires, myDefaites, mySexe, myClassement, nbVicChampI

# penalite WO ?
if nbWO( myDefaites ) >= 5:
print("Penalite car trop de WO (", nbWO( myDefaites ), "> 5)")
if impression:
print("Penalite car trop de WO (", nbWO( myDefaites ), "> 5)")
classementHarmonise = echelonInferieur( classementPropose )

# penalite mauvais V - E - 2I - 5G ?
if 2 == serie[ classementHarmonise ]:
v = VE2I5G( classementHarmonise, myVictoires, myDefaites )
v = VE2I5G( classementHarmonise, myVictoires, myDefaites, impression=False )
if v <= -100:
print("Joueur en 2eme serie, V-E-2I-5G inférieur ou égal à 100 (" + str( v ) + ") : pénalité et descente d'un classement")
if impression:
print("Joueur en 2eme serie, V-E-2I-5G inférieur ou égal à 100 (" + str( v ) + ") : pénalité et descente d'un classement")
classementHarmonise = echelonInferieur( classementHarmonise )

if 'NC' == classementPropose:
Expand All @@ -607,7 +616,7 @@ def calculClassement( myVictoires, myDefaites, mySexe, myClassement, nbVicChampI
else:
classementPropose = classementHarmonise = 'NC'

afficheClassement( myClassement, classementPropose, classementHarmonise )
afficheClassement( myClassement, classementPropose, classementHarmonise, impression )

return ( classementPropose, classementHarmonise )

Expand Down Expand Up @@ -733,7 +742,7 @@ def test():
"""

calculClassement( testVic_n, testDef_n, testSexe, classement, champ )
calculClassement( testVic_n, testDef_n, testSexe, classement, champ, True )



Expand Down
48 changes: 33 additions & 15 deletions palmares.py
Expand Up @@ -416,16 +416,17 @@ def print_line(r):

chaine += " === DÉFAITES ===\n"
if len(joueur.defaites) == 0:
chaine += "Aucune"
chaine += "Aucune\n"
else:
for d in joueur.defaites:
chaine += print_line(d) + "\n"
return chaine


# Calcule le classement d'un joueur
def classementJoueur(joueur, sexe, profondeur):
def classementJoueur(joueur, sexe, profondeur, details_profondeur):
"""
:param details_profondeur: Seuil de profondeur à partir duquel les détails sont affichés
:type joueur: Joueur
"""

Expand All @@ -445,35 +446,48 @@ def classementJoueur(joueur, sexe, profondeur):
else:
# calcul du futur classement de mes victoires
for v in joueur.victoires:
nc, harm, s = classementJoueur(v.joueur, sexe, profondeur - 1)
nc, harm, s = classementJoueur(v.joueur, sexe, profondeur - 1, details_profondeur)
v.joueur.classement_calcul = nc
myV.append((nc, v.wo, v.coefficient))

# calcul du futur classement de mes defaites
for d in joueur.defaites:
nc, harm, s = classementJoueur(d.joueur, sexe, profondeur - 1)
nc, harm, s = classementJoueur(d.joueur, sexe, profondeur - 1, details_profondeur)
d.joueur.classement_calcul = nc
myD.append((nc, d.wo, d.coefficient))

print("Calcul du classement de {} (profondeur {})".format(joueur.nom, profondeur)
.encode(sys.stdout.encoding, errors='replace'))
impression = profondeur >= details_profondeur

if impression:
print("Calcul du classement de {} (profondeur {})".format(joueur.nom, profondeur)
.encode(sys.stdout.encoding, errors='replace'))

# nb de victoires en championnat indiv
champ = nbVictoiresChamp(joueur.victoires)
print(champ, "victoire(s) en championnat individuel")
if impression:
print(champ, "victoire(s) en championnat individuel")

# calcul du classement a jour
cl, harm = calculClassement(myV, myD, sexe, joueur.classement, champ)
cl, harm = calculClassement(myV, myD, sexe, joueur.classement, champ, impression)

# sorties
s = strClassement(joueur, cl, harm)
print(s.encode(sys.stdout.encoding, errors='replace'))
if impression:
# sorties
s = strClassement(joueur, cl, harm)
print(s.encode(sys.stdout.encoding, errors='replace'))
else:
s = None

return cl, harm, s


def recupClassement( login, password, LICENCE, profondeur ):

def recupClassement( login, password, LICENCE, profondeur, details_profondeur=0 ):
"""
:param profondeur: Le niveau de profondeur maximum du calcul
:param details_profondeur: Le nombre de niveaux de profondeur pour lesquels on veut afficher les détails
(0: seulement le résultat final)
:return:
"""

# On s'identifie et on obtient ses prores infos
cj, op = buildOpener()
authentification( login, password, op, cj )
Expand All @@ -494,7 +508,8 @@ def recupClassement( login, password, LICENCE, profondeur ):
getPalmaRecursif(millesime, joueur, op, profondeur)

# calcul du nouveau classement
new_cl, harm, s = classementJoueur(joueur, sexe, profondeur)
new_cl, harm, s = classementJoueur(joueur, sexe, profondeur,
profondeur - min(details_profondeur, profondeur))

print("Nouveau classement: ", harm, " (après harmonisation) - ", new_cl, " (calculé)")

Expand Down Expand Up @@ -525,6 +540,9 @@ def main():
parser.add_argument("profondeur", nargs="?", default=None, type=int)
parser.add_argument("-f", "--force", action="store_true",
help="Désactive le message de confirmation en cas de profondeur élevée")
parser.add_argument("-d", "--details", type=int, default=0,
help="Le nombre de niveaux de profondeurs pour lesquels on veut afficher"
"le détail du calcul. Par défaut : 0 (le résultat final uniquement)")
args = parser.parse_args()

login = args.login if args.login else raw_input("Identifiant : ")
Expand All @@ -548,7 +566,7 @@ def main():
if not confirmation():
return -1

recupClassement(login, password, licence, profondeur)
recupClassement(login, password, licence, profondeur, args.details)
return


Expand Down

0 comments on commit ae1b2ed

Please sign in to comment.