diff --git a/surveillance/mac_prises/mac_prise_analyzer.py b/surveillance/mac_prises/mac_prise_analyzer.py index e09b065e..e74cc483 100755 --- a/surveillance/mac_prises/mac_prise_analyzer.py +++ b/surveillance/mac_prises/mac_prise_analyzer.py @@ -43,10 +43,6 @@ for club in clubs: except: pass -requete = "SELECT * FROM signales WHERE date >= timestamp 'now' - interval '1 day';" -cur.execute(requete) -signales = cur.fetchall() - longueur = (24, 7) titres = (u'mac', u'chambres') alignements = ('c', 'c') @@ -69,7 +65,20 @@ def genere_comptage(duree): global Logs pb_comptage_suspect = {} output = "" - requete = "SELECT array_to_string(array_agg(DISTINCT date), ', ') AS dates , mac, array_to_string(array_agg(DISTINCT chambre), ', ') AS chambres, COUNT(DISTINCT chambre) AS nb_chambres_distinctes, COUNT(chambre) AS nb_chambres, COUNT(DISTINCT date) as nb_dates_distinctes, COUNT(DISTINCT mac) as nb_macs_distinctes FROM correspondance WHERE date >= timestamp 'now' - interval '%(delay)s' GROUP BY mac;" % {'delay': mac_prise.delay[duree]} + requete = """SELECT + array_to_string(array_agg(DISTINCT date), ', ') AS dates, + mac, + array_to_string(array_agg(DISTINCT chambre), ', ') AS chambres, + COUNT(DISTINCT chambre) AS nb_chambres_distinctes, + COUNT(chambre) AS nb_chambres, + COUNT(DISTINCT date) AS nb_dates_distinctes, + COUNT(DISTINCT mac) AS nb_macs_distinctes +FROM + correspondance +WHERE + date >= timestamp 'now' - interval '%(delay)s' +GROUP BY + mac;""" % {'delay': mac_prise.delay[duree]} cur.execute(requete) fetched = cur.fetchall() @@ -109,7 +118,15 @@ def summary(): output = u"" Logs = u"" - requete = "SELECT * FROM spotted WHERE date >= timestamp 'now' - interval '1 day' ORDER BY date ASC;" + requete = """SELECT + * +FROM + spotted +WHERE + date >= timestamp 'now' - interval '1 day' +ORDER BY + date +ASC;""" cur.execute(requete) fetched = cur.fetchall() liste_triee = collections.defaultdict(dict) @@ -163,7 +180,20 @@ def reperage_mac_inconnue(): output = u"" probleme = {} - requete = "SELECT chambre, mac, COUNT(mac) as nb_min FROM correspondance WHERE date >= timestamp 'now' - interval '24 hours' GROUP BY chambre, mac ORDER BY chambre ASC;" + requete = """SELECT + chambre, + mac, + COUNT(mac) AS nb_min +FROM + correspondance +WHERE + date >= timestamp 'now' - interval '24 hours' +GROUP BY + chambre, + mac +ORDER BY + chambre +ASC;""" cur.execute(requete) fetched = cur.fetchall() liste_parsee = collections.defaultdict(dict)