Пример #1
0
    def create_games(self,
                     team_list,
                     year,
                     start_day,
                     rules,
                     rounds,
                     home_and_away,
                     session=None):
        if session is None:
            session = self.repo.get_session()

        scheduler = Scheduler()
        team_ids = [i.oid for i in team_list]

        schedule_games = []
        # schedule_games = scheduler.schedule_games(team_ids, rules.oid, year, start_day, home_and_away)
        for i in range(rounds):
            schedule_games.extend(
                scheduler.schedule_games(team_ids, rules.oid, year, start_day,
                                         home_and_away))
            start_day = max([sg.day for sg in schedule_games])
            start_day += 1

        new_games = [
            self.create_game_from_schedule_game(sg, session)
            for sg in schedule_games
        ]
        [self.repo.add(g, session) for g in new_games]

        session.commit()
Пример #2
0
def create_games(groups, rounds, rules, create_game_method, day_dict):
    for cg in groups:
        cg_teams = [r.team for r in cg.rankings]
        for i in range(rounds):
            next_games = scheduler.schedule_games(cg_teams, rules, 1, 1, True,
                                                  create_game_method)
            new_days = Scheduler.organize_games_into_days(next_games)
            for new_day in new_days.keys():
                Scheduler.add_day_to_scheduler(new_days[new_day], day_dict, 1)
Пример #3
0
    def test_does_team_play_in_game(self):
        team1 = Team("Team 1", 5, True)
        team2 = Team("Team 2", 5, True)
        team3 = Team("Team 3", 5, True)

        game = Game(1, 1, team2, team3, 0, 0, False, False, None)

        self.assertTrue(Scheduler.does_team_play_in_game(game, team2))
        self.assertTrue(Scheduler.does_team_play_in_game(game, team3))
        self.assertFalse(Scheduler.does_team_play_in_game(game, team1))
Пример #4
0
    def test_schedule_games(self):
        scheduler = Scheduler()
        result = scheduler.schedule_games(
            ["team 1", "team 2", "team 3", "team 4", "team 5"], "55", 25, 1,
            False)
        print()
        print("Game List")
        for x in result:
            print(str(x.day) + ": " + x.home_team + " vs " + x.away_team)

        print("Total Games: " + str(len(result)))
Пример #5
0
    def test_does_team_play_in_games_list(self):
        team1 = Team("Team 1", 5, False)
        team2 = Team("Team 2", 5, False)
        team3 = Team("Team 3", 5, False)
        team4 = Team("Team 4", 5, False)

        game1 = Game(1, 1, team1, team2, 0, 0, False, False, None)
        game2 = Game(1, 1, team3, team4, 0, 0, False, False, None)

        game_list_1 = [game1, game2]
        game_list_2 = [game2]

        self.assertTrue(
            Scheduler.does_team_play_in_games_list(game_list_1, team1))
        self.assertTrue(
            Scheduler.does_team_play_in_games_list(game_list_1, team2))
        self.assertTrue(
            Scheduler.does_team_play_in_games_list(game_list_1, team3))
        self.assertTrue(
            Scheduler.does_team_play_in_games_list(game_list_1, team4))

        self.assertFalse(
            Scheduler.does_team_play_in_games_list(game_list_2, team1))
        self.assertFalse(
            Scheduler.does_team_play_in_games_list(game_list_2, team2))
        self.assertTrue(
            Scheduler.does_team_play_in_games_list(game_list_2, team3))
        self.assertTrue(
            Scheduler.does_team_play_in_games_list(game_list_2, team4))
Пример #6
0
    def test_does_any_team_play_in_other_list(self):
        team1 = Team("Team 1", 5, False)
        team2 = Team("Team 2", 5, False)
        team3 = Team("Team 3", 5, False)
        team4 = Team("Team 4", 5, False)
        team5 = Team("Team 5", 5, False)
        team6 = Team("Team 6", 5, False)
        team7 = Team("Team 6", 5, False)
        team8 = Team("Team 6", 5, False)

        game1 = Game(1, 1, team1, team2, 0, 0, False, False, None)
        game2 = Game(1, 1, team3, team4, 0, 0, False, False, None)
        game3 = Game(1, 1, team5, team6, 0, 0, False, False, None)

        game4 = Game(1, 1, team1, team3, 0, 0, False, False, None)
        game5 = Game(1, 1, team2, team5, 0, 0, False, False, None)
        game6 = Game(1, 1, team4, team6, 0, 0, False, False, None)

        game7 = Game(1, 1, team7, team8, 0, 0, False, False, None)

        game_list_1 = [game1, game2, game3]
        game_list_2 = [game2, game3, game4]
        game_list_3 = [game1, game2]
        game_list_4 = [game6]

        game_list_5 = [game1, game2]
        game_list_6 = [game3, game7]

        # all teams play in all other games
        self.assertTrue(
            Scheduler.does_any_team_play_in_other_list(game_list_1,
                                                       game_list_2))

        # only one home team plays in other day
        self.assertTrue(
            Scheduler.does_any_team_play_in_other_list(game_list_4,
                                                       game_list_3))

        # no teams play
        self.assertFalse(
            Scheduler.does_any_team_play_in_other_list(game_list_5,
                                                       game_list_6))
Пример #7
0
    def test_setup_matrix_even(self):
        scheduler = Scheduler()
        scheduler.total_teams = 6
        scheduler.setup()
        scheduler.pairs = 3
        scheduler.odd = False

        self.assertEqual(0, scheduler.anchor)

        assert [1, 2, 3, 4, 5] == scheduler.num_list
Пример #8
0
    def test_setup_matrix_odd(self):
        scheduler = Scheduler()
        scheduler.total_teams = 5
        scheduler.setup()
        scheduler.pairs = 3
        scheduler.odd = True

        self.assertEqual(-1, scheduler.anchor)

        assert [0, 1, 2, 3, 4] == scheduler.num_list
Пример #9
0
    def test_incrementer_odd(self):
        scheduler = Scheduler()
        scheduler.total_teams = 5
        scheduler.setup()

        scheduler.populate_matrix()
        assert [[-1, 0], [1, 4], [2, 3]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[-1, 1], [2, 0], [3, 4]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[-1, 2], [3, 1], [4, 0]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[-1, 3], [4, 2], [0, 1]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[-1, 4], [0, 3], [1, 2]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[-1, 0], [1, 4], [2, 3]] == scheduler.matrix
Пример #10
0
    def test_incrementer_even(self):
        scheduler = Scheduler()
        scheduler.total_teams = 6
        scheduler.setup()

        scheduler.populate_matrix()
        assert [[0, 1], [2, 5], [3, 4]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[0, 2], [3, 1], [4, 5]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[0, 3], [4, 2], [5, 1]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[0, 4], [5, 3], [1, 2]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[0, 5], [1, 4], [2, 3]] == scheduler.matrix

        scheduler.populate_matrix()
        assert [[0, 1], [2, 5], [3, 4]] == scheduler.matrix
for league_rank in league.rankings:
    print(f'{league_rank.rank}. {league_rank.team.name}')

current_day = 1
days = {}
games = []
#  setup first round of playoff
while not playoff.is_complete():
    print(f'Current Round: {playoff.current_round}')
    while not playoff.is_round_complete(playoff.current_round):
        if not playoff.is_round_setup(playoff.current_round):
            playoff.setup_round(playoff.current_round)
        # print(loop)
        new_games = playoff.create_new_games(games)
        Scheduler.add_games_to_schedule(new_games, days, r, current_day)
        games.extend(new_games)
        for g in days[current_day]:
            g.play(r)
            model = GameService.game_to_vm(g)
            competition.process_game(g)
            # print(GameView.get_basic_view(model))
        game_day_view_model = GameService.games_to_game_day_view(
            days[current_day])
        #print(GameDayView.get_view(game_day_view_model))
        current_day += 1

    for s in [
            ps for ps in playoff.series
            if ps.series_round == playoff.current_round
    ]:
Пример #12
0
canadian_league_name = "Canadian League"
american_league_name = "American League"
playoff_name = "Playoff"

competition_config = setup_config(rand, canadian_league_name,
                                  american_league_name, playoff_name,
                                  season_game_rules, playoff_game_rules)

competition = CompetitionConfigurator.setup_competition(competition_config, 1)
canadian_table = competition.get_sub_competition(canadian_league_name)
american_table = competition.get_sub_competition(american_league_name)

playoff = competition.get_sub_competition(playoff_name)

#  schedule the games, need to move this to the configuration when the season is setup
scheduler = Scheduler()
days = {}

level_1_rounds = 1
level_2_rounds = 5

create_games(canadian_table.get_groups_by_level(1), 2, season_game_rules,
             canadian_table.create_game, days)
create_games(american_table.get_groups_by_level(1), 6, season_game_rules,
             american_table.create_game, days)
create_games(canadian_table.get_groups_by_level(2), 4, season_game_rules,
             canadian_table.create_game, days)

last_day = -1

for d in days.keys():