Untitled

mail@pastecode.io avatar
unknown
python
7 months ago
14 kB
6
Indexable
Never
# Team Insights

flavors = {
    # Example: The Los Angeles Clippers are 4-0 (100%) vs. the Detroit Pistons since the start of 2020/2021
    "overall": None,  # NHL, MLB, NBA, NFL
    # Example: The Detroit Pistons are 0-5 (0%) as an underdog in their last five games in 2022/2023
    "asUnderdog": "as an underdog",  # NHL, NBA, NFL
    # Example: The Los Angeles Clippers are 5-0 (100%) at home as a favorite in their last five games in 2022/2023
    "asFavorite": "as a favorite",  # NHL, NBA, NFL
}

statuses = {
    # Example: The Los Angeles Clippers are 4-0 (100%) vs. the Detroit Pistons since the start of 2020/2021
    "all": None,  # NHL, MLB, NBA, NFL
    # Example: The over hit in 0 of the Los Angeles Clippers last 5 games at home off a loss in 2022/2023
    "offLoss": "off a loss",  # NHL, MLB, NBA, NFL
    # Example: The New Orleans Pelicans are 0-5 (0%) against the spread on the road off two or more days rest over their last 6 games
    "offTwoPlusDaysRest": "off two or more days rest",  # NHL, NBA
    # Example: The Charlotte Hornets are 1-5 (16.7%) against the spread off a win over their last 6 games
    "offWin": "off a win",  # NHL, MLB, NBA, NFL
    # The over hit in 7 of the Utah Jazz last 23 games at home off one day rest since the start of 2021/2022
    "offOneDayRest": "off one day rest",  # NHL, NBA
    # Example: The over hit in 8 of the Memphis Grizzlies last 9 games at home off two days rest across the regular season and playoffs since the start of 2020/2021
    "offTwoDaysRest": "off two days rest",  # NHL, NBA
    # The over hit in 4 of the Toronto Raptors last 5 games vs. the Cleveland Cavaliers off a back to back since the start of 2014/2015
    "onBackToBack": "off a back to back"  # NBA
}

settings = {
    # Example: The Los Angeles Clippers are 4-0 (100%) vs. the Detroit Pistons since the start of 2020/2021
    None: None,  # NHL, MLB, NBA, NFL
    # Example: The Detroit Pistons are 0-5 (0%) at home in their last five games in 2022/2023
    "atHome": "at home",  # NHL, MLB, NBA, NFL
    # Example: The over hit in 5 of the Los Angeles Clippers last 5 games on the road in 2022/2023
    "onRoad": "on the road",  # NHL, MLB, NBA, NFL
}

data_timeframes = {
    # The Tampa Bay Buccaneers are 0-6-1 (.000) against the spread off a loss over their last 7 games
    "regular season": None,  # NHL, MLB, NBA, NFL
    # Example: The over hit in 4 of the Arizona Cardinals last 15 games on the road off a loss across the regular season and playoffs since the start of 2020
    "regular season and playoffs": "across the regular season and playoffs",  # NHL, MLB, NBA, NFL
    # Example: The Philadelphia Phillies are 1-1 (.500) vs. the Houston Astros at home in 2022
    "playoffs": None,  # NHL, MLB, NBA, NFL
}

percent_winning_time_frames = [
    # Example: The Nashville Predators are 0-5-1 (0%) on the road off two or more days rest over their last 6 games
    "twentyPercentWinning",  # NHL, NFL
    # Example: The Anaheim Ducks are 1-9-2 (8.3%) on the road off two or more days rest over their last 12 games
    "twentyFivePercentWinning",  # NHL, NFL
    # Example: The Chicago Blackhawks are 3-12-1 (18.8%) off two or more days rest over their last 16 games
    "thirtyPercentWinning",  # NHL, NFL
    # Example: The Anaheim Ducks are 4-17 (19%) off two or more days rest over their last 21 games
    "thirtyFivePercentWinning",  # NHL, NFL
    # Example: The Anaheim Ducks are 15-4-1 (75%) vs. the Calgary Flames at home over their last 20 games
    "sixtyFivePercentWinning",  # NHL, MLB, NFL
    # Example: The Colorado Avalanche are 18-1 (94.7%) off two or more days rest over their last 19 games
    "seventyPercentWinning",  # NHL, MLB, NFL
    # Example: The Colorado Avalanche are 13-1 (92.9%) off two or more days rest over their last 14 games
    "seventyFivePercentWinning",  # NHL, MLB, NFL
    # Example: The Washington Capitals are 7-0 (100%) vs. the Winnipeg Jets at home over their last 7 games
    "eightyPercentWinning",  # NHL, MLB, NFL
]

percent_covers_time_frames = [
    # Example: The New Orleans Pelicans are 0-5 (0%) against the spread on the road off two or more days rest over their last 6 games
    "twentyPercentCovers",  # NBA, NFL
    # Example: The San Antonio Spurs are 1-11 (7.7%) against the spread off a loss over their last 13 games
    "twentyFivePercentCovers",  # NBA, NFL
    # Example: The Houston Rockets are 4-13 (23.5%) against the spread off two or more days rest over their last 17 games
    "thirtyPercentCovers",  # NBA, NFL
    # Example: The Chicago Bulls are 5-14 (25%) against the spread at home over their last 20 games
    "thirtyFivePercentCovers",  # NBA, NFL
    # Example: The Cincinnati Bengals are 44-22 (66.7%) against the spread on the road over their last 66 games
    "sixtyFivePercentCovers",  # NFL
    # Example: The Cleveland Cavaliers are 14-5 (73.7%) against the spread at home over their last 19 games
    "seventyPercentCovers",  # NBA, NFL
    # Example: The Philadelphia 76ers are 12-2 (85.7%) against the spread at home off a win over their last 14 games
    "seventyFivePercentCovers",  # NBA, NFL
    # Example: The Portland Trail Blazers are 6-1 (85.7%) against the spread vs. the Charlotte Hornets at home over their last 7 games
    "eightyPercentCovers",  # NBA, NFL
]

percent_overs_time_frames = [
    # Example: The over hit in 0 of the Los Angeles Clippers last 5 games at home off a loss in 2022/2023
    "twentyPercentOvers",  # NBA, NFL
    # Example: The over hit in 2 of the Los Angeles Clippers last 13 games at home in 2022/2023
    "twentyFivePercentOvers",  # NBA, NFL
    # Example: The over hit in 5 of the Cleveland Cavaliers last 19 games at home off two or more days rest since the start of 2019/2020
    "thirtyPercentOvers",  # NBA, NFL
    # Example: The over hit in 6 of the Charlotte Hornets last 21 games at home since the start of 2021/2022
    "thirtyFivePercentOvers",  # NBA, NFL
    # Example: The over hit in 14 of the Phoenix Suns last 21 games vs. the Denver Nuggets off a loss across the regular season and playoffs since the start of 2012/2013
    "sixtyFivePercentOvers",  # NBA, NFL
    # Example: The over hit in 14 of the Charlotte Hornets last 19 games on the road since the start of 2021/2022
    "seventyPercentOvers",  # NBA, NFL
    # Example: The over hit in 11 of the Charlotte Hornets last 14 games off two or more days rest since the start of 2021/2022
    "seventyFivePercentOvers",  # NBA, NFL
    # Example: The over hit in 8 of the Los Angeles Clippers last 9 games on the road in 2022/2023
    "eightyPercentOvers",  # NBA, NFL
]

three_plus_time_frames = [
    # Example: The Colorado Avalanche have won their last 14 games at home off two or more days rest
    "threePlusWins",  # NHL, MLB, NFL
    # Example: The Anaheim Ducks have lost their last 7 games on the road off two or more days rest
    "threePlusLosses",  # NHL, NFL
    # Example: The Cleveland Cavaliers have covered in their last 6 games off a loss
    "threePlusCovers",  # NBA, NFL
    # Example: The Miami Heat have not covered in their last 3 games at home off a loss
    "threePlusNonCovers",  # NBA, NFL
    # Example: The over has hit in the Detroit Pistons last 5 games at home off a loss
    "threePlusOvers",  # NBA, NFL
    # Example: The under has hit in the Los Angeles Clippers last 5 games at home off a loss
    "threePlusUnders",  # NBA, NFL
]

last_n_time_frames = [
    # Example: The Detroit Pistons are 0-5 (0%) in their last five games in 2022/2023
    "lastFiveGames",  # NHL, NBA, NFL
    # Example: The Utah Jazz are 5-0 (100%) at home as an underdog in 2022/2023
    "currentSeason",  # NHL, MLB, NBA, NFL
    # Example: The Los Angeles Clippers are 4-0 (100%) vs. the Detroit Pistons since the start of 2020/2021
    "lastTwoSeasons",  # NHL, NBA, NFL
    # Example: The Calgary Flames are 4-0 (100%) vs. the Anaheim Ducks on the road over the last three seasons
    "lastThreeSeasons",  # NHL, MLB, NFL
]

def build_team_insight_description(dto: SRTeamBettingTrendDto, cur_season: str) -> Optional[str]:
    if (dto.event.type.time_frame in percent_winning_time_frames or
            (dto.event.market == 'moneyLine' and dto.event.type.time_frame in last_n_time_frames)):
        record = str(dto.event.record.overall.wins)
        record += f'-{dto.event.record.overall.losses}'
        if _sum_ml_pushes(dto.event.record.overall):
            record += f'-{_sum_ml_pushes(dto.event.record.overall)}'
        insight_text = f'The {dto.event.team.name} are {record} ({str(dto.event.record.overall.wins_percent).replace(".0", "")}%)'
    elif (dto.event.type.time_frame in percent_covers_time_frames or
          (dto.event.market == 'spread' and dto.event.type.time_frame in last_n_time_frames)):
        record = str(dto.event.record.spread.covered)
        record += f'-{dto.event.record.spread.not_covered}'
        if dto.event.record.spread.pushed:
            record += f'-{dto.event.record.spread.pushed}'
        insight_text = f'The {dto.event.team.name} are {record} ({str(dto.event.record.spread.covered_percent).replace(".0", "")}%) against the spread'
    elif (dto.event.type.time_frame in percent_overs_time_frames or
          (dto.event.market == 'overUnder' and dto.event.type.time_frame in last_n_time_frames)):
        if dto.event.record.over_under.over == 1 and dto.event.record.overall.total == 1:
            insight_text = f'The over hit in the {dto.event.team.name} only game'
        else:
            if dto.event.record.over_under.over > dto.event.record.over_under.under:
                insight_text = f'The over hit in {dto.event.record.over_under.over} of the {dto.event.team.name} last {dto.event.record.overall.total} games ({str(dto.event.record.over_under.over_percent).replace(".0", "")}%)'
            else:
                insight_text = f'The under hit in {dto.event.record.over_under.under} of the {dto.event.team.name} last {dto.event.record.overall.total} games ({str(dto.event.record.over_under.under_percent).replace(".0", "")}%)'
    elif dto.event.type.time_frame in three_plus_time_frames:
        if dto.event.type.time_frame.endswith("PlusWins"):
            insight_text = f'The {dto.event.team.name} have won their last {dto.event.record.overall.wins} games'
        elif dto.event.type.time_frame.endswith("PlusLosses"):
            insight_text = f'The {dto.event.team.name} have lost their last {dto.event.record.overall.losses} games'
        elif dto.event.type.time_frame.endswith("PlusCovers"):
            insight_text = f'The {dto.event.team.name} have covered in their last {dto.event.record.spread.covered} games'
        elif dto.event.type.time_frame.endswith("PlusNonCovers"):
            insight_text = f'The {dto.event.team.name} have not covered in their last {dto.event.record.spread.not_covered} games'
        elif dto.event.type.time_frame.endswith("PlusOvers"):
            insight_text = f'The over has hit in the {dto.event.team.name} last {dto.event.record.over_under.over} games'
        elif dto.event.type.time_frame.endswith("PlusUnders"):
            insight_text = f'The under has hit in the {dto.event.team.name} last {dto.event.record.over_under.under} games'
        else:
            logger.error(f'Unable to map Insight time_frame {dto.event.type.time_frame} in three_plus_time_frames to description for insight {dto.content}')
            return None
    else:
        logger.error(f'Unable to map Insight time_frame {dto.event.type.time_frame} to description for insight {dto.content}')
        return None

    if dto.event.type.vs_opponent and dto.event.opponent:
        insight_text += f' vs. the {dto.event.opponent.name}'

    if dto.event.type.setting not in settings:
        logger.error(f'Unable to map Insight setting {dto.event.type.setting} to description for insight {dto.content}')
        return None
    setting = settings[dto.event.type.setting]
    if setting:
        insight_text += f' {setting}'

    if dto.event.type.status not in statuses:
        logger.error(f'Unable to map Insight status {dto.event.type.status} to description for insight {dto.content}')
        return None
    status = statuses[dto.event.type.status]
    if status:
        insight_text += f' {status}'

    if dto.event.type.flavor not in flavors:
        logger.error(f'Unable to map Insight flavor {dto.event.type.flavor} to description for insight {dto.content}')
        return None
    flavor = flavors[dto.event.type.flavor]
    if flavor:
        insight_text += f' {flavor}'

    if dto.event.type.time_frame == 'lastFiveGames' and dto.event.market in ['moneyLine', 'spread']:
        insight_text += f' in their last five games'

    if dto.event.type.time_frame == 'lastThreeSeasons':
        insight_text += f' over the last three seasons'
    elif (dto.event.type.time_frame in percent_winning_time_frames or
          dto.event.type.time_frame in percent_covers_time_frames):
        insight_text += f' over their last {dto.event.record.overall.total} games'
    elif dto.event.type.time_frame not in three_plus_time_frames:
        if dto.event.data_timeframe not in data_timeframes:
            logger.error(f'Unable to map Insight data_timeframe {dto.event.data_timeframe} to description for insight {dto.content}')
            return None
        data_timeframe = data_timeframes[dto.event.data_timeframe]
        if data_timeframe and dto.event.type.time_frame != 'currentSeason':
            insight_text += f' {data_timeframe}'

        season = dto.event.season.season_since if dto.event.season.season_since else dto.event.season.season

        if season.startswith(str(cur_season)):
            insight_text += f' in {season}'
        else:
            insight_text += f' since the start of {season}'

    return insight_text
Leave a Comment