diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b65d8b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +# bloop and metals + +# vs code +.venv +.idea +.__pycache__ diff --git a/MonetDB.py b/MonetDB.py new file mode 100644 index 0000000..f252454 --- /dev/null +++ b/MonetDB.py @@ -0,0 +1,6 @@ +import pymonetdb + + +connection = pymonetdb.connect(username="monetdb", password="monetdb", hostname="localhost", database="demo") +# create a cursor +cursor = connection.cursor() diff --git a/PostgreSQL.py b/PostgreSQL.py new file mode 100644 index 0000000..24200f2 --- /dev/null +++ b/PostgreSQL.py @@ -0,0 +1,107 @@ +import time +import psycopg2 + +def connect_postgres(): + return psycopg2.connect( + host="localhost", + database="postgres", + user="postgres", + password="1" + ) + +def create_tables(): + sql_command_create_table= ( + """CREATE TABLE airlines + ( + IATA_CODE VARCHAR(2), + AIRLINE VARCHAR(30) + ) + """, + """CREATE TABLE airports + ( + IATA_CODE VARCHAR(3), + AIRPORT VARCHAR(100), + CITY VARCHAR(40), + STATE VARCHAR(2), + COUNTRY VARCHAR(40), + LATITUDE REAL, + LONGITUDE REAL + ) + """, + """CREATE TABLE flights + ( + YEAR INTEGER, + MONTH INTEGER, + DAY INTEGER, + DAY_OF_WEEK INTEGER, + AIRLINE VARCHAR(2), + FLIGHT_NUMBER INTEGER, + TAIL_NUMBER VARCHAR(6), + ORIGIN_AIRPORT VARCHAR(5), + DESTINATION_AIRPORT VARCHAR(5), + SCHEDULED_DEPARTURE INTEGER, + DEPARTURE_TIME INTEGER, + DEPARTURE_DELAY INTEGER, + TAXI_OUT INTEGER, + WHEELS_OFF INTEGER, + SCHEDULED_TIME INTEGER, + ELAPSED_TIME INTEGER, + AIR_TIME INTEGER, + DISTANCE INTEGER, + WHEELS_ON INTEGER, + TAXI_IN INTEGER, + SCHEDULED_ARRIVAL INTEGER, + ARRIVAL_TIME INTEGER, + ARRIVAL_DELAY INTEGER, + DIVERTED INTEGER, + CANCELLED INTEGER, + CANCELLATION_REASON VARCHAR(1), + AIR_SYSTEM_DELAY INTEGER, + SECURITY_DELAY INTEGER, + AIRLINE_DELAY INTEGER, + LATE_AIRCRAFT_DELAY INTEGER, + WEATHER_DELAY INTEGER + ) + """) + try: + with connect_postgres() as conn: + with conn.cursor() as cursor: + for command in sql_command_create_table: + cursor.execute(command) + conn.commit() + cursor.close() + conn.close() + except (psycopg2.DatabaseError, Exception) as error: + print(error) + + +def create_data(): + 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 ''""", + """COPY flights FROM 'C://Users//Public//2015_Flight_Delay_and_cancellations//flights.csv' DELIMITER ',' NULL AS ''""") + try: + with connect_postgres() as conn: + with conn.cursor() as cursor: + for command in sql_command_copy: + cursor.execute(command) + conn.commit() + cursor.close() + conn.close() + except (psycopg2.DatabaseError, Exception) as error: + print(error) + + +def requete_lecture(str): + try: + with connect_postgres() as conn: + with conn.cursor() as cursor: + start = time.time() + cursor.execute(str) + conn.commit() + temps = time.time() -start + print("Cette requête prends:", temps, "seconde") + cursor.close() + conn.close() + except (psycopg2.DatabaseError, Exception) as error: + print(error) \ No newline at end of file diff --git a/README.md b/README.md index d455486..ef3d354 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# M1_BDD_Comparaison_perf - - +# CACA +# Excrément +# Eaux Usées ## Getting started diff --git a/__pycache__/MonetDB.cpython-312.pyc b/__pycache__/MonetDB.cpython-312.pyc new file mode 100644 index 0000000..3abd97d Binary files /dev/null and b/__pycache__/MonetDB.cpython-312.pyc differ diff --git a/__pycache__/PostgreSQL.cpython-312.pyc b/__pycache__/PostgreSQL.cpython-312.pyc new file mode 100644 index 0000000..7e9abe4 Binary files /dev/null and b/__pycache__/PostgreSQL.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..43cb040 Binary files /dev/null and b/__pycache__/main.cpython-312.pyc differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..4df2008 --- /dev/null +++ b/main.py @@ -0,0 +1,9 @@ +import time + +from PostgreSQL import create_tables,create_data,requete_lecture + +if __name__ == '__main__': + #create_tables() + #create_data() + str="""SELECT * FROM public.flights WHERE airline = 'AA'""" + requete_lecture(str) \ No newline at end of file