Commit b2cce759 authored by Marine Marsal's avatar Marine Marsal
Browse files

Update StatistiquesDataMapper.py mise à jour requête avec vues

parent 54f277b8
......@@ -8,7 +8,7 @@ class StatistiquesDataMapper(DataMapper):
conn = self.connect()
try:
cursor : psycopg2.extensions.cursor = conn.cursor()
sql1 = "SELECT r.titre, COUNT(p.ref) nb_emprunt FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref GROUP BY r.titre HAVING COUNT(ep.ref) > 1 ORDER BY COUNT(ep.ref) DESC"
sql1 = "SELECT rp.titre, rp.nb_emprunt FROM RessourcesPopulaires rp"
cursor.execute(sql1)
rows = cursor.fetchall()
return rows
......@@ -24,7 +24,7 @@ class StatistiquesDataMapper(DataMapper):
conn = self.connect()
try:
cursor : psycopg2.extensions.cursor = conn.cursor()
sql1 = "SELECT COUNT(ep.ref) nb_emprunt FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref WHERE r.codeUnique = '{0}' HAVING COUNT(ep.ref) > 1 ORDER BY COUNT(ep.ref) DESC".format(codeUnique)
sql1 = "SELECT rp.titre, rp.nb_emprunt FROM RessourcesPopulaires rp WHERE rp.codeUnique = '{0}'".format(codeUnique)
cursor.execute(sql1)
ressource = cursor.fetchone()
return ressource[0]
......@@ -39,7 +39,7 @@ class StatistiquesDataMapper(DataMapper):
conn = self.connect()
try:
cursor : psycopg2.extensions.cursor = conn.cursor()
sql1 = "SELECT r.genre, COUNT(ep.ref) nb_emprunt FROM Ressource r JOIN Exemplaire ep ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref GROUP BY r.genre HAVING COUNT(ep.ref) > 1 ORDER BY COUNT(ep.ref) DESC"
sql1 = "SELECT gp.titre, gp.nb_emprunt FROM GenresPopulaires gp"
cursor.execute(sql1)
rows = cursor.fetchall()
return rows
......@@ -54,7 +54,7 @@ class StatistiquesDataMapper(DataMapper):
conn = self.connect()
try:
cursor : psycopg2.extensions.cursor = conn.cursor()
sql1 = "SELECT COUNT(ep.ref) nb_emprunt FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref WHERE r.genre = '{0}' GROUP BY r.genre HAVING COUNT(ep.ref) > 1 ORDER BY COUNT(ep.ref) DESC".format(genre)
sql1 = "SELECT gp.titre, gp.nb_emprunt FROM GenresPopulaires gp WHERE gp.genre = '{0}' GROUP BY gp.genre".format(genre)
cursor.execute(sql1)
ressource = cursor.fetchone()
return ressource[1]
......@@ -69,10 +69,10 @@ class StatistiquesDataMapper(DataMapper):
conn = self.connect()
try:
cursor : psycopg2.extensions.cursor = conn.cursor()
sql1 = "SELECT r.genre, nb_emprunt COUNT(ep.ref) FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref JOIN Pret p ON p.pretID = ep.pretID WHERE p.adherent = '{0}' GROUP BY r.genre HAVING COUNT(ep.ref) > 1 ORDER BY COUNT(ep.ref) DESC".format(login)
sql1 = "SELECT gppa.genre, gppa.nb_emprunt FROM GenrePrefereParAdherent gppa WHERE gppa.login = '{0}'".format(login)
cursor.execute(sql1)
genre = cursor.fetchall()
return genre[0][0] # retourne le premier genre
return genre
except Exception as err:
print(err)
finally:
......@@ -100,13 +100,13 @@ class StatistiquesDataMapper(DataMapper):
conn = self.connect()
try:
cursor : psycopg2.extensions.cursor = conn.cursor()
sql1 = "SELECT COUNT(ep.ref) FROM Livre l JOIN Ressource r ON l.codeUnique = r.codeUnique JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.refExemplaire = e.ref"
sql1 = "SELECT lp.nb_emprunt FROM LivresPopulaire lp"
cursor.execute(sql1)
nbLivres = cursor.fetchone()
sql2 = "SELECT COUNT(ep.ref) FROM OeuvreMusicale om JOIN Ressource r ON om.codeUnique = r.codeUnique JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.refExemplaire = e.ref"
sql2 = "SELECT omp.nb_emprunt FROM OeuvresMusicalesPopulaire omp"
cursor.execute(sql2)
nbOeuvres = cursor.fetchone()
sql3 = "SELECT COUNT(ep.ref) FROM Film f JOIN Ressource r ON f.codeUnique = r.codeUnique JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.refExemplaire = e.ref"
sql3 = "SELECT fp.nb_emprunt FROM FilmsPopulaires fp"
cursor.execute(sql3)
nbFilms = cursor.fetchone()
if(nbLivres[0] > nbFilms[0] and nbLivres[0] > nbOeuvres[0]) :
......
Supports Markdown
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