def clear_glicko(): ranks = Rank_Glicko.query().all() for rank in ranks: rank.rd = 350 rank.rating = 350 rank.last_match = 0 rank.save(commit=False) Rank_Glicko.commit()
def best_worst_glicko(): ranks = Rank_Glicko.query().all() ranks = sorted(ranks, key=lambda x: x.rating.value - (x.rd.value), reverse=best) table = [['Rank', 'Rating', 'RD', 'Nick', 'Firstname', 'Lastname', 'ID']] #print "Rank\tRating\tRD\tNick\tForename\tSurname\tid" for i in range(min(args.amount, len(ranks))): player = Player().query().get(player_id=ranks[i].player_id.value) #print "%d\t%d\t%d\t%s\t%s,\t%s\t%s" % (i + 1, ranks[i].rating.value, # ranks[i].rd.value, player.nickname.value, player.firstname.value, # player.lastname.value, player.player_id.value) table.append([i + 1, int(ranks[i].rating.value), int(ranks[i].rd.value), player.nickname.value, player.firstname.value, player.lastname.value, player.player_id.value]) utils.print_table(table)
def best_worst_glicko(): ranks = Rank_Glicko.query().all() ranks = sorted(ranks, key=lambda x: x.rating.value - (x.rd.value), reverse=best) table = [[ 'Rank', 'Rating', 'RD', 'Nick', 'Firstname', 'Lastname', 'ID' ]] #print "Rank\tRating\tRD\tNick\tForename\tSurname\tid" for i in range(min(args.amount, len(ranks))): player = Player().query().get(player_id=ranks[i].player_id.value) #print "%d\t%d\t%d\t%s\t%s,\t%s\t%s" % (i + 1, ranks[i].rating.value, # ranks[i].rd.value, player.nickname.value, player.firstname.value, # player.lastname.value, player.player_id.value) table.append([ i + 1, int(ranks[i].rating.value), int(ranks[i].rd.value), player.nickname.value, player.firstname.value, player.lastname.value, player.player_id.value ]) utils.print_table(table)
def rating_glicko(player): if player is None: return None return Rank_Glicko.query().get(player_id=player.player_id.value)
def update_glicko(): sys.stdout.write("Query matches...") matches = Match1on1.query().all() sys.stdout.write("\rBeginning to update %d matches" % len(matches)) print "" # Query all ratings and store it in a dictionary. This is done to store # the newest rating data in memory. We do not have to commit. ratings = Rank_Glicko.query().all() rdict = {} for r in ratings: rdict[r.player_id.value] = r # sort matches by date matches = sorted(matches, key=lambda x: x.date.value) mDict = {} for match in matches: if match.date.value in mDict: mDict[match.date.value].append(match) else: mDict[match.date.value] = [match] # for each rating period... for period, pMatches in mDict.iteritems(): # players in current period --> (RD, rating) pDict = {} for match in pMatches: for player in [match.player1.value, match.player2.value]: if player not in pDict: pDict[player] = (rdict[player].rd.value, rdict[player].rating.value) # glicko.chess.c curRD = glicko.getCurrentRD( pDict[player][0], 15.8, period - rdict[player].last_match.value) curRating = rdict[player].rating.value # search all matches the player participated, in period ratingList = [] RDList = [] outcomeList = [] for m in pMatches: # player is player1 of match if m.player1.value == player: if m.player2.value in pDict: ratingList.append( pDict[m.player2.value][1]) RDList.append(pDict[m.player2.value][0]) else: ratingList.append( rdict[m.player2.value].rating.value) RDList.append( rdict[m.player2.value].rd.value) outcomeList.append(m.outcome.value) # player player2 of match if m.player2.value == player: if m.player1.value in pDict: ratingList.append( pDict[m.player1.value][1]) RDList.append(pDict[m.player1.value][0]) else: ratingList.append( rdict[m.player1.value].rating.value) RDList.append( rdict[m.player1.value].rd.value) outcomeList.append(1.0 - m.outcome.value) # calculate new rating newRating = glicko.newRating(curRD, curRating, ratingList, RDList, outcomeList) newRD = glicko.newRD(curRD, newRating, ratingList, RDList) rdict[player].rd.value = newRD rdict[player].rating.value = newRating rdict[player].last_match.value = period rdict[player].save(commit=False) Rank_Glicko.commit() stage = period % 4 if stage == 0: sys.stdout.write("\r| ") elif stage == 1: sys.stdout.write("\r/ ") elif stage == 2: sys.stdout.write("\r--") else: sys.stdout.write("\r\\ ") sys.stdout.flush() print "\rDone."
def update_glicko(): sys.stdout.write("Query matches...") matches = Match1on1.query().all() sys.stdout.write("\rBeginning to update %d matches" % len(matches)) print "" # Query all ratings and store it in a dictionary. This is done to store # the newest rating data in memory. We do not have to commit. ratings = Rank_Glicko.query().all() rdict = {} for r in ratings: rdict[r.player_id.value] = r # sort matches by date matches = sorted(matches, key=lambda x: x.date.value) mDict = {} for match in matches: if match.date.value in mDict: mDict[match.date.value].append(match) else: mDict[match.date.value] = [match] # for each rating period... for period, pMatches in mDict.iteritems(): # players in current period --> (RD, rating) pDict = {} for match in pMatches: for player in [match.player1.value, match.player2.value]: if player not in pDict: pDict[player] = (rdict[player].rd.value, rdict[player].rating.value) # glicko.chess.c curRD = glicko.getCurrentRD(pDict[player][0], 15.8, period - rdict[player].last_match.value) curRating = rdict[player].rating.value # search all matches the player participated, in period ratingList = [] RDList = [] outcomeList = [] for m in pMatches: # player is player1 of match if m.player1.value == player: if m.player2.value in pDict: ratingList.append( pDict[m.player2.value][1]) RDList.append(pDict[m.player2.value][0]) else: ratingList.append( rdict[m.player2.value].rating.value) RDList.append( rdict[m.player2.value].rd.value) outcomeList.append(m.outcome.value) # player player2 of match if m.player2.value == player: if m.player1.value in pDict: ratingList.append( pDict[m.player1.value][1]) RDList.append(pDict[m.player1.value][0]) else: ratingList.append( rdict[m.player1.value].rating.value) RDList.append( rdict[m.player1.value].rd.value) outcomeList.append(1.0 - m.outcome.value) # calculate new rating newRating = glicko.newRating(curRD, curRating, ratingList, RDList, outcomeList) newRD = glicko.newRD(curRD, newRating, ratingList, RDList) rdict[player].rd.value = newRD rdict[player].rating.value = newRating rdict[player].last_match.value = period rdict[player].save(commit=False) Rank_Glicko.commit() stage = period % 4 if stage == 0: sys.stdout.write("\r| ") elif stage == 1: sys.stdout.write("\r/ ") elif stage == 2: sys.stdout.write("\r--") else: sys.stdout.write("\r\\ ") sys.stdout.flush() print "\rDone."