Commit 12ac95a0 authored by Evenson Jeunesse's avatar Evenson Jeunesse
Browse files

Upload New File

parent 5661b6d4
#!/usr/bin/python3
# http://initd.org/psycopg/docs/usage.html
import os
import psycopg2 as pg
HOST = "tuxa.sme.utc"
USER = "bdd0p071"
PASSWORD = "MFyllo2A"
DATABASE = "dbbdd0p071"
conn = pg.connect("host=%s dbname=%s user=%s password=%s" % (HOST, DATABASE, USER, PASSWORD))
cur=conn.cursor()
def afficherSql(sql):
os.system('cls' if os.name == 'nt' else 'clear')
try:
cur.execute(sql)
except pg.Error as e:
print("Execute: ",e)
conn.rollback()
return
# Fetch data line by line
colnames = [desc[0] for desc in cur.description]
raw_size = 0;
for colname in colnames :
text = str(colname)+" "*(15-len(str(colname)))+" |"
raw_size = raw_size + len(text)+1
print(text, end=" ")
print(""*raw_size)
try:
raw = cur.fetchone()
if raw:
print('-'*(raw_size-1))
while raw:
for i in raw:
text = str(i)+" "*(15-len(str(i)))+" |"
print(text, end=" ")
print("")
raw = cur.fetchone()
print('-'*(raw_size-1))
else:
print("Empty table")
conn.commit()
except pg.Error as e:
print("Fetch error", e)
conn.rollback()
def afficherStatistique(conn):
sql=""
while True:
os.system('cls' if os.name == 'nt' else 'clear')
choix=0
print('*'*30)
print("1.Selection des prescriptions d'un animal (pas demandé mais aide à l'analyse de la statistique")
print("2.Statistique medicament pour un animal")
print("3.Statistique quantite prescrite pour un medicament particulier")
print("4.Poids moyen par espèce ")
print("5.Taille moyenne par espèce ")
print("6.Quitter")
print('*'*30)
print("Entrez votre choix:", end=" ")
choix=int(input())
if (choix==1):
id=input("Entrez ID d'animal: ")
sql="SELECT P.medicament, P.quantite FROM Prescriptions P, Traitements T WHERE T.animal = "+str(id)+" AND P.traitement = T.id"
elif(choix==2):
id=input("Entrez ID d'animal: ")
sql="SELECT P.medicament, SUM(P.quantite) FROM Traitements T, Prescriptions P WHERE T.animal = "+str(id)+ "AND P.traitement = T.id GROUP BY P.medicament"
elif(choix==3):
nomMolecule=input("Entrez nom de molecule: ")
sql="SELECT SUM(P.quantite) AS quantite_prescrite FROM Prescriptions P WHERE P.medicament = \'"+nomMolecule+"\'"
elif(choix==4):
sql="SELECT A.espece, AVG(A.dernierPoids) AS poids_moyen FROM animaux A GROUP BY A.espece;"
elif(choix==5):
sql="SELECT A.espece, AVG(A.derniereTaille) AS taille_moyenne FROM animaux A GROUP BY A.espece"
if choix>5 or choix<1:
return
afficherSql(sql)
sql=""
input("\nAppuyez pour continuer...")
def afficherTable(conn):
while True:
os.system('cls' if os.name == 'nt' else 'clear')
sql=""
print("Tables disponibles //////////\n")
tables=["classes","especes","clients","veterinaires","assistants","animaux","proprietaires","medicaments","Traitements","Prescriptions"]
for table in tables:
print(table.upper())
print("\n")
table=input("Entrez le nom de la table:")
if not table:
break
if table.lower() in tables:
sql="SELECT * FroM "+ table
os.system('cls' if os.name == 'nt' else 'clear')
afficherSql(sql)
input("\nAppuyez pour continuer...")
def Main():
while True:
os.system('cls' if os.name == 'nt' else 'clear')
print('*'*30)
print("1.Afficher le contenu d'une table")
print("2.Afficher les statistiques")
print("3.Inserer dans une table")
print("4.Quitter")
print('*'*30)
print("Entrez votre choix:", end=" ")
choix=input()
if choix=="1":
afficherTable(conn)
elif choix=='2':
afficherStatistique(conn)
elif choix=='3':
print("Pas encore disponible")
elif choix=='4' :
break
Main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment