Created
May 22, 2023 18:13
-
-
Save chrisking/e659200eda42b6cbd538bf3b03326481 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import traceback | |
import logging | |
import requests | |
from django.core.management.base import BaseCommand, CommandError | |
from apps.ufcstats.models import Fighter, Prediction, SportsBook, Odds, MLModel | |
from django.conf import settings | |
logger = logging.getLogger(__name__) | |
# Fighter Alias Dict for storing name screw ups | |
fighter_alias_dict = dict() | |
# Fighter name from the sportsbook is the key, fighter name from the DB is the value | |
fighter_alias_dict["Leomana Martinez"] = "Mana Martinez" | |
fighter_alias_dict["T.J. Dillashaw"] = "TJ Dillashaw" | |
fighter_alias_dict["Khalil Rountree"] = "Khalil Rountree Jr." | |
fighter_alias_dict["Steve Garcia Jr."] = "Steve Garcia" | |
fighter_alias_dict["Nathan Maness"] = "Nate Maness" | |
fighter_alias_dict['Mark O. Madsen'] = "Mark Madsen" | |
fighter_alias_dict['Weili Zhang'] = "Zhang Weili" | |
fighter_alias_dict['Daniel Hooker'] = "Dan Hooker" | |
fighter_alias_dict['Seung-Woo Choi'] = "SeungWoo Choi" | |
fighter_alias_dict['Shamil Abdurahimov'] = "Shamil Abdurakhimov" | |
fighter_alias_dict["Terrance Mckinney"] = "Terrance McKinney" | |
fighter_alias_dict['Zarah Fairn Dos Santos'] = "Zarah Fairn" | |
fighter_alias_dict['Sergey Spivak'] = "Serghei Spivac" | |
fighter_alias_dict['Da Un Jung'] = "Da-Un Jung" | |
fighter_alias_dict['Mandy Böhm'] = "Mandy Bohm" | |
fighter_alias_dict['Jun Yong Park'] = "Junyong Park" | |
fighter_alias_dict['Jesus Santos Aguilar'] = "Jesus Aguilar" | |
fighter_alias_dict['Alex Volkanovski'] = "Alexander Volkanovski" | |
fighter_alias_dict['Jim Crute'] = "Jimmy Crute" | |
fighter_alias_dict['Alex Hernandez'] = "Alexander Hernandez" | |
fighter_alias_dict['Ovince St. Preux'] = "Ovince Saint Preux" | |
fighter_alias_dict['Geoffrey Neal'] = "Geoff Neal" | |
fighter_alias_dict['Kenan Song'] = "Song Kenan" | |
fighter_alias_dict['Leomana Martinez'] = "Mana Martinez" | |
fighter_alias_dict["L'udovit Klein"] = "Ludovit Klein" | |
fighter_alias_dict["Daniel Da Silva"] = "Daniel Lacerda" | |
fighter_alias_dict['Alexander Romanov'] = "Alexandr Romanov" | |
fighter_alias_dict['Jj Aldrich'] = "JJ Aldrich" | |
fighter_alias_dict['Steve Garcia Jr.'] = "Steve Garcia" | |
fighter_alias_dict['Joseph Pyfer'] = "Joe Pyfer" | |
fighter_alias_dict['Lupita Godinez'] = "Loopy Godinez" | |
fighter_alias_dict['Raul Rosas Jr'] = "Raul Rosas Jr." | |
fighter_alias_dict['Michelle Waterson'] = "Michelle Waterson-Gomez" | |
fighter_alias_dict['Brogan Walker-Sanchez'] = "Brogan Walker" | |
fighter_alias_dict['Rick Glenn'] = "Ricky Glenn" | |
fighter_alias_dict['Mandy Böhm'] = "Mandy Bohm" | |
fighter_alias_dict['Gabriel Green'] = "Gabe Green" | |
fighter_alias_dict['Carlos Diego Ferreira'] = "Diego Ferreira" | |
fighter_alias_dict['Hayisaer Maheshate'] = "Maheshate" | |
def get_odds_info_from_prediction(prediction, api_response): | |
""" | |
This function serves to take a particular prediction and the responses from the API to find and return | |
back only the relevant odds components from various books. | |
""" | |
response_json = api_response.json() | |
for item in response_json: | |
if (prediction.fighter_1.name == item["home_team"]) and ( | |
prediction.fighter_2.name == item["away_team"] | |
): | |
return item["bookmakers"] | |
return None | |
def get_odds_api_response(): | |
params = { | |
"api_key": settings.THE_ODDS_API_KEY, | |
"regions": ",".join(settings.THE_ODDS_API_REGION_LIST), | |
"markets": "h2h", | |
"oddsFormat": "american", | |
} | |
mma_response = requests.get( | |
"https://api.the-odds-api.com/v4/sports/mma_mixed_martial_arts/odds/", | |
params=params, | |
) | |
return mma_response | |
def get_predictions_and_order(red_corner, blue_corner): | |
""" | |
This attempts to correct if red and blue corners have been swapped to get a prediction | |
""" | |
flipped = False | |
try: | |
predictions = Prediction.objects.filter( | |
fighter_1=red_corner, fighter_2=blue_corner, graded=False | |
) | |
if len(predictions) == 0: | |
predictions = Prediction.objects.filter( | |
fighter_1=blue_corner, fighter_2=red_corner, graded=False | |
) | |
flipped = True | |
except: | |
predictions = Prediction.objects.filter( | |
fighter_1=blue_corner, fighter_2=red_corner, graded=False | |
) | |
flipped = True | |
return predictions, flipped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment