-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_database.py
125 lines (112 loc) · 4.47 KB
/
create_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import sqlite3
import os
# https://www.w3schools.com/sql/sql_view.asp
class db_creator:
def __init__(self, db_name = 'runningDB_master_2.db'):
self.db_name = db_name
def create_db(self):
db_name = self.db_name
running_db = sqlite3.connect(db_name)
connection = running_db.cursor()
connection.execute('''
CREATE TABLE IF NOT EXISTS athletes (
athlete TEXT,
season TEXT,
season_year YEAR,
grade INTEGER,
sex TEXT,
PRIMARY KEY (athlete, season, season_year)
)
''')
connection.execute('''
CREATE TABLE IF NOT EXISTS race_laps (
athlete TEXT,
event_distance_m INTEGER,
date DATE,
meet_name TEXT,
relay_y_n INTEGER,
lap_1 TEXT,
lap_2 TEXT,
lap_3 TEXT,
lap_4 TEXT,
lap_5 TEXT,
lap_6 TEXT,
lap_7 TEXT,
lap_8 TEXT,
total_time TEXT,
PRIMARY KEY (athlete, event_distance_m, date, meet_name, total_time)
)
''')
#TODO: add relative humidity to meet info? meh, dont really feel like looking up all the info retroactively
connection.execute('''
CREATE TABLE IF NOT EXISTS meet_information (
name TEXT,
date DATE,
host_school TEXT,
physical_location TEXT,
city_state TEXT,
weather_temperature_deg_F INTEGER,
weather_clouds TEXT,
weather_precipitation TEXT,
weather_notes TEXT,
PRIMARY KEY (name, date)
)
''')
connection.execute('''
CREATE TABLE IF NOT EXISTS relays (
meet_name TEXT,
date DATE,
event TEXT,
sex TEXT,
leg_1 TEXT,
leg_2 TEXT,
leg_3 TEXT,
leg_4 TEXT,
time TIME,
PRIMARY KEY (meet_name, date, event)
)
''')
connection.execute('''
CREATE TABLE IF NOT EXISTS seasons (
sport TEXT,
year YEAR,
start_date DATE,
end_date DATE
)
''')
# sport: xc, tf_indoor, tf_outdoor
# year: yyyy
# start_date: yyyy-mm-dd
# end_date: yyyy-mm-dd
try:
# Check if a database of the same name exists
if self.db_name not in os.listdir(path = os.getcwd()):
running_db.commit()
running_db.close()
else:
raise Exception
except:
overwrite_permission = input('Overwrite most recent database? [y]/n ')
if overwrite_permission in ['', 'y']:
running_db.commit()
print('Database overwritten.')
else:
print('Commit canceled. Rename database.')
# Commit Database
try:
# Check if a database of the same name exists
if self.db_name not in os.listdir(path = os.getcwd()):
self.running_db.commit()
else:
raise Exception
except:
overwrite_permission = input('Overwrite most recent database? [y]/n ')
if overwrite_permission in ['', 'y']:
running_db.commit()
running_db.close()
print('Database overwritten.')
else:
print('Commit canceled. Rename database.')
if __name__ == '__main__':
new_db = db_creator()
new_db.create_db()