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 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 detect_bigmoney_strategy(match): """defines if one or more players in the match used the bigmoney strategy""" game = Match(match) is_big_money_flag = True for player in game.players: deck = player.deck for card in deck: if not (card in ("province", "gold", "silver", "duchy", "smithy")): is_big_money_flag = False if is_big_money_flag: player.strategy = "bigmoney" MongoInterface.update_log(game.ident, game.toDoc())
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)