-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanRetrosheet.py
More file actions
25 lines (21 loc) · 997 Bytes
/
cleanRetrosheet.py
File metadata and controls
25 lines (21 loc) · 997 Bytes
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
# This removes all tables that we can re-generate with our Elo*.r scripts
import sqlite3 as lite
con = lite.connect('retrosheet.db')
cur = con.cursor()
print('Would you like to remove all dates above 20150000 (Y/n)?')
if raw_input() == 'Y':
with con:
cur.execute('DELETE FROM EVENTS_ID WHERE Date >= 20150000')
cur.execute('DELETE FROM games WHERE YEAR_ID = 2015')
# Get tables
with con:
cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cur.fetchall()
# Now filter tables to find all Mu Sigma tables
for player in ['pitcher', 'batter', 'Pitcher', 'Batter', 'PIT', 'BAT']:
for stat in ['Mu', 'Sigma', 'SOBB_HBPHit', 'SingleDoubleTripleHROut', '_hands', '_cum']:
filtered_tables = filter(lambda x: x[0].find('{}{}'.format(player, stat)) != -1, tables)
for table in filtered_tables:
with con:
print('Dropping {}'.format(table[0]))
cur.execute("DROP TABLE {};".format(table[0]))