Skip to content

Commit

Permalink
add last game data with -lg
Browse files Browse the repository at this point in the history
  • Loading branch information
nealmick committed Nov 12, 2023
1 parent b9215c5 commit 3536b4f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
Binary file modified Data/objects/futureCache.pkl
Binary file not shown.
Binary file removed Data/objects/res.pkl
Binary file not shown.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ def main():
parser.add_argument('-A', action='store_true', help='Run all Models')
parser.add_argument('-odds', help='Sportsbook to fetch from. (fanduel, draftkings, betmgm, pointsbet, caesars, wynn, bet_rivers_ny')
parser.add_argument('-kc', action='store_true', help='Calculates percentage of bankroll to bet based on model edge')
parser.add_argument('-lg', action='store_true', help='Run with last game stats. Currently only supported for xgb money line.')
parser.add_argument('-lg', action='store_true', help='Run with last game stats. Currently only supported for xgb money line model.')
args = parser.parse_args()
main()
2 changes: 1 addition & 1 deletion src/Predict/XGBoost_Runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def xgb_runner(data, todays_games_uo, frame_ml, games, home_team_odds, away_team
for row in data:
home_team = games[c][0]
away_team = games[c][1]
if lg:
if lg:#call augment future data if -lg flag is passed
row = afd(home_team, away_team,row)#AugmentFutureData fetches last game and adds to row...
ml_predictions_array.append(xgb_ml.predict(xgb.DMatrix(np.array([row]))))
c += 1
Expand Down
3 changes: 2 additions & 1 deletion src/Train-Models/XGBoost_Model_ML.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@


import sys
from pathlib import Path
src = str(Path(__file__).resolve().parent.parent)
sys.path.insert(0, src)

from src.Utils.lg import AugmentData
from Utils.lg import AugmentData



Expand Down
55 changes: 51 additions & 4 deletions src/Utils/lg.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def getLastGame(game_date,team_id,cache,game_objects):
def AugmentData(data):
# can add or remove this line here, only works if its been run once before and we have cache saved
# but makes it alot faster if re running
#return load_obj('res')

#return load_obj('res')#uncomment here to load from cache

header = getLabels()
for stat in header:
Expand Down Expand Up @@ -366,7 +367,8 @@ def AugmentFutureData(home_team, away_team,row):
print('Augmenting data for',home_team, 'v',away_team)
home_team_lg_data = getLastGameFutures(home_team)
visitor_team_lg_data = getLastGameFutures(away_team)

print(home_team_lg_data)
print(visitor_team_lg_data)
combined_data = home_team_lg_data[:87] + visitor_team_lg_data[:87]
combined_data = np.array(combined_data, dtype=np.float32)

Expand Down Expand Up @@ -398,6 +400,7 @@ def getLastGameFutures(team_name):
# games endpoint url with params for start date, end date and team id...
# this api call basically gets the last month of games before the game date...
# we use the url as our cache key in order to make things go alot faster...
save_obj_root({},'futureCache')

futureCache = load_obj_root('futureCache')

Expand Down Expand Up @@ -426,8 +429,52 @@ def getLastGameFutures(team_name):
#print('found close game date setting game id here to: '+str(lastID))
#print(game_date.strftime('%Y-%m-%d'),game['date'])




url = 'https://www.balldontlie.io/api/v1/stats?game_ids[]='+str(lastID)

print('url')
try:
r = futureCache[url]
except KeyError:
r = req(url)
futureCache[url] = r
save_obj_root(futureCache,'futureCache')

data = formLastGame(r,team_id)
formed_data = []
formed_data.append(data['history_score'])
formed_data.append(data['opponent_score'])

for player in data['best_history_players']:
for label in labels:
formed_data.append(player[label])

for player in data['best_opponent_players']:
for label in labels:
formed_data.append(player[label])

return formed_data
























Expand Down

0 comments on commit 3536b4f

Please sign in to comment.