Feature #1277
Favorite weapon
| Status: | Closed | Start date: | 08/04/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% | ||
| Category: | Server Code | |||
| Target version: | - |
Description
I thought it would be nice to see a player's most-used weapon on XonStat (similar to "favorite map").
Since this was also a good exercise to get into the XonStat code, I implemented it and it seems to work from what I can tell. Maybe the SQL query can be improved somewhat, it's basically taken over from the get_fav_map() function.
History
#1
Updated by zykure 11 months ago
Now also available in my Gitorious fork of XonStat:
https://gitorious.org/xonstat/xonstat/commit/be526167caa309742477e3a20507fd91f7ecd959
#2
Updated by zykure 11 months ago
Argh, that's the wrong link -.-
https://gitorious.org/xonstat/xonstat/commit/fecb469603842703d647c2392cb2f54f133577a1
#3
Updated by zykure 11 months ago
Fixed bug / updated to show more weapons (now most and second-most used weapon is shown by default):
https://gitorious.org/xonstat/xonstat/commit/2e96bc5fea7cfccb4079fd582b32e2050430a187
#5
Updated by zykure 11 months ago
Since one can now show one or more favorite weapons, the same can be applied to the "favorite maps" entry. By default, the player info page now displays the 3 most-played maps:
https://gitorious.org/xonstat/xonstat/commit/a498dcfe8fddc6734377746ab79e8a24467dffce
Screenshot:

#6
Updated by zykure 11 months ago
Okay, now that I was able to test my changes with an actual database dump provided by Antibidy, I noticed that the query for getting the favorite weapons takes far too long on my system (it never completes, actually).
I traced the problem down to the actual query:
raw_fav_weapon = DBSession.query(Weapon.descr, Weapon.weapon_cd).\
filter(Game.game_id == PlayerGameStat.game_id).\
filter(PlayerGameStat.player_id == player_id).\
filter(PlayerWeaponStat.weapon_cd == Weapon.weapon_cd).\
filter(PlayerGameStat.create_dt > back_then).\
group_by(Weapon.descr, Weapon.weapon_cd).\
order_by(func.count().desc()).\
limit(5).all()
I don't know why this takes so long, it is not that different from the favorite_map and favorite_server queries...
#7
Updated by zykure 11 months ago
Fixed it, I was just accessing two tables in the same query .. no wonder that takes too long ;-)
Now it looks like this:
raw_fav_weapon = DBSession.query(Weapon.descr, Weapon.weapon_cd).\
filter(Game.game_id == PlayerWeaponStat.game_id).\
filter(PlayerWeaponStat.player_id == player_id).\
filter(PlayerWeaponStat.weapon_cd == Weapon.weapon_cd).\
filter(PlayerWeaponStat.create_dt > back_then).\
group_by(Weapon.descr, Weapon.weapon_cd).\
order_by(func.count().desc()).\
limit(5).all()
#8
Updated by antibody 4 months ago
- Status changed from New to Closed
Closing this as unnecessary. I'd rather have something more meaningful on the player_info pages regarding weapons. Perhaps a horizontal, stacked bar chart showing the frags per weapon distribution (from, say, the past 90 days) would be better.

