39 lines
1.2 KiB
Python
Executable file
39 lines
1.2 KiB
Python
Executable file
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Affiche des statistiques sur le câblage des prises des chambres
|
|
(CRANS ou CROUS)."""
|
|
|
|
import sys
|
|
import psycopg2
|
|
sys.path.append('/usr/scripts/gestion')
|
|
from affich_tools import tableau
|
|
|
|
conn = psycopg2.connect("user=crans dbname=switchs host=pgsql.adm.crans.org")
|
|
|
|
def compte_prises(reseau, batiment=''):
|
|
"""Compte les prises câblées sur reseau (crans ou crous)."""
|
|
|
|
reseau = reseau.lower()
|
|
cur = conn.cursor()
|
|
if batiment == '':
|
|
cur.execute("SELECT COUNT(prises) FROM prises WHERE " + reseau + "=True")
|
|
n = cur.fetchone()[0]
|
|
else:
|
|
batiment = batiment.lower()
|
|
cur.execute("SELECT COUNT(prises) FROM prises WHERE (batiment, " + reseau + ")=(%s, True)", (batiment, ))
|
|
n = cur.fetchone()[0]
|
|
return n
|
|
|
|
data = []
|
|
for bat in ['A', 'B', 'C', 'G', 'H', 'I', 'J', 'M', '']:
|
|
n_crans = compte_prises('crans', bat)
|
|
n_crous = compte_prises('crous', bat)
|
|
frac_crans = 1.*n_crans/(n_crous + n_crans)
|
|
if bat == '':
|
|
bat = 'Total'
|
|
data.append([bat, n_crans, n_crous, '%0.2f' % (100*frac_crans)])
|
|
|
|
print tableau(data, [u'Bât.', u'CRANS',
|
|
u'CROUS', u'% CRANS'],
|
|
[7, 7, 7, 9], ['c', 'd', 'd', 'd'])
|