]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Merge branch 'master' of http://git.xonotic.org/xonotic/xonstat into approved
authorJan Behrens <zykure@web.de>
Sat, 2 Feb 2013 16:04:38 +0000 (17:04 +0100)
committerJan Behrens <zykure@web.de>
Sat, 2 Feb 2013 16:04:38 +0000 (17:04 +0100)
xonstat/batch/badges/gen_badges.py
xonstat/batch/badges/skin.py

index 770e42f40b82e21131333643e5c556f8e67cba61..d0d6fb226e5c0b46bb629a2eaf84ac8fc401c9c1 100644 (file)
@@ -16,6 +16,9 @@ from playerdata import PlayerData
 # maximal number of query results (for testing, set to None to get all)
 NUM_PLAYERS = None
 
+# filter by player id (for testing, set to None to disable)
+PLAYER_ID = None
+
 # we look for players who have activity within the past DELTA hours
 DELTA = 6
 
@@ -34,7 +37,7 @@ skin_archer = Skin( "archer",
         #bg              = "background_archer-v2_full",
         bg              = "background_archer-v3",
         overlay         = "",
-        nick_maxwidth  = 265,
+        nick_maxwidth  = 260,
         gametype_pos    = (91,33),
         nostats_pos            = (91,59),
         elo_pos        = (91,47),
@@ -101,18 +104,27 @@ skin_minimal = Skin( "minimal",
 skins = []
 for arg in sys.argv[1:]:
     if arg.startswith("-"):
-        arg = arg[1:]
-        if arg == "force":
+        try:
+            key,value = arg[1:].split("=")
+        except:
+            key,value = arg[1:], ""
+        if key == "force":
             DELTA = 2**24   # large enough to enforce update, and doesn't result in errors
-        elif arg == "test":
+        elif key == "delta":
+            DELTA = float(value)
+        elif key == "test":
             NUM_PLAYERS = 100
-        elif arg == "verbose":
+        elif key == "player":
+            PLAYER_ID = int(value)
+        elif key == "verbose":
             VERBOSE = True
         else:
             print """Usage:  gen_badges.py [options] <ini-file> [skin list]
     Options:
         -force      Force updating all badges (delta = 2^24)
+        -delta n    Manually set an update interval (delta)
         -test       Limit number of players to 100 (for testing)
+        -player #   Filter by given player id
         -verbose    Show more verbose output
         -help       Show this help text
     Ini-File:
@@ -160,6 +172,15 @@ if NUM_PLAYERS:
             filter(Player.player_id > 2).\
             filter(Player.active_ind == True).\
             limit(NUM_PLAYERS).all()
+elif PLAYER_ID:
+    players = DBSession.query(distinct(Player.player_id)).\
+            filter(Player.player_id == PlayerElo.player_id).\
+            filter(Player.player_id == PlayerGameStat.player_id).\
+            filter(PlayerGameStat.create_dt > cutoff_dt).\
+            filter(Player.nick != None).\
+            filter(Player.player_id == PLAYER_ID).\
+            filter(Player.active_ind == True).\
+            limit(NUM_PLAYERS).all()
 else:
     players = DBSession.query(distinct(Player.player_id)).\
             filter(Player.player_id == PlayerElo.player_id).\
index 67d4826a9cf222e8588499b70e85c22e6070e8ee..740b442bfdbc7be74b261e8b5fc7187157ba923d 100644 (file)
@@ -212,6 +212,9 @@ class Skin:
                 game_types.insert(0, gt)
             else:
                 game_types.append(gt)
+        
+        # make sure gametypes list if sorted correctly (number of games, descending)
+        game_types = sorted(game_types, key=lambda x: data['games_played'][x].games, reverse=True)
 
 
 
@@ -348,7 +351,7 @@ class Skin:
             if not elos.has_key(gt) or not ranks.has_key(gt):
                 continue
             count += 1
-
+            
         # re-align segments if less than max. gametypes are shown
         if count > 0:
             if count < self.num_gametypes:
@@ -405,7 +408,7 @@ class Skin:
 
         txt = "???"
         try:
-            txt = "%.2f%%" % round(win_pct * 100, 2)
+            txt = "%.2f%%" % round(win_pct, 2)
         except:
             win_pct = 0