]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Improved "favorite weapon" feature to actually work, and to show more than one weapon
authorJan D. Behrens <zykure@web.de>
Sat, 4 Aug 2012 14:08:42 +0000 (16:08 +0200)
committerJan D. Behrens <zykure@web.de>
Sat, 4 Aug 2012 14:08:42 +0000 (16:08 +0200)
The fav_weapon field now holds all the recently used weapons; the number of shown weapons can be set in the .mako file.

xonstat/templates/player_info.mako
xonstat/views/player.py

index 7247cd65afb2fd074d8919ca45d2b3347dc4955f..c16afb6bf0f2b44f822960c99978c1f746976293 100644 (file)
@@ -197,7 +197,7 @@ Player Information
       % endif
 
       % if fav_weapon is not None:
-      Favorite Weapon: <small>${fav_weapon['name']}</small><br />
+      Favorite Weapons: <small>${", ".join([wpn['name'] for wpn in fav_weapon[:2]])}</small><br />
       % endif
     </p>
   </div>
index 571d77aec51efc3152be7cb5b5f87cb955e84a8d..b7512996155997b26841d15c0fce2e5c13871941 100644 (file)
@@ -148,7 +148,8 @@ def _get_fav_weapon(player_id):
     as the weapon that he or she has employed the most in the past 
     90 days.
 
-    Returns a dictionary with keys for the weapon's name and id.
+    Returns a sequence of dictionaries with keys for the weapon's name and id.
+    The sequence holds the most-used weapons in decreasing order.
     """
     # 90 day window
     back_then = datetime.datetime.utcnow() - datetime.timedelta(days=90)
@@ -160,14 +161,14 @@ def _get_fav_weapon(player_id):
             filter(PlayerGameStat.create_dt > back_then).\
             group_by(Weapon.descr, Weapon.weapon_cd).\
             order_by(func.count().desc()).\
-            one()
-            #limit(1).one()
-            
-    print player_id, raw_fav_weapon
-
-    fav_weapon = {}
-    fav_weapon['name'] = raw_fav_weapon[0]
-    fav_weapon['id'] = raw_fav_weapon[1]
+            all()
+
+    fav_weapon = []
+    for wpn in raw_fav_weapon:
+        entry = {}
+        entry['name'] = wpn[0]
+        entry['id'] = wpn[1]
+        fav_weapon.append(entry)
 
     return fav_weapon