Exemplo n.º 1
0
    def _compute_elos(self, agent_names, scores):
        old_elos = [self.elos[name][-1] for name in agent_names]
        positions = self._compute_absolute_positions(scores)
        players = [
            multi_elo.EloPlayer(place=place, elo=old_elo)
            for place, old_elo in zip(positions, old_elos)
        ]

        new_elos = multi_elo.calc_elo(players, self.elo_k)

        return new_elos
Exemplo n.º 2
0
def calc_game_2p(p1_place, p1_r, p2_place, p2_r, name1, name2):
    elo_players = [EloPlayer(p1_place, p1_r), EloPlayer(p2_place, p2_r)]
    new_elos = calc_elo(elo_players)

    sql1 = "UPDATE players SET Rating = %d WHERE Name = '%s'" % (new_elos[0], name1)
    sql2 = "UPDATE players SET Rating = %d WHERE Name = '%s'" % (new_elos[1], name2)

    mycursor.execute(sql1)
    mycursor.execute(sql2)
    db.commit()

    print(new_elos)
Exemplo n.º 3
0
def calc_game_4p(p1_place, p1_r, p2_place, p2_r, p3_place, p3_r, p4_place, p4_r, name1, name2, name3, name4):
    elo_players = [EloPlayer(p1_place, p1_r), EloPlayer(p2_place, p2_r), EloPlayer(p3_place, p3_r), EloPlayer(p4_place, p4_r)]
    new_elos = calc_elo(elo_players)
    
    sql1 = "UPDATE players SET Rating = %d WHERE Name = '%s'" % (new_elos[0], name1)
    sql2 = "UPDATE players SET Rating = %d WHERE Name = '%s'" % (new_elos[1], name2)
    sql3 = "UPDATE players SET Rating = %d WHERE Name = '%s'" % (new_elos[2], name3)
    sql4 = "UPDATE players SET Rating = %d WHERE Name = '%s'" % (new_elos[3], name4)

    mycursor.execute(sql1)
    mycursor.execute(sql2)
    mycursor.execute(sql3)
    mycursor.execute(sql4)
    db.commit()

    print(new_elos)
Exemplo n.º 4
0
                    if (username_to_rating.has_key(username)):
                        rating = username_to_rating[username]['rating']
                        formatted_match.append(
                            EloPlayer(place=place, elo=rating))
                    else:
                        formatted_match.append(
                            EloPlayer(place=place, elo=starting_rating))
                    match_score = MatchScore(
                        match_id=match_data.id,
                        username=username,
                        score=player['score'],
                        place=place,
                    )
                    db.session.add(match_score)
                    place += 1
                ratings = calc_elo(formatted_match, k_factor)
                for i in range(len(ratings)):
                    username = usernames[i]
                    old_rating = 1500
                    if (username_to_rating.has_key(username)):
                        old_rating = username_to_rating[username]['rating']
                    new_rating = ratings[i]
                    rating_data = {}
                    rating_data['rating'] = new_rating
                    rating_data['latest_delta'] = new_rating - old_rating
                    username_to_rating[username] = rating_data

        # print("Match count: " + str(match_count))

        # The sorting below was for generating a nice printed list. Since everything is being stored to a db now, we don't need the sort (it will happen later)
        # Still going to leave the code in just in case it comes in handy at some point.