]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Fixed crash when no active players were found
authorJan D. Behrens <zykure@web.de>
Wed, 29 Aug 2012 10:27:50 +0000 (12:27 +0200)
committerJan D. Behrens <zykure@web.de>
Wed, 29 Aug 2012 10:27:50 +0000 (12:27 +0200)
xonstat/batch/badges/gen_badges.py

index 86725620c6312b6a0a3a1b495100a59d5272a4da..f556ab3d89a1a59fa633ff1e6604a480760353ed 100644 (file)
@@ -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!"