From: Jan D. Behrens Date: Wed, 29 Aug 2012 10:27:50 +0000 (+0200) Subject: Fixed crash when no active players were found X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=56b9b34c1725612db283e3f97919491dde6e95a9;p=xonotic%2Fxonstat.git Fixed crash when no active players were found --- diff --git a/xonstat/batch/badges/gen_badges.py b/xonstat/batch/badges/gen_badges.py index 8672562..f556ab3 100644 --- a/xonstat/batch/badges/gen_badges.py +++ b/xonstat/batch/badges/gen_badges.py @@ -12,11 +12,12 @@ from render import Skin # maximal number of query results (for testing, set to 0 to get all) -#NUM_PLAYERS = 100 +#NUM_PLAYERS = 200 # we look for players who have activity within the past DELTA hours DELTA = 6 + skin_classic = Skin( bg = "asfalt", ) @@ -95,35 +96,39 @@ else: filter(Player.active_ind == True).\ all() -stop = datetime.now() -td = stop-start -total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 -print "Query took %.2f seconds" % (total_seconds) - -print "Creating badges for %d players ..." % len(players) -start = datetime.now() -data_time, render_time = 0,0 -for player_id in players: - req.matchdict['id'] = player_id - - sstart = datetime.now() - skin.get_data(player_id) - sstop = datetime.now() - td = sstop-sstart +if len(players) > 0: + stop = datetime.now() + td = stop-start total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 - data_time += total_seconds - - sstart = datetime.now() - skin.render_image("output/%d.png" % player_id) - sstop = datetime.now() - td = sstop-sstart + print "Query took %.2f seconds" % (total_seconds) + + print "Creating badges for %d players ..." % len(players) + start = datetime.now() + data_time, render_time = 0,0 + for player_id in players: + req.matchdict['id'] = player_id + + sstart = datetime.now() + skin.get_data(player_id) + sstop = datetime.now() + td = sstop-sstart + total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + data_time += total_seconds + + sstart = datetime.now() + skin.render_image("output/%d.png" % player_id) + sstop = datetime.now() + td = sstop-sstart + total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + render_time += total_seconds + + stop = datetime.now() + td = stop-start total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 - render_time += total_seconds - -stop = datetime.now() -td = stop-start -total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 -print "Creating the badges took %.1f seconds (%.3f s per player)" % (total_seconds, total_seconds/float(len(players))) -print "Total time for redering images: %.3f s" % render_time -print "Total time for getting data: %.3f s" % data_time + print "Creating the badges took %.1f seconds (%.3f s per player)" % (total_seconds, total_seconds/float(len(players))) + print "Total time for redering images: %.3f s" % render_time + print "Total time for getting data: %.3f s" % data_time + +else: + print "No active players found!"