Beispiel #1
0
    def create_default_playoff(groups):
        competition = create_default_competition_for_testing("My Comp")
        playoff = PlayoffSubCompetition("Playoff", [], competition, None, 1, 1, False, False, False, False)
        competition.sub_competitions.append(playoff)

        league = CompetitionGroup("League", None, None, 1, [], CompetitionGroupConfiguration.RANKING_TYPE)
        r1_winners_group = CompetitionGroup("R1 Winners", None, 1, playoff, [], CompetitionGroupConfiguration.RANKING_TYPE)
        r1_losers_group = CompetitionGroup("R1 Losers", None, 1, playoff, [], CompetitionGroupConfiguration.RANKING_TYPE)
        r2_winners_group = CompetitionGroup("R2 Winners", None, 1, playoff, [], CompetitionGroupConfiguration.RANKING_TYPE)
        r2_losers_group = CompetitionGroup("R2 Losers", None, 1, playoff, [], CompetitionGroupConfiguration.RANKING_TYPE)
        eliminated = CompetitionGroup("Eliminated Group", None, 1, playoff, [], CompetitionGroupConfiguration.RANKING_TYPE)

        league.rankings = [
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 1", 5), 1),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 2", 5), 2),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 3", 5), 3),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 4", 5), 4),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 5", 5), 5),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 6", 5), 6),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 7", 5), 7),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 8", 5), 8),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 9", 5), 9),
            CompetitionRanking(league, helpers.new_comp_team(competition, "Team 10", 5), 10),
        ]

        groups.extend([league, r1_winners_group, r1_losers_group, r2_winners_group, r2_losers_group, eliminated])

        game_rules_tie = GameRules("Can Tie", True)
        game_rules_no_tie = GameRules("No Tie", False)

        series_rules_by_goals_2 = SeriesByGoalsRules("By Goals 2 Games", 2, game_rules_tie, game_rules_no_tie, None)
        series_rules_by_goals_3 = SeriesByGoalsRules("By Goals 3 Games", 3, game_rules_tie, game_rules_no_tie, None)
        series_rules_by_goals_1 = SeriesByGoalsRules("By Goals 1 Games", 1, game_rules_tie, game_rules_no_tie, None)
        series_rules_wins_4 = SeriesByWinsRules("4 wins", 4, game_rules_no_tie, [0, 0, 1, 1, 0, 1, 0])

        series1 = SeriesByGoals(playoff, "Series 1", 1, None, None, 0, 0, 0, series_rules_by_goals_2,
                                league, 1, league, 8, r1_winners_group, league, r1_losers_group, league, False, False)

        series2 = SeriesByGoals(playoff, "Series 2", 1, None, None, 0, 0, 0, series_rules_by_goals_3,
                                league, 2, league, 7, r1_winners_group, league, r1_losers_group, league, False, False)

        series3 = SeriesByGoals(playoff, "Series 3", 1, None, None, 0, 0, 0, series_rules_by_goals_1,
                                league, 3, league, 6, r1_winners_group, league, r1_losers_group, league, False, False)

        series4 = SeriesByWins(playoff, "Series 4", 1, None, None, 0, 0, series_rules_wins_4,
                               league, 4, league, 5, r1_winners_group, league, r1_losers_group, league, False, False)

        series5 = SeriesByWins(playoff, "Series 5", 2, None, None, 0, 0, series_rules_wins_4,
                               r1_winners_group, 1, r1_winners_group, 4, r2_winners_group, league, r2_losers_group, league, False, False)

        series6 = SeriesByGoals(playoff, "Series 6", 2, None, None, 0, 0, 0, series_rules_by_goals_1,
                                r1_winners_group, 2, r1_winners_group, 3, r2_winners_group, league, r2_losers_group, league, False, False)

        series7 = SeriesByGoals(playoff, "Series 7", 2, None, None, 0, 0, 0, series_rules_by_goals_1,
                                r1_losers_group, 1, league, 2, r1_losers_group, eliminated, league, eliminated, league, False, False)

        playoff.series.extend([series1, series2, series3, series4, series5, series6, series7])

        return playoff
Beispiel #2
0
    def test_stats(self):
        t1_skill = 10
        t2_skill = 0
        team1 = Team("T1", t1_skill, True, "1")
        team2 = Team("T2", t2_skill, True, "2")

        record1 = Record(1, team1, 1, 0, 0, 0, 0, 0, 0, "3")
        record2 = Record(1, team2, 1, 0, 0, 0, 0, 0, 0, "3")

        rules = GameRules("Rules", True, "4")

        for i in range(1000):
            game = Game(1, 1, team1, team2, 0, 0, False, False, rules, str(i))
            game.play()
            record1.process_game(game.home_score, game.away_score)
            record2.process_game(game.away_score, game.home_score)

        print()
        print("Results")
        print(RecordView.get_table_header())
        print(
            RecordView.get_table_row(
                RecordService.get_view_from_model(record1)))
        print(
            RecordView.get_table_row(
                RecordService.get_view_from_model(record2)))
Beispiel #3
0
    def test_play(self):
        game = Game(5, 25, Team("T1", 5, True, "1"), Team("T1", 4, True, "2"),
                    0, 0, False, False, GameRules("Rules", True, ""), "")

        np.random.seed = 1235
        game.play()

        self.assertTrue(game.complete)
 def get_updated_record(self, original_record):
     original_record.day = 10
     original_record.year = 20
     original_record.home_team = TeamDTO(Team("New Home TEam", 249, False))
     original_record.away_team = TeamDTO(Team("New Away TEam", 244, True))
     original_record.home_score = 30
     original_record.away_score = 30
     original_record.complete = True
     original_record.processed = False
     original_record.rules = GameRulesDTO(GameRules("Rules Name 2", False))
     return original_record
    def test_get_pattern_properly(self):
        session = self.setup_basic_test()
        rules = SeriesRules("Test", GameRules("Rules", True), SeriesRules.WINS_TYPE, [1, 5, 6, 7])
        self.get_repo().add(SeriesRulesDTO(rules), session)
        session.commit()

        retrieved_object = self.get_repo().get_by_oid(rules.oid, session)

        self.assertEqual(1, retrieved_object.home_pattern[0])
        self.assertEqual(5, retrieved_object.home_pattern[1])
        self.assertEqual(6, retrieved_object.home_pattern[2])
        self.assertEqual(7, retrieved_object.home_pattern[3])
 def get_updated_record(self, original_record):
     original_record.day = 10
     original_record.year = 20
     original_record.home_team = TeamDTO(Team("New Home TEam", 249, False))
     original_record.away_team = TeamDTO(Team("New Away TEam", 244, True))
     original_record.home_score = 30
     original_record.away_score = 30
     original_record.complete = True
     original_record.processed = False
     original_record.rules = GameRulesDTO(GameRules("Rules Name 2", False))
     original_record.competition = CompetitionDTO(Competition("Test 2", 5, None, None, 1, False, True, True, False))
     original_record.sub_competition = TableSubCompetitionDTO(TableSubCompetition("Sub Comp", None, original_record.competition, None, 1, True, True, False, False))
     return original_record
Beispiel #7
0
    def setup_default_series(games):
        home_team = Team("Team 1", 5, True)
        away_team = Team("Team 2", 5, True)

        competition = create_default_competition_for_testing("My Comp")
        sub_competition = PlayoffSubCompetition("Playoff A", None, competition,
                                                None, 1, 1, True, True, False,
                                                False)

        home_competition_team = CompetitionTeam(competition, home_team)
        away_competition_team = CompetitionTeam(competition, away_team)

        game_rules = GameRules("A", True)
        last_game_rules = GameRules("B", False)

        series_rules = SeriesByGoalsRules("My Rules", games, game_rules,
                                          last_game_rules, None)

        series = SeriesByGoals(sub_competition, "My Series", 1,
                               home_competition_team, away_competition_team, 0,
                               0, 0, series_rules, None, None, None, None,
                               None, None, None, None, True, False)

        return series
    def test_add_no_existing_teams(self):
        session = self.setup_basic_test()

        name_1 = "Team GA1"
        name_2 = "Team GA2"

        team_1 = Team(name_1, 12, True, self.get_id())
        team_2 = Team(name_2, 12, True, self.get_id())

        self.get_repo().add(Game(1, 15, team_1, team_2, 5, 4, True, False, GameRules("Rules", True, self.get_id()),
                                 self.get_id()), session)
        session.commit()

        g_list = self.get_repo().get_all(session)
        self.assertEqual(1, len(g_list))
    def test_get_first_day_for_game(self):
        session = self.setup_basic_test()
        Database.clean_up_database(session)
        team_repo = TeamRepository()
        rules_repo = GameRulesRepository()

        team1 = Team("t1", 5, True, "A")
        team2 = Team("t2", 5, True, "B")
        team3 = Team("t3", 5, True, "C")
        team4 = Team("t4", 5, True, "D")

        new_teams = [team1, team2, team3, team4]
        [team_repo.add(team, session) for team in new_teams]

        new_gr = GameRules("Rules 12", True, "T")
        rules_repo.add(new_gr, session)
        session.commit()

        gr = rules_repo.get_by_name("Rules 12", session)

        teams = team_repo.get_all(session)

        game1 = Game(1, 5, teams[0], teams[1], 0, 1, True, True, gr, "K")

        games = [game1]

        [self.get_repo().add(game, session) for game in games]

        session.commit()
        # first test, should be none because teams[0] plays on day 5
        game2 = GameDTO(Game(1, -1, teams[0], teams[2], 0, 1, True, True, gr, "L"))
        result = self.get_repo().get_list_days_teams_play_on(1, 1, 100, game2, session)

        self.assertEquals(5, result[0])

        game2.day = 1
        self.get_repo().add(game2, session)
        session.commit()

        result = self.get_repo().get_list_days_teams_play_on(1, 1, 100, game2, session)
        print(result)
    def test_get_my_complete_and_unprocessed(self):
        session = self.setup_basic_test()
        Database.clean_up_database(session)
        team_repo = TeamRepository()
        rules_repo = GameRulesRepository()

        team1 = Team("t1", 5, True, "A")
        team2 = Team("t2", 5, True, "B")
        team_repo.add(team1, session)
        team_repo.add(team2, session)
        gr = GameRules("Rules 12", True, "T")
        rules_repo.add(gr, session)
        session.commit()

        team1 = team_repo.get_by_name("t1", session)
        team2 = team_repo.get_by_name("t2", session)
        gr = rules_repo.get_by_name("Rules 12", session)

        game1 = Game(1, 1, team1, team2, 0, 0, True, False, gr, "1")
        game2 = Game(1, 1, team1, team2, 0, 0, False, False, gr, "2")
        game3 = Game(1, 2, team1, team2, 0, 0, False, False, gr, "3")
        game4 = Game(1, 2, team1, team2, 0, 0, False, False, gr, "4")
        game5 = Game(1, 3, team1, team2, 0, 0, True, False, gr, "5")
        game6 = Game(1, 3, team1, team2, 0, 0, False, False, gr, "6")
        game7 = Game(1, 4, team1, team2, 0, 0, True, False, gr, "7")
        game8 = Game(2, 1, team1, team2, 0, 0, True, False, gr, "8")

        games = [game1, game2, game3, game4, game5, game6, game7, game8]

        [self.get_repo().add(g, session) for g in games]

        session.commit()

        result = list(self.get_repo().get_by_unprocessed_and_complete(1, 1, 4, session))
        self.assertEqual(3, len(result))

        result = list(self.get_repo().get_by_unprocessed_and_complete(1, 1, 2, session))
        self.assertEqual(1, len(result))

        result = list(self.get_repo().get_by_unprocessed_and_complete(2, 1, 25, session))
        self.assertEqual(1, len(result))
Beispiel #11
0
from teams.domain.game import GameRules
from teams.domain.series import SeriesByWins
from teams.domain.series_rules import SeriesByWinsRules
from teams.domain.sub_competition import PlayoffSubCompetition
from teams.domain.team import Team

home_team = Team("Team 1", 5, True)
away_team = Team("Team 2", 5, True)

competition = Competition("My Comp", 1, None, None, True, True, False, False)
sub_competition = PlayoffSubCompetition("Playoff A", None, competition, 1, 1, True, True, False, False)

home_competition_team = CompetitionTeam(competition, home_team)
away_competition_team = CompetitionTeam(competition, away_team)

game_rules = GameRules("Playoff", False)

series_rules = SeriesByWinsRules("My Rules", 4, game_rules, [0, 0, 1, 1, 0, 1, 0])

series = SeriesByWins(sub_competition, "My Series", 1, home_competition_team, away_competition_team,
                      0, 0, series_rules, None, None, None, None, None, None, None, None,
                      True, False)

games = []

print(series.name)
while not series.is_complete():
    complete_games = [g for g in games if g.complete and g.processed]
    incomplete_games = [g for g in games if not g.complete]

    games.extend(series.get_new_games(len(complete_games), len(incomplete_games)))
 def get_add_record(self):
     return GameDTO(Game(1, 2,
                         TeamDTO(Team("Home team", 250, True)),
                         TeamDTO(Team("Away Team", 251, False)),
                         3, 4, False, True, GameRulesDTO(GameRules("Rules Name", False))))
from teams.ConsoleUI.views.playoff_views import SeriesView
from teams.domain.comp_configorator import CompetitionConfigurator
from teams.domain.competition_configuration import CompetitionConfiguration, RankingGroupConfiguration, \
    SeriesConfiguration, PlayoffSubCompetitionConfiguration, CompetitionTeamConfiguration
from teams.domain.game import GameRules
from teams.domain.scheduler import Scheduler
from teams.domain.series import SeriesByGoals, SeriesByWins
from teams.domain.series_rules import SeriesByWinsRules
from teams.services.game_service import GameService
from teams.services.view_models.playoff_view_models import SeriesViewModel
from teams.services.view_models.team_view_models import TeamViewModel
from tests.teams.domain.competition.testing_sample_data import western_teams, eastern_teams, pacific_teams, teams, \
    central_teams, atlantic_teams, north_teams

playoff_game_rules = GameRules("Playoff Rules", False)
series_rules = SeriesByWinsRules("Best of 7", 4, playoff_game_rules,
                                 [0, 0, 1, 1, 0, 1, 0])
series_rules_3 = SeriesByWinsRules("Best of 3", 2, playoff_game_rules,
                                   [0, 0, 1])

competition_config = CompetitionConfiguration("Playoff Test", [], [], 1, 1,
                                              None)

playoff_config = PlayoffSubCompetitionConfiguration("Playoff",
                                                    competition_config, [], [],
                                                    [], 1, 1, None)
competition_config.sub_competitions.append(playoff_config)

team_configs = []
# seeding group
Beispiel #14
0
from teams.domain.series import SeriesByGoals
from teams.domain.series_rules import SeriesByGoalsRules
from teams.domain.sub_competition import PlayoffSubCompetition
from teams.domain.team import Team

home_team = Team("Team 1", 5, True)
away_team = Team("Team 2", 5, True)

competition = Competition("My Comp", 1, None, None, True, True, False, False)
sub_competition = PlayoffSubCompetition("Playoff A", None, competition, 1, 1,
                                        True, True, False, False)

home_competition_team = CompetitionTeam(competition, home_team)
away_competition_team = CompetitionTeam(competition, away_team)

game_rules = GameRules("Playoff", True)
last_game_rules = GameRules("Last Game", False)

series_rules = SeriesByGoalsRules("My Rules", 2, game_rules, last_game_rules,
                                  None)

series = SeriesByGoals(sub_competition, "My Series", 1, home_competition_team,
                       away_competition_team, 0, 0, 0, series_rules, None,
                       None, None, None, None, None, None, None, True, False)

games = []

print(series.name)
while not series.is_complete():
    complete_games = [g for g in games if g.complete and g.processed]
    incomplete_games = [g for g in games if not g.complete]
    def test_add(self):
        session = self.setup_basic_test()
        self.get_repo().add(GameRules("My Name", False, self.get_id()), session)
        session.commit()

        self.assertEqual(1, len(self.get_repo().get_all(session)))
 def get_add_record(self):
     return SeriesRulesDTO(SeriesRules("Test Rule", GameRules("My Rules", False), SeriesRules.WINS_TYPE, []))
    def get_updated_record(self, original_record):
        original_record.name = "New Name"
        original_record.game_rules = GameRulesDTO(GameRules("Updated Rules", False))
        original_record.home_pattern = [1, 2, 3, 5]

        return original_record
Beispiel #18
0
 def __init__(self, game_rules):
     GameRules.__init__(self, game_rules.name, game_rules.can_tie,
                        game_rules.oid)
Beispiel #19
0
 def create(self, name, can_tie, session=None):
     if session is None:
         session = self.repo.get_session()
     self.repo.add(GameRules(name, can_tie, self.get_new_id()), session)
     session.commit()
Beispiel #20
0
                                None)

    # misc
    can_am = SeriesConfiguration("CanAm", 3, playoff_config, canadian_config,
                                 8, american_rep, 1, series_rules_2,
                                 can_am_winners, None, None, None, 1, None)

    series_config = [r1s1, r1s2, r1s3, final, can_am]

    playoff_config.series = series_config
    # configuration done

    return competition_config


season_game_rules = GameRules("Season Rules", True)
playoff_game_rules = GameRules("Playoff Rules", False)

rand = random
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)
 def get_add_record(self):
     return GameRulesDTO(GameRules("Rules Name", False))