[stats_cableurs.py] stats_cableurs --efficiency
donne les stats sur les 3 derniers mois des c^ableurs
Ignore-this: 42b5ff6a62924ccb8e8a15cd9c5c40bb darcs-hash:20090327151549-bd074-5a92fb238665eeda419f13f0ae2d51e070785c3c.gz
This commit is contained in:
parent
e48bff52a6
commit
cb4e55ed94
1 changed files with 118 additions and 23 deletions
|
@ -6,9 +6,10 @@
|
|||
# stats_cableurs.py
|
||||
# -----------------
|
||||
#
|
||||
# Copyright (C) 2008 François Bobot <bobot@crans.org>,
|
||||
# Jeremie Dimino <jeremie@dimino.org>,
|
||||
# Michel Blockelet <blockelet@crans.org>
|
||||
# Copyright (C) 2008, 2009 François Bobot <bobot@crans.org>,
|
||||
# Jeremie Dimino <jeremie@dimino.org>,
|
||||
# Michel Blockelet <blockelet@crans.org>,
|
||||
# Antoine Durand-Gasselin <adg@crans.org>
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -24,20 +25,110 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||
|
||||
import sys
|
||||
import sys, re
|
||||
sys.path.append("/usr/scripts/gestion/")
|
||||
from ldap_crans import crans_ldap
|
||||
from config import ann_scol
|
||||
from affich_tools import cprint
|
||||
from affich_tools import cprint, anim
|
||||
import time
|
||||
|
||||
db = crans_ldap()
|
||||
date_debut_ann_scol = time.mktime((ann_scol, 8, 1, 0, 0, 0, 0, 0, 0))
|
||||
paiement_ann_scol = "paiement+%d" % ann_scol
|
||||
|
||||
def donne_cableur(mois,adherent):
|
||||
u""" Cherche le cableur qui a inscrit ou réinscrit un adhérent. """
|
||||
|
||||
class ActionsCableurs:
|
||||
u"""Cette classe s'occupe de recenser l'activité des différents
|
||||
câbleurs."""
|
||||
|
||||
stats = {}
|
||||
sablier = None
|
||||
|
||||
def __init__(self, mois):
|
||||
|
||||
self.sablier = anim(u"Récupération de la liste des câbleurs")
|
||||
ldap_cableurs = db.search("droits=cableur")['adherent']
|
||||
for i in ldap_cableurs:
|
||||
self.stats[i.nom()] = []
|
||||
self.sablier.reinit()
|
||||
cprint('OK', 'vert')
|
||||
|
||||
self.get_stats(mois)
|
||||
self.print_results()
|
||||
|
||||
def ajoute_actions(self, mois, machine):
|
||||
u"""Ajoute dans les stats la liste des actions effectués par
|
||||
chacuns des câbleurs sur la machine pendant les mois."""
|
||||
|
||||
for hist in machine.historique():
|
||||
# On decoupe pour avoir un truc utilisable
|
||||
champ = hist.replace(',', '').replace(': ', '').split(' ')
|
||||
date = champ[0].split('/')
|
||||
# On inspecte la date
|
||||
if (int (date[1]), int(date[2])) in mois:
|
||||
if self.stats.has_key(champ[2]):
|
||||
self.stats[champ[2]].append(champ[3])
|
||||
else:
|
||||
self.stats[champ[2]] = [champ[3]]
|
||||
|
||||
def get_stats(self, mois):
|
||||
u"""Récupère les statistiques des différents câbleurs sur les
|
||||
différentes machines"""
|
||||
|
||||
self.sablier = anim(u"Récupération de la liste des machines")
|
||||
all_machines = db.search('host=*')
|
||||
self.sablier.cycle()
|
||||
machines = all_machines['machineFixe'] + all_machines['machineWifi']
|
||||
self.sablier.reinit()
|
||||
cprint('OK', 'vert')
|
||||
|
||||
self.sablier = anim(u"Récupération des actions sur les machines", iter = len (machines))
|
||||
for becane in machines:
|
||||
self.ajoute_actions(mois, becane)
|
||||
self.sablier.cycle()
|
||||
self.sablier.reinit()
|
||||
cprint('OK', 'vert')
|
||||
|
||||
def print_results(self, nombre= 0):
|
||||
u"""Affiche les statistiques d'activité des différents câbleurs"""
|
||||
|
||||
cableurs = self.stats.keys()
|
||||
cableurs.sort(lambda x, y : cmp(len (self.stats[x]), len (self.stats[y])), reverse=True)
|
||||
long_max = reduce(lambda m, c : max(m, len(c)), cableurs, len('cableur'))
|
||||
|
||||
colonnes = [('actions', u'Actions'),
|
||||
('ins', u'Inscription'),
|
||||
('mac', u'Change MAC'),
|
||||
('host', u'Change DNS'),
|
||||
('ip', u'Change IP')]
|
||||
|
||||
# Titres des colonnes
|
||||
ligne = "%-*s" % (long_max, u'Câbleur')
|
||||
for typ, nom in colonnes:
|
||||
ligne += " | %s" % nom
|
||||
cprint(ligne)
|
||||
|
||||
# Ligne pour délimiter
|
||||
ligne = ''.center(long_max, '-')
|
||||
for typ, nom in colonnes:
|
||||
ligne += "-+-%s" % ''.center(len(nom), '-')
|
||||
cprint(ligne)
|
||||
|
||||
# Statiqtiques par câbleur
|
||||
for cableur in cableurs:
|
||||
acts = self.stats[cableur]
|
||||
score_cableur = {}
|
||||
score_cableur['actions'] = len (acts)
|
||||
for key, chaine in colonnes[1:]:
|
||||
score_cableur[key] = len ([i for i in acts if re.search(key, i)])
|
||||
ligne = "%-*s" % (long_max, cableur)
|
||||
for typ, nom in colonnes:
|
||||
ligne += " | %*d" % (len(nom), score_cableur[typ])
|
||||
cprint(ligne)
|
||||
|
||||
|
||||
def donne_cableur(mois, adherent):
|
||||
u""" Cherche le cableur qui a inscrit ou réinscrit un adhérent. """
|
||||
cableur = None
|
||||
# Est-ce qu'on recherche une inscription ou une reinscription?
|
||||
if adherent.dateInscription() < date_debut_ann_scol:
|
||||
|
@ -67,7 +158,7 @@ def calcul_score(mois):
|
|||
|
||||
score = {}
|
||||
for adherent in liste:
|
||||
action, cableur = donne_cableur(mois,adherent)
|
||||
action, cableur = donne_cableur(mois, adherent)
|
||||
if cableur:
|
||||
if not score.has_key(cableur):
|
||||
score[cableur] = { 'inscription': 0,
|
||||
|
@ -83,36 +174,40 @@ def calcul_score(mois):
|
|||
def classe(score={}):
|
||||
u""" Retourne la liste des câbleurs classé par score total décroisant. """
|
||||
cableurs = score.keys()
|
||||
cableurs.sort(lambda x,y : cmp(score[x]['total'],score[y]['total']), reverse=True)
|
||||
cableurs.sort(lambda x, y : cmp(score[x]['total'], score[y]['total']), reverse=True)
|
||||
return cableurs
|
||||
|
||||
if __name__ == "__main__":
|
||||
nb_affiche = 10
|
||||
mois = [8,9,10]
|
||||
mois = range(8, 11)
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == '-e':
|
||||
mois = [8,9,10,11]
|
||||
mois = range(8, 13)
|
||||
if len(sys.argv) > 2:
|
||||
try:
|
||||
nb_affiche = int(sys.argv[2])
|
||||
except:
|
||||
nb_affiche = 10
|
||||
try:
|
||||
nb_affiche = int(sys.argv[2])
|
||||
except ValueError:
|
||||
nb_affiche = 10
|
||||
else:
|
||||
try:
|
||||
nb_affiche = int(sys.argv[1])
|
||||
except:
|
||||
except ValueError:
|
||||
nb_affiche = 10
|
||||
|
||||
if sys.argv[1] == '--efficiency':
|
||||
ActionsCableurs([(1, 2009), (2, 2009), (3, 2009)])
|
||||
sys.exit(0)
|
||||
|
||||
score = calcul_score(mois)
|
||||
classement = classe(score)
|
||||
|
||||
if nb_affiche > 0:
|
||||
classement = classement[0:nb_affiche]
|
||||
|
||||
|
||||
# On cherche les noms des câbleurs parceque c'est quand même mieux
|
||||
nom_reel = {}
|
||||
for cableur in classement:
|
||||
nom_reel[cableur] =db.search('uid=%s' % cableur)['adherent'][0].Nom()
|
||||
nom_reel[cableur] = db.search('uid=%s' % cableur)['adherent'][0].Nom()
|
||||
|
||||
# Calcul des statistiques
|
||||
total_inscription = 0
|
||||
|
@ -132,7 +227,7 @@ if __name__ == "__main__":
|
|||
'total': total }, newline=False)
|
||||
|
||||
# Calcul la longueur du nom le plus long
|
||||
long_max = reduce(lambda m,c : max(m, len(c)), nom_reel.values(), len('cableur'))
|
||||
long_max = reduce(lambda m, c : max(m, len(c)), nom_reel.values(), len('cableur'))
|
||||
|
||||
colonnes = [('inscription', u'inscription'),
|
||||
('reinscription', u'réinscription'),
|
||||
|
@ -140,18 +235,18 @@ if __name__ == "__main__":
|
|||
|
||||
# Titres des colonnes
|
||||
ligne = "%-*s" % (long_max, u'câbleur')
|
||||
for type, nom in colonnes:
|
||||
for typ, nom in colonnes:
|
||||
ligne += " | %s" % nom
|
||||
cprint(ligne)
|
||||
# Ligne pour délimiter
|
||||
ligne = ''.center(long_max, '-')
|
||||
for type, nom in colonnes:
|
||||
for typ, nom in colonnes:
|
||||
ligne += "-+-%s" % ''.center(len(nom), '-')
|
||||
cprint(ligne)
|
||||
# Statiqtiques par câbleur
|
||||
for cableur in classement:
|
||||
score_cableur = score[cableur]
|
||||
ligne = "%-*s" % (long_max, nom_reel[cableur])
|
||||
for type, nom in colonnes:
|
||||
ligne += " | %*d" % (len(nom), score_cableur[type])
|
||||
for typ, nom in colonnes:
|
||||
ligne += " | %*d" % (len(nom), score_cableur[typ])
|
||||
cprint(ligne)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue