Skip to content

Commit

Permalink
Add exception handling to wg_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SerVB committed Jan 15, 2019
1 parent 09c2694 commit ff1e6a6
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/scripts/client/gui/mods/mod_recent_stat_wg_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,32 @@ def loadPlayerDataByVehicleList(self, vehicles, playerIdToData):
else:
for playerId in idsToBeLoaded:
strPlayerId = str(playerId)
if strPlayerId in accountsInfo and accountsInfo[strPlayerId]["statistics"]["all"]["battles"] != 0:
currentAccountInfo = accountsInfo[strPlayerId]
battles = currentAccountInfo["statistics"]["all"]["battles"]

playerData = playerIdToData[playerId]
playerData.battles = battles
playerData.kb = formatBattlesToKiloBattles(battles)
playerData.wn8 = 0
playerData.xwn8 = 0

if strPlayerId in accountsTanks and battles != 0:
floatBattles = float(battles)

winrate = currentAccountInfo["statistics"]["all"]["wins"] * 100.0 / floatBattles
avgDmg = currentAccountInfo["statistics"]["all"]["damage_dealt"] / floatBattles
avgFrags = currentAccountInfo["statistics"]["all"]["frags"] / floatBattles
avgSpot = currentAccountInfo["statistics"]["all"]["spotted"] / floatBattles
avgDef = currentAccountInfo["statistics"]["all"]["dropped_capture_points"] / floatBattles

wn8 = self.getWN8(winrate, avgDmg, avgFrags, avgSpot, avgDef, accountsTanks[strPlayerId], self._wn8Expected)

playerData.wn8 = wn8
playerData.xwn8 = getXWN8(wn8)
try:
if accountsInfo[strPlayerId]["statistics"]["all"]["battles"] != 0:
currentAccountInfo = accountsInfo[strPlayerId]
battles = currentAccountInfo["statistics"]["all"]["battles"]

playerData = playerIdToData[playerId]
playerData.battles = battles
playerData.kb = formatBattlesToKiloBattles(battles)
playerData.wn8 = 0
playerData.xwn8 = 0

if strPlayerId in accountsTanks and battles != 0:
floatBattles = float(battles)

winrate = currentAccountInfo["statistics"]["all"]["wins"] * 100.0 / floatBattles
avgDmg = currentAccountInfo["statistics"]["all"]["damage_dealt"] / floatBattles
avgFrags = currentAccountInfo["statistics"]["all"]["frags"] / floatBattles
avgSpot = currentAccountInfo["statistics"]["all"]["spotted"] / floatBattles
avgDef = currentAccountInfo["statistics"]["all"]["dropped_capture_points"] / floatBattles

wn8 = self.getWN8(winrate, avgDmg, avgFrags, avgSpot, avgDef, accountsTanks[strPlayerId], self._wn8Expected)

playerData.wn8 = wn8
playerData.xwn8 = getXWN8(wn8)
except BaseException:
logError("Error calculating stats for PlayerID %s..." % playerId, traceback.format_exc())

@staticmethod
def getWN8(winrate, avgDmg, avgFrags, avgSpot, avgDef, accountTanks, wn8Expected):
Expand Down

0 comments on commit ff1e6a6

Please sign in to comment.