#NEWLINE# def player_stats( self ) : #NEWLINE# #INDENT# '\n        Calculates stats about the players historical performance.\n        ' #NEWLINE# played = self . result_player . count ( ) #NEWLINE# won = float ( self . result_player . filter ( result = 9 ) . count ( ) ) #NEWLINE# lost = ( played - won ) #NEWLINE# if ( played != 0 ) : #NEWLINE# #INDENT# win_rate = ( ( won / float ( played ) ) * 100.0 ) #NEWLINE# additional_points = ( ( ( match_count * 2 ) + played ) / played ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'played' : '-' , #NEWLINE# 'win_rate' : '- %' , #NEWLINE# 'average' : '-' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# average = list ( self . result_player . aggregate ( Avg ( 'result' ) ) . values ( ) ) [ 0 ] #NEWLINE# average_with_additional = ( average + additional_points ) #NEWLINE# leagues = self . league_set . filter ( player = self ) #NEWLINE# match_count = 0 #NEWLINE# for league in leagues : #NEWLINE# #INDENT# match_count += ( league . ladder . league_set . count ( ) - 1 ) #NEWLINE# #UNINDENT# completion_rate = ( ( float ( played ) / float ( match_count ) ) * 100.0 ) #NEWLINE# return { #NEWLINE# #INDENT# 'played' : played , #NEWLINE# 'win_rate' : '{0:.2f} %' . format ( win_rate ) , #NEWLINE# 'completion_rate' : '{0:.2f} %' . format ( completion_rate ) , #NEWLINE# 'average' : '{0:.2f}' . format ( average_with_additional ) , #NEWLINE# #UNINDENT# }