Pylint était tout triste.
This commit is contained in:
parent
3f1b7401ca
commit
33eac6ffac
1 changed files with 84 additions and 63 deletions
|
@ -20,75 +20,95 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||||
|
"""
|
||||||
|
Ce script permet de se faire mousser en listant les câbleurs et leurs
|
||||||
|
stats.
|
||||||
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
|
||||||
import datetime
|
import datetime
|
||||||
import string
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from lc_ldap import shortcuts
|
import lc_ldap.shortcuts as shortcuts
|
||||||
import lc_ldap.crans_utils as crans_utils
|
import lc_ldap.crans_utils as crans_utils
|
||||||
import gestion.config as config
|
import gestion.config as config
|
||||||
import gestion.affichage as affichage
|
import gestion.affichage as affichage
|
||||||
|
|
||||||
|
from cranslib.decorators import static_var
|
||||||
from config import ann_scol
|
from config import ann_scol
|
||||||
|
|
||||||
### Appels à LDAP et tri initial sur l'année en cours
|
|
||||||
db = shortcuts.lc_ldap_readonly()
|
### Appels à LDAP et tri initial sur l'année en cours.
|
||||||
adherents = db.search(u'(&(debutAdhesion>=%s)(aid=*))' % (crans_utils.to_generalized_time_format(config.debut_periode_transitoire)), sizelimit=2000)
|
DB = shortcuts.lc_ldap_readonly()
|
||||||
cableurs = db.search(u'(|(droits=cableur)(droits=nounou))')
|
SCORES = []
|
||||||
scores = []
|
HISTORIQUE = []
|
||||||
historique = []
|
ENCODING = sys.stdout.encoding or "UTF-8"
|
||||||
encoding = sys.stdout.encoding or "UTF-8"
|
|
||||||
|
@static_var(("data", []))
|
||||||
|
def adherents(regen=False):
|
||||||
|
"""Fonction évaluée paresseusement pour retourner la liste des
|
||||||
|
adhérents"""
|
||||||
|
|
||||||
|
if regen or not adherents.data:
|
||||||
|
adherents.data = DB.search(u'(&(debutAdhesion>=%s)(aid=*))' % (crans_utils.to_generalized_time_format(config.debut_periode_transitoire)), sizelimit=2000)
|
||||||
|
return list(adherents.data)
|
||||||
|
|
||||||
|
@static_var(("data", []))
|
||||||
|
def cableurs(regen=False):
|
||||||
|
"""Fonction évaluée paresseusement pour retourner la liste des
|
||||||
|
câbleurs"""
|
||||||
|
|
||||||
|
if regen or not cableurs.data:
|
||||||
|
cableurs.data = DB.search(u'(|(droits=cableur)(droits=nounou))')
|
||||||
|
return list(cableurs.data)
|
||||||
|
|
||||||
#### On prends les historiques de tout les adhérents
|
#### On prends les historiques de tout les adhérents
|
||||||
def parse_historique(ligne):
|
def parse_historique(ligne):
|
||||||
"""Parse une ligne d'historique et renvoie [ligne parsée],action
|
"""Parse une ligne d'historique et renvoie [ligne parsée],action
|
||||||
du cableur, date de l'action"""
|
du cableur, date de l'action"""
|
||||||
champ = ligne.value.replace(',','').replace(':','').split(' ',3)
|
champ = ligne.value.replace(',', '').replace(':', '').split(' ', 3)
|
||||||
sdate = champ[0].split('/')
|
sdate = champ[0].split('/')
|
||||||
date = datetime.date(int(sdate[2]),int(sdate[1]),int(sdate[0]))
|
date = datetime.date(int(sdate[2]), int(sdate[1]), int(sdate[0]))
|
||||||
champ_action=champ[3]
|
champ_action = champ[3]
|
||||||
return champ,champ_action,date
|
return (champ, champ_action, date)
|
||||||
|
|
||||||
def actions_cableurs():
|
def actions_cableurs():
|
||||||
"""Renvoie l'historique de tous les adherents et tri en fonction
|
"""Renvoie l'historique de tous les adherents et tri en fonction
|
||||||
des actions éffectuées."""
|
des actions éffectuées."""
|
||||||
for adherent in adherents:
|
for adherent in adherents():
|
||||||
histo=adherent.get('historique',None)
|
histo = adherent.get('historique', None)
|
||||||
for j in range (0,len(histo)):
|
for j in range (0, len(histo)):
|
||||||
champ=parse_historique(histo[j])[0]
|
champ = parse_historique(histo[j])[0]
|
||||||
champ_action=parse_historique(histo[j])[1]
|
champ_action = parse_historique(histo[j])[1]
|
||||||
date=parse_historique(histo[j])[2]
|
date = parse_historique(histo[j])[2]
|
||||||
if ((u' inscription' in champ_action or u'Adhesion+' in champ_action) and date > datetime.date(ann_scol,8,1)):
|
if ((u' inscription' in champ_action or u'Adhesion+' in champ_action) and date > datetime.date(ann_scol, 8, 1)):
|
||||||
historique.append(champ)
|
HISTORIQUE.append(champ)
|
||||||
return historique
|
return HISTORIQUE
|
||||||
|
|
||||||
#### On parse l'historique et on trie
|
#### On parse l'historique et on trie
|
||||||
def score_cableurs():
|
def score_cableurs():
|
||||||
"""Calcul le score de tout les câbleurs en fonction des actions
|
"""Calcul le score de tout les câbleurs en fonction des actions
|
||||||
effectuées """
|
effectuées """
|
||||||
for cableur in cableurs:
|
for cableur in cableurs():
|
||||||
inscriptions = reinscriptions=0
|
inscriptions = reinscriptions = 0
|
||||||
nom = cableur.get(u'nom',None)[0].value
|
nom = cableur.get(u'nom', None)[0].value
|
||||||
prenom = cableur.get(u'prenom',None)[0].value
|
prenom = cableur.get(u'prenom', None)[0].value
|
||||||
uid = cableur.get(u'uid',None)[0].value
|
uid = cableur.get(u'uid', None)[0].value
|
||||||
for l in range (0,len(historique)):
|
for index in range (0, len(HISTORIQUE)):
|
||||||
histo_uid = historique[l][2]
|
histo_uid = HISTORIQUE[index][2]
|
||||||
histo_action = historique[l][3]
|
histo_action = HISTORIQUE[index][3]
|
||||||
if histo_uid == uid and histo_action == u' inscription':
|
if histo_uid == uid and histo_action == u' inscription':
|
||||||
inscriptions = inscriptions+1
|
inscriptions = inscriptions + 1
|
||||||
if histo_uid == uid and (u"debutAdhesion+" in histo_action):
|
if histo_uid == uid and (u"debutAdhesion+" in histo_action):
|
||||||
reinscriptions = reinscriptions+1
|
reinscriptions = reinscriptions + 1
|
||||||
score = 2*inscriptions + reinscriptions
|
score = 2*inscriptions + reinscriptions
|
||||||
scores.append(["%s %s" % (prenom, nom), score, inscriptions, reinscriptions])
|
SCORES.append(["%s %s" % (prenom, nom), score, inscriptions, reinscriptions])
|
||||||
return scores
|
return SCORES
|
||||||
|
|
||||||
|
|
||||||
### Tri par score
|
### Tri par score
|
||||||
def sort_by_score():
|
def sort_by_score():
|
||||||
"""Tri la liste des câbleurs par ordre de score décroissant de score"""
|
"""Tri la liste des câbleurs par ordre de score décroissant de score"""
|
||||||
return score_cableurs().sort(key=lambda x:int(x[1]),reverse=True)
|
return score_cableurs().sort(key=lambda x:int(x[1]), reverse=True)
|
||||||
|
|
||||||
def sort_by_inverse_score():
|
def sort_by_inverse_score():
|
||||||
"""Tri la liste des câbleurs par ordre de score croissant de score"""
|
"""Tri la liste des câbleurs par ordre de score croissant de score"""
|
||||||
|
@ -96,11 +116,11 @@ def sort_by_inverse_score():
|
||||||
|
|
||||||
def cableurs_utiles():
|
def cableurs_utiles():
|
||||||
"""Renvoi le nombre de cableurs ayant un score non nul"""
|
"""Renvoi le nombre de cableurs ayant un score non nul"""
|
||||||
useless_cableurs=0
|
useless_cableurs = 0
|
||||||
for k in range(0,len(cableurs)):
|
for k in range(0, len(cableurs())):
|
||||||
if (scores[k][1] == 0):
|
if (SCORES[k][1] == 0):
|
||||||
useless_cableurs = useless_cableurs+1
|
useless_cableurs = useless_cableurs + 1
|
||||||
return len(cableurs) - useless_cableurs
|
return len(cableurs()) - useless_cableurs
|
||||||
|
|
||||||
|
|
||||||
#### Affichage ou x est le nombre de câbleurs à afficher
|
#### Affichage ou x est le nombre de câbleurs à afficher
|
||||||
|
@ -109,38 +129,39 @@ def show_all(limit, swap):
|
||||||
titre = [u"Câbleur", u"Score", u"Inscriptions", u"Réinscriptions"]
|
titre = [u"Câbleur", u"Score", u"Inscriptions", u"Réinscriptions"]
|
||||||
largeur = [25, 8, 16, 16]
|
largeur = [25, 8, 16, 16]
|
||||||
alignement = ["c", "c", "c", "c"]
|
alignement = ["c", "c", "c", "c"]
|
||||||
data = [[elem for elem in scores[index]] for index in xrange(limit)]
|
data = [[elem for elem in SCORES[index]] for index in xrange(limit)]
|
||||||
print affichage.tableau(data, titre=titre, largeur=largeur, alignement=alignement, swap=swap).encode(encoding)
|
print affichage.tableau(data, titre=titre, largeur=largeur, alignement=alignement, swap=swap).encode(ENCODING)
|
||||||
|
|
||||||
#### On définit le Parser
|
#### On définit le Parser
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
actions_cableurs()
|
actions_cableurs()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
PARSER = argparse.ArgumentParser()
|
||||||
parser.add_argument("-a", "--all", help="Affiche les scores de tout les câbleurs", action="store_true")
|
PARSER.add_argument("-a", "--all", help="Affiche les scores de tout les câbleurs", action="store_true")
|
||||||
parser.add_argument("-t", "--top", help="Affiche seulement les meilleurs câbleurs", action="store_true")
|
PARSER.add_argument("-t", "--top", help="Affiche seulement les meilleurs câbleurs", action="store_true")
|
||||||
parser.add_argument("-s", "--scores", help="Affiche seulement les câbleurs ayant un score non nul", action="store_true")
|
PARSER.add_argument("-s", "--scores", help="Affiche seulement les câbleurs ayant un score non nul", action="store_true")
|
||||||
parser.add_argument("-m", "--menage", help="Affiche seulement les câbleurs ayant un score nul", action="store_true")
|
PARSER.add_argument("-m", "--menage", help="Affiche seulement les câbleurs ayant un score nul", action="store_true")
|
||||||
parser.add_argument("-n", "--nocolour", help="Désactive la couleur", action="store_true")
|
PARSER.add_argument("-n", "--nocolour", help="Désactive la couleur", action="store_true")
|
||||||
args = parser.parse_args()
|
ARGS = PARSER.parse_args()
|
||||||
|
|
||||||
if args.nocolour:
|
|
||||||
swap = []
|
if ARGS.nocolour:
|
||||||
|
SWAP = []
|
||||||
else:
|
else:
|
||||||
swap = [None, "vert"]
|
SWAP = [None, "vert"]
|
||||||
|
|
||||||
if args.all:
|
if ARGS.all:
|
||||||
sort_by_score()
|
sort_by_score()
|
||||||
show_all(len(cableurs), swap=swap)
|
show_all(len(cableurs()), swap=SWAP)
|
||||||
elif args.scores:
|
elif ARGS.scores:
|
||||||
sort_by_score()
|
sort_by_score()
|
||||||
show_all(cableurs_utiles(), swap=swap)
|
show_all(cableurs_utiles(), swap=SWAP)
|
||||||
elif args.menage:
|
elif ARGS.menage:
|
||||||
sort_by_inverse_score()
|
sort_by_inverse_score()
|
||||||
show_all(len(cableurs)-cableurs_utiles(), swap=swap)
|
show_all(len(cableurs()) - cableurs_utiles(), swap=SWAP)
|
||||||
elif args.top:
|
elif ARGS.top:
|
||||||
sort_by_score()
|
sort_by_score()
|
||||||
show_all(5, swap=swap)
|
show_all(5, swap=SWAP)
|
||||||
else:
|
else:
|
||||||
sort_by_score()
|
sort_by_score()
|
||||||
show_all(10, swap=swap)
|
show_all(10, swap=SWAP)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue