Feature #1277

Favorite weapon

Added by zykure over 1 year ago. Updated about 1 year ago.

Status:ClosedStart date:08/04/2012
Priority:NormalDue date:
Assignee:Samual% 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.

0004-Add-Favorite-Weapon-field-to-player-object-and-show-.patch Magnifier - <-- click here for cool new feature ;-) (3.4 KB) zykure, 08/04/2012 03:12 pm

History

#1 Updated by zykure over 1 year ago

#3 Updated by zykure over 1 year 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

#4 Updated by zykure over 1 year ago

And this is how it looks:

#5 Updated by zykure over 1 year 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 over 1 year 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 over 1 year 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 about 1 year 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.

Also available in: Atom PDF