Commit 3af41a3f authored by sim-baz's avatar sim-baz

Create table by date

parent eadeb273
......@@ -3,7 +3,8 @@ import csv
import re
FILE_NAME = "asos.txt"
table_name = "data"
table_name_space = "data"
table_name_date = "data_by_date"
# Country: Finland
# Dates : 2001 to 2010
......@@ -261,6 +262,47 @@ def createTableQuery(table):
)"""
return query
def createTableQueryPartitionningByDate(table):
query = f"""CREATE TABLE {table}(
station varchar,
year int,
month int,
day int,
hour int,
minute int,
lon decimal,
lat decimal,
tmpf decimal,
dwpf decimal,
relh decimal,
drct decimal,
sknt decimal,
p01i decimal,
alti decimal,
mslp decimal,
vsby decimal,
gust decimal,
skyc1 varchar,
skyc2 varchar,
skyc3 varchar,
skyc4 varchar,
skyl1 decimal,
skyl2 decimal,
skyl3 decimal,
skyl4 decimal,
wxcodes varchar,
feel decimal,
ice_accretion_1hr decimal,
ice_accretion_3hr decimal,
ice_accretion_6hr decimal,
peak_wind_gust decimal,
peak_wind_drct decimal,
peak_wind_time decimal,
metar varchar,
PRIMARY KEY((year, month, day), hour, minute, station)
)"""
return query
def insertQueryData(row, table):
query = f"""
INSERT INTO
......@@ -320,13 +362,26 @@ dict = loadata(FILE_NAME)
# # --------------------------------------------------------
# # A faire seulement 1 fois pour charger les données
# session.execute(dropTableQuery(table_name))
# print(f"Table {table_name} dropped")
# session.execute(createTableQuery(table_name))
# print(f"Table {table_name} created")
# session.execute(dropTableQuery(table_name_space))
# print(f"Table {table_name_space} dropped")
# session.execute(createTableQuery(table_name_space))
# print(f"Table {table_name_space} created")
# print(f"Starting inserting datas into table {table_name}")
# print(f"Starting inserting datas into table {table_name_space}")
# for d in dict:
# session.execute(insertQueryData(d, table_name))
# print(f"Datas inserted into {table_name}")
# # --------------------------------------------------------
\ No newline at end of file
# session.execute(insertQueryData(d, table_name_space))
# print(f"Datas inserted into {table_name_space}")
# # --------------------------------------------------------
# --------------------------------------------------------
# A faire seulement 1 fois pour charger les données
session.execute(dropTableQuery(table_name_date))
print(f"Table {table_name_date} dropped")
session.execute(createTableQueryPartitionningByDate(table_name_date))
print(f"Table {table_name_date} created")
print(f"Starting inserting datas into table {table_name_date}")
for d in dict:
session.execute(insertQueryData(d, table_name_date))
print(f"Datas inserted into {table_name_date}")
# --------------------------------------------------------
\ No newline at end of file
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