From a1595b528ea3e2769dd651b0eaa1314c4de50123 Mon Sep 17 00:00:00 2001 From: Eugene Fang Date: Sat, 7 Mar 2015 02:30:43 -0500 Subject: [PATCH] Fix division by zero if no matches played --- TbaCommunicator.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/TbaCommunicator.py b/TbaCommunicator.py index a87411b..24bdb46 100644 --- a/TbaCommunicator.py +++ b/TbaCommunicator.py @@ -90,8 +90,14 @@ def getTeamScoreAvgInMatches(teamKey, matches): else: qualMatches += 1 qualTotal += match.alliances.red.score - average.playoffAvg = playoffTotal/playoffMatches - average.qualAvg = qualTotal/qualMatches + if playoffMatches != 0: + average.playoffAvg = playoffTotal/playoffMatches + else: + average.PlayoffAvg = 0 + if qualMatches != 0: + average.qualAvg = qualTotal/qualMatches + else: + average.qualAvg = 0 return average @@ -121,7 +127,7 @@ def getMatch(eventCode, matchCode): def getEventAwards(eventCode): url = TbaApiSettings.tbaBaseUrl + '/event/' + eventCode + '/awards' api_response_string = send_and_get_response(url) - + if not api_response_string: awards = None else: