#Sean Merz #Things to include: # o Match History vs All vs Players # o Personal Bests # o Achievements # o Losses in a row # o How much ELO won/lost today # o Games in first place # o First place changes # o How many times player has been shut out # o Record in 5v4 HighestELORecord=0 WinStreak=[0,''] NewRecords=[] PlayerSet=[] MatchCount=0 EloSwap=0.0 BiggestUpsets=[] LastPointDifferentials=[] GoalsScored=0 class Player: def __init__(self,stringname,extrachar=0): PlayerSet.append(self) self.name=stringname self.name_14_char=self.name+' '*(14-len(self.name)+extrachar)+':' self.ELO=1500.0 self.formerELO=1500.0 self.MaxELO=1500.0 self.MinELO=1500.0 self.TotalELO=1500.0 self.games=0.0 self.wins=0.0 self.losses=0.0 self.winpercentage=0.0 self.record='' self.streak=0 self.upsets=0 self.upsetted=0 self.points=0.0 self.ppg=0.0 self.allscores=[] self.lastgame=0.0 self.shutouts='-' self.shutouted='-' self.matchhistory=[] def setpoints(self,pts,result): global NewRecords self.points+=pts self.setppg() self.allscores.append(pts) self.lastgame=pts def setppg(self): self.ppg=self.points/self.games def setELO(self,newELO): self.formerELO=self.ELO global NewRecords global HighestELORecord self.ELO = newELO self.TotalELO+= newELO if newELO > self.MaxELO: NewRecords.append(self.name+' has set a new personal highest ELO at '+str(int(newELO))) self.MaxELO= newELO if newELO > HighestELORecord: HighestELORecord = newELO NewRecords.append(self.name+' has set the alltime highest ELO at '+str(int(newELO))) elif newELO < self.MinELO: NewRecords.append(self.name+' has set a new personal lowest ELO at '+str(int(newELO))) self.MinELO= newELO def addgame(self): self.games+=1 def addwin(self): global WinStreak global NewRecords self.wins+=1 self.addgame() self.setwinperc() self.setrecord() if self.streak < 0: self.streak = 0 self.streak+=1 if self.streak > WinStreak[0]: WinStreak = [self.streak,self.name] NewRecords.append(self.name+' has set a new longest winning streak with '+str(self.streak)) elif self.streak == WinStreak[0]: WinStreak[1] = str(WinStreak[1])+', '+str(self.name) NewRecords.append(self.name+' has tied the longest winning streak at '+str(self.streak)) def addUpset(self): self.upsets+=1 def addUpsetted(self): self.upsetted+=1 def addloss(self): self.losses+=1 self.addgame() self.setwinperc() self.setrecord() if self.streak > 0: self.streak = 0 self.streak -= 1 def addshutout(self): if self.shutouts == '-': self.shutouts = 0 self.shutouts+=1 def addshutouted(self): if self.shutouted == '-': self.shutouted = 0 self.shutouted+=1 def setwinperc(self): if self.games != 0: self.winperc=self.wins/self.games*100 def setrecord(self): self.record=str(int(self.wins))+' - '+str(int(self.losses)) def addhistory(self,news): self.matchhistory.append(news) def SWSS(string,spaces,Front=False):#String With Set Spaces if Front==False: return str(string)+(spaces-len(str(string)))*' ' elif Front==True: return (spaces-len(str(string)))*' '+str(string) def TopTen(Set,string):#Generates a Top Ten List print 'Top Ten '+string for i in range(10): print SWSS(i+1,4)+SWSS(str(Set[i][0]),4)+' '+str(Set[i][1]) def Match(winner,loser,WSCORE,LSCORE): global BiggestUpsets global MatchCount global LastPointDifferentials global Date global EloSwap global GoalsScored LastPointDifferentials=[] MatchCount+=1 Ew = (10.0**(winner.ELO/400.0))/(10.0**(winner.ELO/400.0) + 10.0**(loser.ELO/400.0)) El = (10.0**(loser.ELO/400.0))/(10.0**(winner.ELO/400.0) + 10.0**(loser.ELO/400.0)) Sw = 1.0 Sl = 0.0 k = 32.0 if Ew < .5: winner.addUpset() loser.addUpsetted() neww = winner.ELO + k*(Sw - Ew) LastPointDifferentials.append([winner.name,k*(Sw - Ew)]) EloSwap += k*(Sw - Ew) winner.setELO(neww) winner.addwin() winner.setpoints(WSCORE,'W') GoalsScored += WSCORE if LSCORE == 0: winner.addshutout() loser.addshutouted() winner.addhistory('Win vs '+loser.name) newl = loser.ELO + k*(Sl - El) LastPointDifferentials.append([loser.name,k*(Sl - El)]) loser.setELO(newl) loser.addloss() loser.setpoints(LSCORE,'L') GoalsScored += LSCORE loser.addhistory('Loss vs '+winner.name) if len(BiggestUpsets) < 10: BiggestUpsets.append([str(round(Ew*100,1))+'%',SWSS(winner.name+' ('+str(int(winner.formerELO))+')',20,Front=True)+' vs '+loser.name+' ('+str(int(loser.formerELO))+') '+Date]) BiggestUpsets.sort() else: if float(BiggestUpsets[9][0].rstrip('%'))>Ew*100: BiggestUpsets.pop() BiggestUpsets.append([str(round(Ew*100,1))+'%',SWSS(winner.name+' ('+str(int(winner.formerELO))+')',20,Front=True)+' vs '+loser.name+' ('+str(int(loser.formerELO))+') '+Date]) BiggestUpsets.sort() def printRecords(Players): Records = [] for Playa in Players: Records.append([round((float(Playa.wins)/float((Playa.losses+Playa.wins))),3),Playa.wins,Playa.losses,Playa.name_14_char,Playa.streak]) Records.sort(reverse=True) print ' Win% Record Streak' for group in Records: if len(str(group[0])) == 3: group[0] = str(group[0])+'00' elif len(str(group[0])) == 4: group[0] = str(group[0])+'0' if group[1] <= 9.5: if group[2] <=9.5: print group[3],group[0],' ',int(group[1]),'- ',int(group[2]),' ',group[4] else: print group[3],group[0],' ',int(group[1]),'-',int(group[2]),' ',group[4] else: if int(group[2]) <=9.5: print group[3],group[0],' ',int(group[1]),'- ',int(group[2]),' ',group[4] else: print group[3],group[0],' ',int(group[1]),'-',int(group[2]),' ',group[4] def printStats(Players): Records = [] for Playa in Players: try: Records.append([round(Playa.ppg,1), str(int(Playa.shutouts)), Playa.name_14_char, Playa.upsets, Playa.upsetted, str(int(Playa.shutouted))]) except ValueError: Records.append([round(Playa.ppg,1), Playa.shutouts, Playa.name_14_char, Playa.upsets, Playa.upsetted, Playa.shutouted]) Records.sort(reverse=True) print ' PPG Shutouts Upsets Upsetted Been Shutout' for group in Records: print group[2],' ',group[0],' ',group[1],' ',group[3],' ',group[4],' ',group[5] def Nextmatch(winner,loser): Ew = (10.0**(winner.ELO/400.0))/(10.0**(winner.ELO/400.0) + 10.0**(loser.ELO/400.0)) if Ew >= .5: print winner.name+' has a '+str(round(Ew*100,1))+'% chance of beating '+loser.name else: print loser.name+' has a '+str(round((1-Ew)*100,1))+'% chance of beating '+winner.name Sean=Player('Sean',-1) Russel=Player('Russel') Garret=Player('Garret') Ryan=Player('Ryan',-1) Kris=Player('Kris') Logan=Player('Logan',-1) Phil=Player('Phil') Jon=Player('Jon',-1) Charles=Player('Charles') Zach=Player('Zach',-1) Date='12/7' Match(Sean,Russel,5,4) Date='12/8' Match(Russel,Sean,5,4) Date='12/9' Match(Sean,Russel,5,1) Match(Sean,Russel,5,2) Match(Sean,Russel,5,1) Match(Sean,Russel,5,0) Match(Russel,Sean,5,3) Match(Russel,Sean,5,4) Date='12/10' Match(Russel,Sean,5,3) Match(Sean,Russel,5,0) Match(Russel,Sean,5,0) Match(Russel,Sean,5,4) Match(Sean,Russel,5,4) Match(Russel,Sean,5,0) Match(Sean,Russel,5,3) Match(Sean,Russel,5,1) Date='12/11' Match(Sean,Russel,5,0) Match(Sean,Russel,5,2) Match(Russel,Sean,5,4) Match(Sean,Russel,5,3) Match(Sean,Russel,5,4) Match(Sean,Russel,5,0) Match(Sean,Russel,5,1) Match(Sean,Russel,5,1) Match(Sean,Russel,5,4) Date='12/14' Match(Sean,Russel,5,0) Match(Russel,Sean,5,3) Match(Sean,Russel,5,1) Match(Russel,Sean,5,2) Match(Sean,Russel,5,3) Match(Sean,Russel,5,2) Match(Russel,Sean,5,3) Date='12/15' Match(Sean,Russel,5,3) Match(Sean,Russel,5,4) Match(Sean,Russel,5,2) Match(Russel,Sean,5,4) Match(Sean,Russel,5,0) Match(Sean,Russel,5,4) Date='12/16' Match(Sean,Russel,5,3) Match(Sean,Russel,5,2) Match(Sean,Russel,5,2) Match(Sean,Russel,5,3) Match(Sean,Russel,5,3) Match(Sean,Russel,5,3) Date='12/17' Match(Russel,Sean,5,0) Match(Sean,Russel,5,2) Match(Sean,Russel,5,4) Match(Sean,Russel,5,3) Match(Russel,Sean,5,3) Match(Sean,Russel,5,1) Match(Russel,Sean,5,4) Match(Sean,Russel,5,4) Match(Sean,Russel,5,3) Match(Sean,Russel,5,4) Match(Sean,Garret,5,1) Match(Russel,Garret,5,1) Match(Garret,Ryan,5,0) Match(Garret,Kris,5,1) Match(Garret,Sean,5,2) Match(Garret,Russel,5,1) Match(Kris,Garret,5,2) Date='12/18' Match(Sean,Garret,5,3) Match(Sean,Russel,5,1) Match(Russel,Sean,5,2) Match(Russel,Sean,5,1) Match(Russel,Sean,5,2) Match(Russel,Kris,5,3) Match(Russel,Kris,5,2) Match(Sean,Russel,5,3) Match(Phil,Garret,5,3) Match(Garret,Logan,5,2) Match(Garret,Russel,5,3) Match(Garret,Kris,5,0) Match(Russel,Sean,5,3) Match(Jon,Kris,5,3) Match(Garret,Kris,5,3) Match(Sean,Garret,5,1) Match(Kris,Garret,5,4) Match(Garret,Kris,5,4) Match(Garret,Sean,5,3) Date='12/21' Match(Russel,Garret,5,3) Match(Russel,Garret,5,1) Match(Sean,Kris,5,0) Match(Russel,Garret,5,2) Match(Russel,Garret,5,2) Match(Kris,Garret,5,2) Match(Russel,Kris,5,4) Match(Logan,Ryan,5,3) Match(Kris,Jon,5,3) Match(Sean,Russel,5,3) Match(Russel,Sean,5,3) Match(Russel,Kris,5,1) Match(Russel,Sean,5,2) Match(Russel,Sean,5,3) Match(Russel,Sean,5,4) Match(Russel,Sean,5,4) Match(Sean,Russel,5,1) Match(Sean,Kris,5,0) Date='12/22' Match(Sean,Russel,5,4) Match(Sean,Russel,5,1) Match(Sean,Russel,5,1) Match(Russel,Garret,5,4) Match(Russel,Jon,5,2) Match(Garret,Russel,5,1) Match(Russel,Garret,5,3) Match(Russel,Garret,5,1) Match(Garret,Jon,5,3) Match(Sean,Garret,5,0) Match(Garret,Logan,5,1) Match(Sean,Phil,5,3) Match(Russel,Garret,5,2) Match(Russel,Garret,5,1) Match(Russel,Garret,5,2) Match(Sean,Russel,5,1) Match(Russel,Sean,5,2) Match(Russel,Sean,5,3) Match(Sean,Garret,5,3) Match(Garret,Sean,5,4) Match(Sean,Garret,5,1) Date='12/23' Match(Russel,Sean,5,2) Match(Sean,Russel,5,4) Match(Russel,Phil,5,4) Match(Sean,Russel,5,3) Match(Russel,Garret,5,0) Match(Russel,Garret,5,4) Match(Sean,Garret,5,0) Match(Garret,Jon,5,1) Match(Russel,Kris,5,3) Match(Russel,Kris,5,4) Match(Russel,Kris,5,4) Match(Russel,Charles,5,0) Match(Sean,Russel,5,1) Match(Sean,Russel,5,2) Match(Sean,Russel,5,2) Match(Sean,Russel,5,1) Date='12/24' Match(Sean,Russel,5,1) Match(Sean,Zach,5,0) Match(Sean,Zach,5,2) Match(Sean,Russel,5,4) Match(Sean,Russel,5,4) Date='12/28' Match(Sean,Russel,5,2) Match(Russel,Sean,5,3) Match(Russel,Logan,5,1) Match(Sean,Russel,5,2) Match(Sean,Russel,5,0) Match(Russel,Sean,5,4) Match(Russel,Sean,5,3) Match(Sean,Russel,5,3) Match(Sean,Russel,5,0) Match(Sean,Russel,5,3) Match(Sean,Russel,5,2) Match(Sean,Russel,5,3) Match(Sean,Russel,5,3) Date='12/29' Match(Sean,Russel,5,2) Match(Sean,Russel,5,0) Match(Sean,Russel,5,0) Match(Sean,Russel,5,0) Match(Russel,Sean,5,4) Match(Sean,Russel,5,1) Match(Sean,Russel,5,2) Date='12/30' Match(Sean,Russel,5,4) Match(Sean,Russel,5,0) Match(Sean,Russel,5,2) Date='12/31' Match(Sean,Kris,5,2) Match(Sean,Kris,5,2) Match(Sean,Kris,5,1) Match(Sean,Kris,5,2) Match(Sean,Russel,5,3) Date='1/4' Match(Sean,Kris,5,1) Match(Sean,Kris,5,1) Date='1/5' Match(Sean,Russel,5,1) Match(Sean,Russel,5,1) Match(Sean,Russel,5,2) Match(Sean,Russel,5,2) Date='1/6' Match(Sean,Garret,5,4) Date='1/8' Match(Sean,Kris,5,2) Match(Sean,Kris,5,3) Match(Sean,Kris,5,2) Date='1/12' Match(Sean,Kris,5,0) Match(Sean,Kris,5,3) Match(Sean,Kris,5,1) Match(Sean,Kris,5,4) Match(Sean,Kris,5,1) Date='1/18' Match(Sean,Kris,5,3) Match(Sean,Kris,5,0) Match(Sean,Kris,5,3) Match(Sean,Kris,5,4) Match(Sean,Kris,5,0) Date='1/27' Match(Sean,Kris,5,3) Match(Sean,Kris,5,2) Match(Sean,Kris,5,3) Match(Sean,Kris,5,0) Match(Sean,Kris,5,3) Match(Sean,Kris,5,0) Nextmatch(Sean,Russel) print '' print MatchCount,'games have been played.' print GoalsScored,'goals have been scored.' print int(EloSwap),'ELO points have been swapped.' print '' print 'Last game:' print LastPointDifferentials[0][0]+' gained '+str(int(round(LastPointDifferentials[0][1])))+' ELO points' print LastPointDifferentials[1][0]+' lost '+str(int(round(LastPointDifferentials[1][1]*-1)))+' ELO points' print '' PrintSet=[] print ' Current AVG Max Min' for player in PlayerSet: PrintSet.append([player.ELO,player.name_14_char,' '+str(int(player.TotalELO/(player.games+1)))+' '+str(int(player.MaxELO))+' '+str(int(player.MinELO))]) PrintSet = sorted(PrintSet,key=lambda player_stats: player_stats[0], reverse=True) for player in PrintSet: print player[1]+str(int(player[0]))+player[2] print '' printRecords(PlayerSet) print '' printStats(PlayerSet) print '' TopTen(BiggestUpsets,'Biggest Upsets') print '' print WinStreak[1]+" holds the longest winning streak with "+str(WinStreak[0]) print '' #for match in Russel.matchhistory: # print match
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question