Exemplo n.º 1
0
def elo_calculator(match):
    """generate the ELO of the match"""

    ELO_FACTOR = 32
    ELO_PONDERATION = 400

    game = Match(match)
    playersOldElo = {}
    eloPool = 0
    # collect the base data to calculate the elo
    for player in game.players:
        temp = MongoInterface.get_player(player.playerName).get("elo")
        playersOldElo[player.playerName] = temp
        eloPool += temp
    # calculate each players elo
    for player in game.players:

        splayer = SimplifiedPlayer(MongoInterface.get_player(player.playerName))

        oldElo = playersOldElo[player.playerName]

        if player.playerName in game.winners:
            newElo = oldElo + (
                (ELO_FACTOR * (1 - (math.pow(10, oldElo / ELO_PONDERATION) / eloPool))) / len(game.winners)
            )
        else:
            newElo = oldElo + ((ELO_FACTOR * (0 - (math.pow(10, oldElo / ELO_PONDERATION) / eloPool))))

        splayer.elo = newElo
        splayer.save()
        player.elo = newElo
    MongoInterface.update_log(game.ident, game.toDoc())
    return newElo
Exemplo n.º 2
0
def elo_calculator(match):
    """generate the ELO of the match"""

    ELO_FACTOR = 32
    ELO_PONDERATION = 400

    game = Match(match)
    playersOldElo = {}
    eloPool = 0
    #collect the base data to calculate the elo
    for player in game.players:
        temp = MongoInterface.get_player(player.playerName).get('elo')
        playersOldElo[player.playerName] = temp
        eloPool += temp
    #calculate each players elo
    for player in game.players:

        splayer = SimplifiedPlayer(MongoInterface.get_player(
            player.playerName))

        oldElo = playersOldElo[player.playerName]

        if player.playerName in game.winners:
            newElo = oldElo + ((ELO_FACTOR * (1 - (math.pow(
                10, oldElo / ELO_PONDERATION) / eloPool))) / len(game.winners))
        else:
            newElo = oldElo + (
                (ELO_FACTOR *
                 (0 - (math.pow(10, oldElo / ELO_PONDERATION) / eloPool))))

        splayer.elo = newElo
        splayer.save()
        player.elo = newElo
    MongoInterface.update_log(game.ident, game.toDoc())
    return newElo
    def save(self):
        """insert or update the player on the database

        this function will search the database on the players collection
        and see if player exists if it already exists and 'update' is true it
        will update the player data on the database else it does nothing,
        and if player don't exists it saves the new player
        """
        player = MongoInterface.get_player(self.name)
        document = {"name": self.name, "elo": self.elo}

        if player is None:
            MongoInterface.insert_player(document)
        else:
            MongoInterface.update_player(player["_id"], document)
Exemplo n.º 4
0
    def save(self):
        """insert or update the player on the database

        this function will search the database on the players collection
        and see if player exists if it already exists and 'update' is true it
        will update the player data on the database else it does nothing,
        and if player don't exists it saves the new player
        """
        player = MongoInterface.get_player(self.name)
        document = {"name": self.name, "elo": self.elo}

        if player is None:
            MongoInterface.insert_player(document)
        else:
            MongoInterface.update_player(player["_id"], document)