]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/batch/badges/gen_badges.py
Implemented some (preliminary) JSON API to retrieve player data
[xonotic/xonstat.git] / xonstat / batch / badges / gen_badges.py
index 4465ead7035ffbf800685ca97191fce0b9eb3a21..44d73aec3da4f1ea2a16690cf9e965c954777b33 100644 (file)
@@ -7,6 +7,7 @@ import sqlalchemy.sql.functions as func
 from sqlalchemy import distinct
 from pyramid.paster import bootstrap
 from xonstat.models import *
+from xonstat.util import datetime_seconds
 
 from skin import Skin
 from playerdata import PlayerData
@@ -21,7 +22,7 @@ DELTA = 6
 
 # classic skin WITHOUT NAME - writes PNGs into "output//###.png"
 skin_classic = Skin( "",
-        bg              = "asfalt",
+        bg              = "broken_noise",
         overlay         = "overlay_classic",
     )
 
@@ -38,38 +39,44 @@ skin_minimal = Skin( "minimal",
         overlay         = "overlay_minimal",
         width           = 560,
         height          = 40,
+        nick_fontsize   = 16,
+        nick_pos        = (36,16),
         num_gametypes   = 3,
-        gametype_pos    = (8,30),
-        gametype_color  = (0.8, 0.8, 0.8),
+        nick_maxwidth   = 300,
+        gametype_pos    = (70,30),
+        gametype_color  = (0.0, 0.0, 0.0),
         gametype_text   = "%s:",
-        gametype_width  = 112,
+        gametype_width  = 100,
         gametype_fontsize = 10,
-        gametype_center = False,
+        gametype_align  = -1,
+        gametype_upper  = False,
         elo_pos         = (75,30),
         elo_text        = "Elo %.0f",
-        elo_color       = (0.9, 0.9, 0.7),
-        elo_center      = True,
+        elo_color       = (0.7, 0.7, 0.7),
+        elo_align       = 1,
         rank_pos        = None,
-        nostats_pos     = (75,30),
-        nostats_fontsize = 10,
-        nostats_angle   = 0,
-        nostats_text    = "no stats!",
-        nostats_color   = (0.8, 0.3, 0.3),
-        nostats_center  = True,
+        nostats_pos     = None,
+        #nostats_pos     = (75,30),
+        #nostats_fontsize = 10,
+        #nostats_angle   = 0,
+        #nostats_text    = "no stats yet!",
+        #nostats_color   = (0.7, 0.4, 0.4),
         kdr_pos         = (392,15),
-        kdr_colortop    = (0.1, 0.8, 0.1),
-        kdr_colormid    = (0.6, 0.6, 0.1),
-        kdr_colorbot    = (0.8, 0.1, 0.1),
+        kdr_fontsize    = 10,
+        kdr_colortop    = (0.6, 0.8, 0.6),
+        kdr_colormid    = (0.6, 0.6, 0.6),
+        kdr_colorbot    = (0.8, 0.6, 0.6),
         kills_pos       = None,
         deaths_pos      = None,
         winp_pos        = (508,15),
+        winp_fontsize   = 10,
+        winp_colortop   = (0.6, 0.8, 0.8),
+        winp_colormid   = (0.6, 0.6, 0.6),
+        winp_colorbot   = (0.8, 0.8, 0.6),
         wins_pos        = None,
-        winp_colortop   = (0.1, 0.6, 0.6),
-        winp_colormid   = (0.2, 0.6, 0.2),
-        winp_colorbot   = (0.6, 0.6, 0.1),
         loss_pos        = None,
         ptime_pos       = (451,30),
-        ptime_color     = (0.7, 0.7, 0.9),
+        ptime_color     = (0.7, 0.7, 0.7),
     )
 
 
@@ -107,7 +114,6 @@ for arg in sys.argv[1:]:
 if len(skins) == 0:
     skins = [ skin_classic, skin_minimal ]
 
-
 # environment setup
 env = bootstrap('../../../development.ini')
 req = env['request']
@@ -141,8 +147,7 @@ playerdata = PlayerData()
 if len(players) > 0:
     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 "Query took %.2f seconds" % (datetime_seconds(td))
 
     print "Creating badges for %d players ..." % len(players)
     start = datetime.now()
@@ -154,20 +159,18 @@ if len(players) > 0:
         playerdata.get_data(player_id)
         sstop = datetime.now()
         td = sstop-sstart
-        total_seconds = float(td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
-        data_time += total_seconds
+        data_time += datetime_seconds(td)
 
         sstart = datetime.now()
         for sk in skins:
             sk.render_image(playerdata, "output/%s/%d.png" % (str(sk), player_id[0]))
         sstop = datetime.now()
         td = sstop-sstart
-        total_seconds = float(td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
-        render_time += total_seconds
+        render_time += datetime_seconds(td)
 
     stop = datetime.now()
     td = stop-start
-    total_seconds = float(td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
+    total_seconds = datetime_seconds(td)
     print "Creating the badges took %.1f seconds (%.3f s per player)" % (total_seconds, total_seconds/float(len(players)))
     print "Total time for rendering images: %.3f s" % render_time
     print "Total time for getting data: %.3f s" % data_time