def test_GetPreviousResults_1(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values1 = ["E0","26/03/08","Bohs","Rowfus","2","1","H","0","1","H","1","1","4","1","1.1","1.2"] values2 = ["E0","27/03/08","Bohs","Rowfus","2","1","H","1","1","H","1","1","1","1","1.1","1.2"] values3 = ["E0","28/03/08","Bohs","Rowfus","2","1","H","1","1","D","1","1","1","1","1.1","1.2"] fixture1 = Fixture(header, values1) fixture2 = Fixture(header, values2) fixture3 = Fixture(header, values3) team = Team("Rowfus") team.addFixture(fixture1) team.addFixture(fixture2) team.addFixture(fixture3) results = team.getPreviousResults() result = True for testResult in results: if testResult != 'L': result = False break if len(results) != 3: result = False self.assertTrue(result)
def test_Team_1(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","26/03/08","Bohs","Rowfus","4","1","H","3","1","H","4","4","10","5","1.1","1.2"] fixture1 = Fixture(header, values) header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","27/03/08","Bohs","Rowfus","5","2","H","3","1","H","4","4","10","5","1.1","1.2"] fixture2 = Fixture(header, values) header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","28/03/08","Bohs","Rowfus","3","1","H","1","1","D","4","4","10","5","1.1","1.2"] fixture3 = Fixture(header, values) header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","28/03/08","Bohs","Rowfus","3","1","H","2","1","H","4","4","10","5","1.1","1.2"] fixture4 = Fixture(header, values) team = Team("Bohs") team.addFixture(fixture1) team.addFixture(fixture2) team.addFixture(fixture3) team.addFixture(fixture4) self.assertEquals(team.getProbWin(), 1.0)
def test_GetPreviousLosses_1(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values1 = ["E0","28/03/08","Bohs","Rowfus","2","1","H","1","1","D","1","1","1","1","1.1","1.2"] fixture1 = Fixture(header, values1) team = Team("Rowfus") team.addFixture(fixture1) result = team.getPreviousLosses(1) self.assertEquals(result, 1)
def test_GetForm_2(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] win = ["E0","26/03/08","Bohs","Rowfus","2","1","H","0","0","H","1","1","4","1","1.1","1.2"] loss = ["E0","26/03/08","Bohs","St. Pauli","0","3","H","0","1","H","1","1","4","1","1.1","1.2"] team = Team("Bohs") for x in xrange(0, 20): fixture = Fixture(header, loss) team.addFixture(fixture) result = team.getForm(5) self.assertTrue(result >= 0.0 and result < 0.0001)
def test_GetForm_4(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] win = ["E0","26/03/08","Bohs","Rowfus","2","1","H","0","0","H","1","1","4","1","1.1","1.2"] loss = ["E0","26/03/08","Bohs","St. Pauli","0","3","H","0","1","H","1","1","4","1","1.1","1.2"] team = Team("Bohs") fixture1 = Fixture(header, win) fixture2 = Fixture(header, loss) team.addFixture(fixture2) team.addFixture(fixture1) result = team.getForm(5) self.assertEquals(result, 0.0)
def addFixture(self, fixture): """ Adds a single fixture to the league and updates all the team-specific features. """ self.numGames += 1 self.fixtures.append(fixture) homeTeam = fixture.getHomeTeam() awayTeam = fixture.getAwayTeam() # Update the home team if homeTeam not in self.teamNames: self.teamNames.append(homeTeam) team = Team(homeTeam) team.addFixture(fixture) self.leagueTable.append(team) else: teamIndex = -1 for x in xrange(0, len(self.leagueTable)): if self.leagueTable[x].getTeamName() == homeTeam: teamIndex = x break self.leagueTable[teamIndex].addFixture(fixture) # Update the away team if awayTeam not in self.teamNames: self.teamNames.append(awayTeam) team = Team(awayTeam) team.addFixture(fixture) self.leagueTable.append(team) else: teamIndex = -1 for x in xrange(0, len(self.leagueTable)): if self.leagueTable[x].getTeamName() == awayTeam: teamIndex = x break self.leagueTable[teamIndex].addFixture(fixture) # Rank the league self.leagueTable.sort(key=lambda team: team.getGoalDiff(), reverse=True) self.leagueTable.sort(key=lambda team: team.getPoints(), reverse=True) # Only update the k-means and eigenvalue after # a minimum number of games have been played. if self.getGamesPlayed() >= self.minGames: self.kMeansCluster() self.setEigenValues(fixture, updateOnly=False) else: self.setEigenValues(updateOnly=True)
def test_GetPreviousWins_3(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values1 = ["E0","26/03/08","Bohs","Rowfus","2","1","H","0","1","H","1","1","4","1","1.1","1.2"] values2 = ["E0","27/03/08","Bohs","Rowfus","2","2","H","1","1","H","1","1","1","1","1.1","1.2"] values3 = ["E0","28/03/08","Bohs","Rowfus","2","2","H","1","1","D","1","1","1","1","1.1","1.2"] fixture1 = Fixture(header, values1) fixture2 = Fixture(header, values2) fixture3 = Fixture(header, values3) team = Team("Bohs") team.addFixture(fixture1) team.addFixture(fixture2) team.addFixture(fixture3) result = team.getPreviousWins(3) self.assertEquals(result, 1)
def test_GetShots_3(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","26/03/08","Bohs","Rowfus","4","1","H","3","1","H","1","1","4","1","1.1","1.2"] fixture1 = Fixture(header, values) header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","27/03/08","Bohs","Rowfus","5","2","H","3","1","H","1","1","1","1","1.1","1.2"] fixture2 = Fixture(header, values) header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] values = ["E0","28/03/08","Bohs","Rowfus","2","1","H","1","1","D","1","1","1","1","1.1","1.2"] fixture3 = Fixture(header, values) team = Team("Rowfus") team.addFixture(fixture1) team.addFixture(fixture2) team.addFixture(fixture3) total = fixture1.getHomeShots() total += fixture2.getHomeShots() total += fixture3.getHomeShots() self.assertEquals(total, 6)
def test_RecentGA_1(self): header = ["Div","Date","HomeTeam","AwayTeam","FTHG","FTAG","FTR","HTHG","HTAG","HTR","HST","AST","HS","AS","WHH","B365A"] win = ["E0","26/03/08","Bohs","Rowfus","2","1","H","0","0","H","1","1","4","1","1.1","1.2"] loss = ["E0","26/03/08","Bohs","St. Pauli","0","3","H","0","1","H","1","1","4","1","1.1","1.2"] fixture1 = Fixture(header, loss) fixture2 = Fixture(header, loss) fixture3 = Fixture(header, loss) fixture4 = Fixture(header, loss) fixture5 = Fixture(header, win) fixture6 = Fixture(header, win) fixture7 = Fixture(header, loss) team = Team("Bohs") team.addFixture(fixture1) team.addFixture(fixture2) team.addFixture(fixture3) team.addFixture(fixture4) team.addFixture(fixture5) team.addFixture(fixture6) team.addFixture(fixture7) result = team.getRecentGA() self.assertEquals(result, 11)