Ejemplo n.º 1
0
def generate_top_4_playoffs(first_playoff_week: int) -> List[ScheduleWeek]:
    week_1 = ScheduleWeek(week_number=first_playoff_week,
                          week_type=WeekType.PLAYOFFS)
    week_1.matchups.append(Matchup(type=MatchupType.PLAYOFF))
    week_1.matchups.append(Matchup(type=MatchupType.PLAYOFF))

    championship_week = ScheduleWeek(week_number=first_playoff_week + 1,
                                     week_type=WeekType.CHAMPIONSHIP)
    championship_week.matchups.append(Matchup(type=MatchupType.CHAMPIONSHIP))

    return [week_1, championship_week]
Ejemplo n.º 2
0
def test_assign_winners_week2_away_win_home_win():
    previous_week = ScheduleWeek(week_number=1, week_type=WeekType.PLAYOFFS)
    previous_week.matchups = [
        Matchup(id="01",
                away=team_3,
                home=team_2,
                type=MatchupType.PLAYOFF,
                away_score=100,
                home_score=50),
        Matchup(id="02",
                away=team_4,
                home=team_1,
                type=MatchupType.PLAYOFF,
                away_score=50,
                home_score=100)
    ]

    current_week = ScheduleWeek(week_number=2, week_type=WeekType.CHAMPIONSHIP)
    current_week.matchups = [Matchup(id="01", type=MatchupType.CHAMPIONSHIP)]

    current_week.assign_playoff_matchups(PlayoffType.TOP_4, teams,
                                         previous_week)
    matchup = current_week.matchups[0]
    are_equal(matchup.away, team_3)
    are_equal(matchup.home, team_1)
Ejemplo n.º 3
0
def test_week3_assign_playoff_matchups_top6(home_wins: bool):
    previous_week = ScheduleWeek(week_number=0, week_type=WeekType.REGULAR)
    playoffs = generate_playoffs(teams,
                                 PlayoffType.TOP_6,
                                 first_playoff_week=2,
                                 enable_loser_playoff=False)
    week1 = playoffs[0]
    # setup week 1
    week1.assign_playoff_matchups(PlayoffType.TOP_6, teams, previous_week)

    for matchup in week1.matchups:
        if matchup.type != MatchupType.PLAYOFF_BYE:
            matchup.home_score = 100 if home_wins else 0
            matchup.away_score = 100 if not home_wins else 0

    week2 = playoffs[1]
    week2.assign_playoff_matchups(PlayoffType.TOP_6, teams, week1)

    for matchup in week2.matchups:
        matchup.home_score = 100 if home_wins else 0
        matchup.away_score = 100 if not home_wins else 0

    week3 = playoffs[2]
    week3.assign_playoff_matchups(PlayoffType.TOP_6, teams, week2)

    matchup = week3.matchups[0]
    if home_wins:
        are_equal(team_1.id, matchup.home.id)
        are_equal(team_2.id, matchup.away.id)
    else:
        are_equal(team_5.id, matchup.home.id)
        are_equal(team_6.id, matchup.away.id)
Ejemplo n.º 4
0
def test_week1_assign_playoff_matchups_top6_no_loser_game(team_count: int):
    rosters = teams[0:team_count]

    previous_week = ScheduleWeek(week_number=0, week_type=WeekType.REGULAR)
    weeks = generate_playoffs(team_count,
                              PlayoffType.TOP_6,
                              first_playoff_week=2,
                              enable_loser_playoff=False)
    week1 = weeks[0]
    week1.assign_playoff_matchups(PlayoffType.TOP_6, rosters, previous_week)

    matchup1 = week1.matchups[0]
    are_equal(team_6, matchup1.away)
    are_equal(team_3, matchup1.home)

    matchup2 = week1.matchups[1]
    are_equal(team_5, matchup2.away)
    are_equal(team_4, matchup2.home)

    matchup3 = week1.matchups[2]
    are_equal(None, matchup3.away)
    are_equal(team_1, matchup3.home)

    matchup4 = week1.matchups[3]
    are_equal(None, matchup4.away)
    are_equal(team_2, matchup4.home)
Ejemplo n.º 5
0
def create_mock_schedule(week_number) -> Schedule:
    return Schedule(weeks=[
        ScheduleWeek(week_number=week_number, week_type=WeekType.REGULAR)
    ],
                    playoff_type=PlayoffType.TOP_2,
                    enable_loser_playoff=False,
                    first_playoff_week=2)
Ejemplo n.º 6
0
def test_week1_assign_playoff_matchups_top2_no_loser_game(team_count: int):
    rosters = teams[0:team_count]

    previous_week = ScheduleWeek(week_number=0, week_type=WeekType.REGULAR)
    playoffs = generate_playoffs(team_count,
                                 PlayoffType.TOP_2,
                                 first_playoff_week=2,
                                 enable_loser_playoff=False)
    week = playoffs[0]
    week.assign_playoff_matchups(PlayoffType.TOP_2, rosters, previous_week)

    championship = week.matchups[0]
    are_equal(team_2, championship.away)
    are_equal(team_1, championship.home)
Ejemplo n.º 7
0
def test_week1_assign_playoff_matchups_top3_loser_game(team_count: int):
    rosters = teams[0:team_count]

    previous_week = ScheduleWeek(week_number=0, week_type=WeekType.REGULAR)
    playoffs = generate_playoffs(team_count,
                                 PlayoffType.TOP_3,
                                 first_playoff_week=2,
                                 enable_loser_playoff=True)
    week = playoffs[0]
    week.assign_playoff_matchups(PlayoffType.TOP_3, rosters, previous_week)

    loser_game = week.matchups[2]
    last_place = rosters[-1]
    second_last = rosters[-2]
    are_equal(last_place, loser_game.away)
    are_equal(second_last, loser_game.home)
Ejemplo n.º 8
0
def test_week1_assign_playoff_matchups_top3_no_loser_game(team_count: int):
    rosters = teams[0:team_count]

    previous_week = ScheduleWeek(week_number=0, week_type=WeekType.REGULAR)
    weeks = generate_playoffs(team_count,
                              PlayoffType.TOP_3,
                              first_playoff_week=2,
                              enable_loser_playoff=False)
    week1 = weeks[0]
    week1.assign_playoff_matchups(PlayoffType.TOP_3, rosters, previous_week)

    matchup = week1.matchups[0]
    are_equal(team_3, matchup.away)
    are_equal(team_2, matchup.home)

    bye = week1.matchups[1]
    are_equal(None, bye.away)
    are_equal(team_1, bye.home)
Ejemplo n.º 9
0
def generate_regular_season(
    number_of_weeks: int,
    sequence: List[List[ScheduledMatchup]],
    rosters: List[Roster],
) -> List[ScheduleWeek]:
    weeks = []

    for week_number in range(1, number_of_weeks + 1):
        games = sequence[0]
        week = ScheduleWeek(week_number=week_number,
                            week_type=WeekType.REGULAR)

        for game in games:
            away = rosters[game.away]
            home = rosters[game.home]
            matchup = Matchup(away=away, home=home, type=MatchupType.REGULAR)
            week.matchups.append(matchup)

        weeks.append(week)

        sequence.append(sequence.pop(0))

    return weeks
Ejemplo n.º 10
0
def generate_top_2_playoffs(first_playoff_week: int) -> ScheduleWeek:
    championship_week = ScheduleWeek(week_number=first_playoff_week,
                                     week_type=WeekType.CHAMPIONSHIP)
    championship_week.matchups.append(Matchup(type=MatchupType.CHAMPIONSHIP))

    return championship_week