import numpy as np
data = open('PremierLeague2011.txt')
teams = ('Aston Villa','Arsenal ','Blackburn','Bolton ','Chelsea ','Everton ','Fulham ','Liverpool','Man City','Man United','Newcastle','Norwich ','QPR ','Stoke ','Sunderland','Swansea ','Tottenham','West Brom','Wigan ','Wolves ')
points = [0] * 20
matchesplayed = [0] * 20
goalsfor = [0] * 20
goalsagainst = [0] * 20
matcheswon = [0] * 20
matchesdrawn = [0] * 20
matcheslost = [0] * 20
Titles = ('Team ','PL', 'W','D','L','GF','GA','POINTS')
class PremierLeagueTeam(object):
def __init__(self, Date, code_H, code_A, Scored, Conceded, Result):
self.date = Date
self.codeH = code_H
self.codeA = code_A
self.scored = Scored
self.conceded = Conceded
self.result = Result
def tot_points(self):
if (self.result == 'H'):
points[int(self.codeH)] += 3
if (self.result == 'A'):
points[int(self.codeA)] += 3
if (self.result == 'D'):
points[int(self.codeA)] += 1
points[int(self.codeH)] += 1
def matches(self):
matchesplayed[int(self.codeH)] += 1
matchesplayed[int(self.codeA)] += 1
def goals(self):
goalsfor[int(self.codeH)] += self.scored
goalsagainst[int(self.codeH)] += self.conceded
goalsfor[int(self.codeA)] += self.conceded
goalsagainst[int(self.codeA)] += self.scored
def WDL(self):
if (self.result == 'H'):
matcheswon[int(self.codeH)] += 1
matcheslost[int(self.codeA)] += 1
if (self.result == 'A'):
matcheswon[int(self.codeA)] += 1
matcheslost[int(self.codeH)] += 1
if (self.result == 'D'):
matchesdrawn[int(self.codeH)] += 1
matchesdrawn[int(self.codeA)] += 1
for line in data:
F = []
line = line.split()
for i in line:
if i == line[0] or i == line[5]:
i = i
F.append(i)
else:
i = float(i)
F.append(i)
A = PremierLeagueTeam(F[0],F[1],F[2],F[3],F[4],F[5])
PremierLeagueTeam.tot_points(A)
PremierLeagueTeam.matches(A)
PremierLeagueTeam.goals(A)
PremierLeagueTeam.WDL(A)
zipped = zip( teams, matchesplayed, matcheswon, matchesdrawn, matcheslost, goalsfor, goalsagainst, points)
sortedlist = sorted(zipped, key = lambda x: x[7], reverse = True)
print (*Titles, sep='\t')
for a in sortedlist:
print(*a, sep='\t')