]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/views/player.py
Win/loss should use scoreboardpos, not rank.
[xonotic/xonstat.git] / xonstat / views / player.py
index 33b4774c88e5472754c5402995ff1231ab709793..a183114bd341dbafd0767ad6b0ce290dbad1e4ad 100644 (file)
@@ -1,18 +1,13 @@
 import datetime
-import json
 import logging
 import pyramid.httpexceptions
-import re
 import sqlalchemy as sa
 import sqlalchemy.sql.functions as func
-import time
 from calendar import timegm
 from collections import namedtuple
-from pyramid.url import current_route_url
-from sqlalchemy import desc, distinct
-from webhelpers.paginate import Page, PageURL
+from webhelpers.paginate import Page
 from xonstat.models import *
-from xonstat.util import page_url, to_json, pretty_date, datetime_seconds, html_colors
+from xonstat.util import page_url, to_json, pretty_date, datetime_seconds
 from xonstat.views.helpers import RecentGame, recent_games_q
 
 log = logging.getLogger(__name__)
@@ -31,7 +26,7 @@ def player_index_data(request):
                 filter(sa.not_(Player.nick.like('Anonymous Player%'))).\
                 order_by(Player.player_id.desc())
 
-        players = Page(player_q, current_page, items_per_page=10, url=page_url)
+        players = Page(player_q, current_page, items_per_page=25, url=page_url)
 
     except Exception as e:
         players = None
@@ -80,12 +75,12 @@ def get_games_played(player_id):
                                "g.game_type_cd, "
                                "CASE "
                                  "WHEN g.winner = pgs.team THEN 1 "
-                                 "WHEN pgs.rank = 1 THEN 1 "
+                                 "WHEN pgs.scoreboardpos = 1 THEN 1 "
                                  "ELSE 0 "
                                "END win, "
                                "CASE "
                                  "WHEN g.winner = pgs.team THEN 0 "
-                                 "WHEN pgs.rank = 1 THEN 0 "
+                                 "WHEN pgs.scoreboardpos = 1 THEN 0 "
                                  "ELSE 1 "
                                "END loss "
                         "FROM   games g, "
@@ -214,6 +209,35 @@ def get_overall_stats(player_id):
 
         overall_stats[row.game_type_cd] = os
 
+    # We have to edit "overall" stats to exclude deaths in CTS.
+    # Although we still want to record deaths, they shouldn't
+    # count towards the overall K:D ratio.
+    if 'cts' in overall_stats:
+        os = overall_stats['overall']
+
+        try:
+            k_d_ratio = float(os.total_kills)/(os.total_deaths - overall_stats['cts'].total_deaths)
+        except:
+            k_d_ratio = None
+
+        non_cts_deaths = os.total_deaths - overall_stats['cts'].total_deaths
+
+
+        overall_stats['overall'] = OverallStats(
+                total_kills             = os.total_kills,
+                total_deaths            = non_cts_deaths,
+                k_d_ratio               = k_d_ratio,
+                last_played             = os.last_played,
+                last_played_epoch       = os.last_played_epoch,
+                last_played_fuzzy       = os.last_played_fuzzy,
+                total_playing_time      = os.total_playing_time,
+                total_playing_time_secs = os.total_playing_time_secs,
+                total_pickups           = os.total_pickups,
+                total_captures          = os.total_captures,
+                cap_ratio               = os.cap_ratio,
+                total_carrier_frags     = os.total_carrier_frags,
+                game_type_cd            = os.game_type_cd)
+
     return overall_stats
 
 
@@ -322,7 +346,7 @@ def get_ranks(player_id):
     for row in raw_ranks:
         rank = Rank(rank=row.rank,
             max_rank=row.max_rank,
-            percentile=100 - 100*float(row.rank)/row.max_rank,
+            percentile=100 - 100*float(row.rank-1)/(row.max_rank-1),
             game_type_cd=row.game_type_cd)