Last active
November 21, 2016 21:38
-
-
Save mitchellbusby/4dfdd125e5df1b11a486c47d76b8f70f to your computer and use it in GitHub Desktop.
go self yourself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv # for reading data from CSV files | |
homeGoalsRecord = 0 | |
awayGoalsRecord = [] | |
""" | |
Team class | |
Example usage: | |
#Create a new team | |
homeTeam = new Team("home") | |
#Record a win | |
homeTeam.record_win("", 5) | |
>> 5 is the record | |
""" | |
class Team(): | |
homeGoalsRecord = 0 | |
def __init__(team, name): | |
team.name = name | |
def record_win(team, side, homeGoals): | |
if side.lower() in self.name: | |
team.homeGoalsRecord = homeGoals | |
print("{} is the record".format(team.homeGoalsRecord)) | |
#def recordWin(self, side, homeGoals): | |
# if side.capitalize().__contains__('HOME'): | |
# self.homeGoalsRecord += homeGoals | |
# print(self.homeGoalsRecord) | |
with open('eplresults.csv', newline='') as results: | |
allResultsWithHeaders = csv.reader(results, delimiter=',') | |
skipHeaders = 'true' | |
winner = [] | |
awayWins = 0 | |
homeWins = 0 | |
tieWins = 0 | |
# Create your team objects out here | |
for result in allResultsWithHeaders: | |
if skipHeaders: | |
skipHeaders = False | |
continue | |
score = result[4] | |
# need to strip the leading and trailing spaces from the data | |
homeGoals = str(score.split(':')[0]) | |
homeGoals = homeGoals[:-1] | |
awayGoals = str(score.split(':')[1]) | |
awayGoals = awayGoals[1:] | |
if homeGoals > awayGoals: | |
winner.append("HOME") | |
homeWins += 1 | |
recordWin("home", homeGoals) | |
elif awayGoals > homeGoals: | |
winner.append("AWAY") | |
awayWins += 1 | |
else: | |
winner.append("TIE") | |
tieWins += 1 | |
if homeWins > awayWins: | |
totalBias = homeWins - awayWins | |
totalBiasPerCent = (totalBias / (homeWins + awayWins)) * 100 | |
print('Home teams win more than away teams by ' + str(totalBiasPerCent) + ' %') | |
if awayWins > homeWins: | |
totalBias = awayWins - homeWins | |
totalBiasPerCent = (totalBias / (homeWins + awayWins)) * 100 | |
print('Away teams win more than home teams by ' + str(totalBiasPerCent) + ' %') | |
if awayWins == homeWins: | |
print('There is no advantage between teams playing at home and teams playing away') | |
print('Home:', homeWins) | |
print('Away:', awayWins) | |
print('Tie:', tieWins) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment