plein de truc : uniformisation des chronomètres, ajout de requête, print un rapport à la fin et le sauvegarde dans un .txt

This commit is contained in:
Rochas
2024-12-21 13:19:31 +01:00
parent dc0715b5c5
commit c125d4ad6f
2 changed files with 124 additions and 36 deletions

View File

@@ -10,6 +10,9 @@ def connect_postgres():
)
def create_tables_postgres():
start_time = 0
end_time = 0
sql_command_create_table= (
"""CREATE TABLE airlines
(
@@ -78,6 +81,8 @@ def create_tables_postgres():
return end_time-start_time
def create_data_postgres():
start_time = 0
end_time = 0
sql_command_copy =(
"""COPY airlines FROM 'C://Users//Public//2015_Flight_Delay_and_cancellations//airlines.csv' DELIMITER ',' NULL AS ''""",
"""COPY airports FROM 'C://Users//Public//2015_Flight_Delay_and_cancellations//airports.csv' DELIMITER ',' NULL AS ''""",
@@ -94,29 +99,36 @@ def create_data_postgres():
conn.close()
except (psycopg2.DatabaseError, Exception) as error:
print(error)
return end_time - start_time
return end_time-start_time
def requete_postgres(str):
start_time = 0
end_time = 0
try:
with connect_postgres() as conn:
with conn.cursor() as cursor:
start = time.time()
start_time = time.time()
cursor.execute(str)
conn.commit()
end = time.time() -start
end_time = time.time()
cursor.close()
conn.close()
except (psycopg2.DatabaseError, Exception) as error:
print(error)
return end-start
return end_time-start_time
def reset_database_postgres():
start_time = 0
end_time = 0
try:
with connect_postgres() as conn:
start_time = time.time()
with conn.cursor() as cursor:
cursor.execute('DROP TABLE IF EXISTS flights,airlines,airports,flights10')
conn.commit()
end_time = time.time()
cursor.close()
conn.close()
except (psycopg2.DatabaseError, Exception) as error:
print(error)
print(error)
return end_time-start_time