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.
Now also available in my Gitorious fork of XonStat:
Argh, that's the wrong link -.-
Fixed bug / updated to show more weapons (now most and second-most used weapon is shown by default):
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:
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...
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()
- 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.