Skip to content

Commit

Permalink
Dynamic current season based on current month. (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpope9 authored Nov 5, 2023
1 parent 281585e commit 6285acb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 53 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,46 @@ It will take an estimated 6 hours to build the whole database. However, some tab

## Commandline Reference
```
>python stats/nba_sql.py -h
>python stats/nba_sql.py --help
usage: nba_sql.py [-h] [--database {mysql,postgres,sqlite}] [--database_name DATABASE_NAME] [--database_host DATABASE_HOST]
[--username USERNAME] [--create-schema] [--time-between-requests REQUEST_GAP] [--batch_size BATCH_SIZE]
[--sqlite-path SQLITE_PATH] [--quiet] [--default-mode] [--current-season-mode] [--password PASSWORD]
[--seasons [{1997-98,1998-99,1999-00,2000-01,2001-02,2002-03,2003-04,2004-05,2005-06,2006-07,2007-08,2008-09,2009-10,2010-11,2011-12,2012-13,2013-14,2014-15,2015-16,2016-17,2017-18,2018-19,2019-20,2020-21,2021-22,2022-23} ...]]
[--seasons [{1997-98,1998-99,1999-00,2000-01,2001-02,2002-03,2003-04,2004-05,2005-06,2006-07,2007-08,2008-09,2009-10,2010-11,2011-12,2012-13,2013-14,2014-15,2015-16,2016-17,2017-18,2018-19,2019-20,2020-21,2021-22,2022-23,2023-24} ...]]
[--skip-tables [{player_season,player_game_log,play_by_play,pgtt,shot_chart_detail,game,event_message_type,team,player,} ...]]
nba-sql
optional arguments:
-h, --help show this help message and exit
--database {mysql,postgres,sqlite}
The database flag specifies which database protocol to use. Defaults to "sqlite", but also accepts "postgres" and
"mysql".
The database flag specifies which database protocol to use. Defaults to "sqlite", but also accepts
"postgres" and "mysql".
--database_name DATABASE_NAME
Database Name (Not Needed For SQLite)
--database_host DATABASE_HOST
Database Hostname (Not Needed For SQLite)
--username USERNAME Database Username (Not Needed For SQLite)
--create-schema Flag to initialize the database schema before loading data. If the schema already exists then nothing will happen.
--create-schema Flag to initialize the database schema before loading data. If the schema already exists then nothing
will happen.
--time-between-requests REQUEST_GAP
This flag exists to prevent rate limiting, and injects the desired amount of time inbetween requesting resources.
This flag exists to prevent rate limiting, and injects the desired amount of time inbetween requesting
resources.
--batch_size BATCH_SIZE
Inserts BATCH_SIZE chunks of rows to the database. This value is ignored when selecting database 'sqlite'.
Inserts BATCH_SIZE chunks of rows to the database. This value is ignored when selecting database
'sqlite'.
--sqlite-path SQLITE_PATH
Setting to define sqlite path.
--quiet Setting to define stdout logging level. If set, only "ok" will be printed if ran successfully. This currently only
applies to refreshing a db, and not loading one.
--default-mode 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.
--quiet Setting to define stdout logging level. If set, only "ok" will be printed if ran successfully. This
currently only applies to refreshing a db, and not loading one.
--default-mode 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.
--current-season-mode
Mode to refresh the current season. Use this mode on an existing database to update it with the latest data.
Mode to refresh the current season. Use this mode on an existing database to update it with the latest
data.
--password PASSWORD Database Password (Not Needed For SQLite)
--seasons [{1997-98,1998-99,1999-00,2000-01,2001-02,2002-03,2003-04,2004-05,2005-06,2006-07,2007-08,2008-09,2009-10,2010-11,2011-12,2012-13,2013-14,2014-15,2015-16,2016-17,2017-18,2018-19,2019-20,2020-21,2021-22,2022-23} ...]
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.
--seasons [{1997-98,1998-99,1999-00,2000-01,2001-02,2002-03,2003-04,2004-05,2005-06,2006-07,2007-08,2008-09,2009-10,2010-11,2011-12,2012-13,2013-14,2014-15,2015-16,2016-17,2017-18,2018-19,2019-20,2020-21,2021-22,2022-23,2023-24} ...]
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.
--skip-tables [{player_season,player_game_log,play_by_play,pgtt,shot_chart_detail,game,event_message_type,team,player,} ...]
Use this option to skip loading certain tables.
```
Expand Down
33 changes: 0 additions & 33 deletions stats/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,6 @@
Constants used in the application.
"""

"""
List of seasons.
"""
season_list = [
'1996-97',
'1997-98',
'1998-99',
'1999-00',
'2000-01',
'2001-02',
'2002-03',
'2003-04',
'2004-05',
'2005-06',
'2006-07',
'2007-08',
'2008-09',
'2009-10',
'2010-11',
'2011-12',
'2012-13',
'2013-14',
'2014-15',
'2015-16',
'2016-17',
'2017-18',
'2018-19',
'2019-20',
'2020-21',
'2021-22',
'2022-23'
]

"""
Headers.
"""
Expand Down
2 changes: 1 addition & 1 deletion stats/nba_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from play_by_play import PlayByPlayRequester
from shot_chart_detail import ShotChartDetailRequester

from constants import season_list, team_ids
from constants import team_ids
from settings import Settings
from utils import progress_bar, generate_valid_seasons, generate_valid_season

Expand Down
11 changes: 7 additions & 4 deletions stats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"""

import datetime
from constants import season_list

from datetime import datetime

def season_id_to_int(season_id):
"""
Expand Down Expand Up @@ -88,11 +87,15 @@ def printProgressBar(iteration):

def generate_valid_seasons():
"""
Genrate the valid seasons to choose from, starting at 1997 to the current date.
Genrate the valid seasons to choose from, starting at 1997 to the current season.
This assumes that a season begins in October.
"""

valid_seasons = []
curr_season = int(season_list[-1].split('-')[1])
if datetime.now().month > 10:
curr_season = datetime.now().year - 2000 + 1
else:
curr_season = datetime.now().year - 2000
for x in range(1997, curr_season + 2000):
valid_season = generate_valid_season(x)
valid_seasons.append(valid_season)
Expand Down

0 comments on commit 6285acb

Please sign in to comment.