from pyramid.response import Response\r
from sqlalchemy import Sequence\r
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound\r
+from collections import namedtuple\r
from xonstat.d0_blind_id import d0_blind_id_verify\r
from xonstat.elo import process_elos\r
from xonstat.models import *\r
game_meta = {}\r
events = {}\r
players = []\r
+ teams = []\r
\r
+ last_key = None\r
for line in body.split('\n'):\r
try:\r
(key, value) = line.strip().split(' ', 1)\r
# Server (S) and Nick (n) fields can have international characters.\r
if key in 'S' 'n':\r
value = unicode(value, 'utf-8')\r
+ last_key = key\r
\r
- if key not in 'P' 'n' 'e' 't' 'i':\r
+ if key not in 'Q' 'P' 'n' 'e' 't' 'i':\r
game_meta[key] = value\r
+ last_key = key\r
\r
- if key == 'P':\r
- # if we were working on a player record already, append\r
- # it and work on a new one (only set team info)\r
+ if key in 'P' 'Q':\r
+ # if we were working on a player or team record already,\r
+ # append it and work on a new one (only set team info)\r
if len(events) > 0:\r
- players.append(events)\r
+ if last_key == 'P':\r
+ players.append(events)\r
+ elif last_key == 'Q':\r
+ teams.append(events)\r
events = {}\r
\r
events[key] = value\r
+ last_key = key\r
\r
if key == 'e':\r
(subkey, subvalue) = value.split(' ', 1)\r
\r
# add the last player we were working on\r
if len(events) > 0:\r
- players.append(events)\r
+ if last_key == 'P':\r
+ players.append(events)\r
+ elif last_key == 'Q':\r
+ teams.append(events)\r
\r
- return (game_meta, players)\r
+ return (game_meta, players, teams)\r
\r
\r
def is_blank_game(gametype, players):\r
return pgstat\r
\r
\r
-def create_game_stat(session, game_meta, game, server, gmap, player, events):\r
+def create_game_stat(session, game_meta, game, server, gmap, player, teams, events):\r
"""Game stats handler for all game types"""\r
\r
game_type_cd = game.game_type_cd\r
update_fastest_cap(session, player.player_id, game.game_id,\r
gmap.map_id, pgstat.fastest)\r
\r
+ pgstat.teamscore = teams[pgstat.team].score\r
+\r
# there is no "winning team" field, so we have to derive it\r
if wins and pgstat.team is not None and game.winner is None:\r
game.winner = pgstat.team\r
"----- END REQUEST BODY -----\n\n")\r
\r
(idfp, status) = verify_request(request)\r
- (game_meta, raw_players) = parse_stats_submission(request.body)\r
+ (game_meta, raw_players, raw_teams) = parse_stats_submission(request.body)\r
revision = game_meta.get('R', 'unknown')\r
duration = game_meta.get('D', None)\r
\r
duration = duration,\r
mod = game_meta.get('O', None))\r
\r
+ TeamInfo = namedtuple("TeamInfo", ['team','score'])\r
+ teams = {}\r
+ for events in raw_teams:\r
+ team = events['Q']\r
+ if team.startswith("team#"):\r
+ t = int(team[5:])\r
+ for (key,value) in events.items():\r
+ if key == 'scoreboard-teamscore':\r
+ teams[t] = TeamInfo(team=t, score=int(value))\r
+\r
for events in raw_players:\r
player = get_or_create_player(\r
session = session,\r
nick = events.get('n', None))\r
\r
pgstat = create_game_stat(session, game_meta, game, server,\r
- gmap, player, events)\r
+ gmap, player, teams, events)\r
\r
if should_do_weapon_stats(game_type_cd) and player.player_id > 1:\r
pwstats = create_weapon_stats(session, game_meta, game, player,\r