def getPlayerAchievementsJson(player): achievements = [{ 'name': a.name, 'description': a.description, 'time': player.achievements[a] } for a in player.achievements.keys()] [achievements.append({ 'name': clz.name, 'description': clz.description, }) for clz in Achievement.__subclasses__() if clz not in player.achievements.keys()] return achievements
def getPlayerAchievementsJson(player): achievements = [{ 'name': a.name, 'description': a.description, 'time': player.achievements[a] } for a in player.achievements.keys()] [ achievements.append({ 'name': clz.name, 'description': clz.description, }) for clz in Achievement.__subclasses__() if clz not in player.achievements.keys() ] return achievements
def addGame(self, game): self.games.append(game) if game.isDeleted(): return if game.redPlayer not in self.players: self.players[game.redPlayer] = Player(game.redPlayer) red = self.players[game.redPlayer] if game.bluePlayer not in self.players: self.players[game.bluePlayer] = Player(game.bluePlayer) blue = self.players[game.bluePlayer] predict = 1 / (1 + 10 ** ((red.elo - blue.elo) / 180)) result = float(game.blueScore) / (game.blueScore + game.redScore) delta = 25 * (result - predict) game.skillChangeToBlue = delta bluePosBefore = -1 redPosBefore = -1 for index, player in enumerate( sorted([p for p in self.players.values() if p.isActive(game.time - 1)], key=lambda x: x.elo, reverse=True) ): if player.name == game.bluePlayer: bluePosBefore = index elif player.name == game.redPlayer: redPosBefore = index blue.game(game) red.game(game) bluePosAfter, redPosAfter = -1, -1 for index, player in enumerate( sorted([p for p in self.players.values() if p.isActive(game.time)], key=lambda x: x.elo, reverse=True) ): if player.name == game.bluePlayer: bluePosAfter = index game.bluePosAfter = bluePosAfter + 1 # because it's zero-indexed here elif player.name == game.redPlayer: redPosAfter = index game.redPosAfter = redPosAfter + 1 if bluePosBefore > 0: game.bluePosChange = ( bluePosBefore - bluePosAfter ) # It's this way around because a rise in position is to a lower numbered rank. if redPosBefore > 0: game.redPosChange = redPosBefore - redPosAfter if bluePosBefore > 0 and redPosBefore > 0: if bluePosBefore == redPosAfter or redPosBefore == bluePosAfter: game.positionSwap = True game.redAchievements = Achievement.getAllForGame(red, game, blue, self) game.blueAchievements = Achievement.getAllForGame(blue, game, red, self) if blue.elo > self.highSkill["skill"]: self.highSkill["skill"] = blue.elo self.highSkill["player"] = blue self.highSkill["time"] = game.time if red.elo > self.highSkill["skill"]: self.highSkill["skill"] = red.elo self.highSkill["player"] = red self.highSkill["time"] = game.time if blue.elo < self.lowSkill["skill"]: self.lowSkill["skill"] = blue.elo self.lowSkill["player"] = blue self.lowSkill["time"] = game.time if red.elo < self.lowSkill["skill"]: self.lowSkill["skill"] = red.elo self.lowSkill["player"] = red self.lowSkill["time"] = game.time