Init
add code
This commit is contained in:
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
# bloop and metals
|
||||
|
||||
# vs code
|
||||
.venv
|
||||
.idea
|
||||
.__pycache__
|
||||
6
MonetDB.py
Normal file
6
MonetDB.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import pymonetdb
|
||||
|
||||
|
||||
connection = pymonetdb.connect(username="monetdb", password="monetdb", hostname="localhost", database="demo")
|
||||
# create a cursor
|
||||
cursor = connection.cursor()
|
||||
107
PostgreSQL.py
Normal file
107
PostgreSQL.py
Normal file
@@ -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)
|
||||
@@ -1,6 +1,6 @@
|
||||
# M1_BDD_Comparaison_perf
|
||||
|
||||
|
||||
# CACA
|
||||
# Excrément
|
||||
# Eaux Usées
|
||||
|
||||
## Getting started
|
||||
|
||||
|
||||
BIN
__pycache__/MonetDB.cpython-312.pyc
Normal file
BIN
__pycache__/MonetDB.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/PostgreSQL.cpython-312.pyc
Normal file
BIN
__pycache__/PostgreSQL.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-312.pyc
Normal file
BIN
__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user