forked from Jman4190/nba-sql
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Mode to update the current season. (#64)
* Adding default_mode and current_season_mode switches * live refresh of shot_chart_detail working * current season ignore tables * update current season for player_game_log and game table
- Loading branch information
Showing
14 changed files
with
421 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --create-schema | ||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --default_mode --database="mysql" --create-schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --database="postgres" --create-schema | ||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --default_mode --database="postgres" --skip-tables play_by_play pgtt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --database="sqlite" --create-schema --skip-tables play_by_play | ||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --default_mode --skip-tables play_by_play pgtt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --current_season_mode --database="postgres" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
DB_NAME="nba" DB_HOST="localhost" DB_USER=nba_sql DB_PASSWORD=nba_sql python stats/nba_sql.py --current_season_mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from gooey import GooeyParser | ||
from constants import season_list | ||
|
||
|
||
""" | ||
Creates a parser. | ||
""" | ||
|
||
|
||
def create_parser(): | ||
""" | ||
Creates and returns a Gooey parser. | ||
""" | ||
|
||
parser = GooeyParser(description="nba-sql") | ||
|
||
mode_parser = parser.add_mutually_exclusive_group( | ||
required=True, | ||
gooey_options={ | ||
'initial_selection': 0 | ||
}) | ||
mode_parser.add_argument( | ||
'--default_mode', | ||
help='Mode to create the database and load historic data. Use this mode when creating a new database or when trying to load a specific season or a range of seasons.', | ||
action='store_true') | ||
mode_parser.add_argument( | ||
'--current_season_mode', | ||
help='Mode to refresh the current season. Use this mode on an existing database to update it with the latest data.', | ||
action='store_true') | ||
|
||
parser.add_argument( | ||
'--database', | ||
dest='database_type', | ||
default='sqlite', | ||
choices=['mysql', 'postgres', 'sqlite'], | ||
help='The database flag specifies which database protocol to use. Defaults to "sqlite", but also accepts "postgres" and "mysql".') | ||
|
||
parser.add_argument( | ||
'--database_name', | ||
help="Database Name (Not Needed For SQLite)", | ||
default='nba') | ||
|
||
parser.add_argument( | ||
'--database_host', | ||
help="Database Hostname (Not Needed For SQLite)", | ||
default=None) | ||
|
||
parser.add_argument( | ||
'--username', | ||
help="Database Username (Not Needed For SQLite)", | ||
default=None) | ||
|
||
parser.add_argument( | ||
'--password', | ||
help="Database Password (Not Needed For SQLite)", | ||
widget='PasswordField', | ||
default=None) | ||
|
||
last_loadable_season = season_list[-1] | ||
|
||
parser.add_argument( | ||
'--seasons', | ||
dest='seasons', | ||
default=[last_loadable_season], | ||
choices=season_list, | ||
widget='Listbox', | ||
nargs="*", | ||
help='The seasons flag loads the database with the specified season. The format of the season should be in the form "YYYY-YY". The default behavior is loading the current season.') | ||
|
||
parser.add_argument( | ||
'--create-schema', | ||
dest='create_schema', | ||
action="store_true", | ||
default=True, | ||
help='Flag to initialize the database schema before loading data. If the schema already exists then nothing will happen.') | ||
|
||
parser.add_argument( | ||
'--time-between-requests', | ||
dest='request_gap', | ||
default='.7', | ||
help='This flag exists to prevent rate limiting, and injects the desired amount of time inbetween requesting resources.') | ||
|
||
parser.add_argument( | ||
'--skip-tables', | ||
action='store', | ||
nargs="*", | ||
default='', | ||
choices=['player_season', 'player_game_log', 'play_by_play', 'pgtt', 'shot_chart_detail', 'game', 'event_message_type', 'team', 'player', ''], | ||
widget='Listbox', | ||
help='Use this option to skip loading certain tables.') | ||
|
||
#To fix issue https://github.com/mpope9/nba-sql/issues/56 | ||
parser.add_argument( | ||
'--batch_size', | ||
default='10000', | ||
type=int, | ||
help="Inserts BATCH_SIZE chunks of rows to the database. This value is ignored when selecting database 'sqlite'.") | ||
|
||
return parser | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from peewee import ( | ||
IntegerField, | ||
FloatField, | ||
Model, | ||
CompositeKey, | ||
FixedCharField | ||
) | ||
from . import Player | ||
from . import Team | ||
from . import Game | ||
|
||
|
||
class PlayerGameLogTemp(Model): | ||
|
||
# Composite PK Fields | ||
player_id = IntegerField(index=True) | ||
game_id = IntegerField(null=True) | ||
|
||
team_id = IntegerField(index=True) | ||
|
||
# Indexes | ||
season_id = IntegerField(index=True) | ||
|
||
wl = FixedCharField(null=True, max_length=1) | ||
min = FloatField(null=True) | ||
fgm = FloatField(null=True) | ||
fga = FloatField(null=True) | ||
fg_pct = FloatField(null=True) | ||
fg3m = FloatField(null=True) | ||
fg3a = FloatField(null=True) | ||
fg3_pct = FloatField(null=True) | ||
ftm = FloatField(null=True) | ||
fta = FloatField(null=True) | ||
ft_pct = FloatField(null=True) | ||
oreb = FloatField(null=True) | ||
dreb = FloatField(null=True) | ||
reb = FloatField(null=True) | ||
ast = FloatField(null=True) | ||
tov = FloatField(null=True) | ||
stl = FloatField(null=True) | ||
blk = FloatField(null=True) | ||
blka = FloatField(null=True) | ||
pf = FloatField(null=True) | ||
pfd = FloatField(null=True) | ||
pts = FloatField(null=True) | ||
plus_minus = FloatField(null=True) | ||
nba_fantasy_pts = FloatField(null=True) | ||
dd2 = FloatField(null=True) | ||
td3 = FloatField(null=True) | ||
|
||
class Meta: | ||
db_table = 'player_game_log_temp' | ||
primary_key = CompositeKey( | ||
'player_id', | ||
'game_id' | ||
) | ||
temporary = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.