import sqlalchemy.sql.functions as func
import sqlalchemy.sql.expression as expr
from datetime import datetime, timedelta
-from pyramid.config import get_current_registry
from pyramid.response import Response
from xonstat.models import *
from xonstat.util import *
log = logging.getLogger(__name__)
def main_index(request):
- settings = get_current_registry().settings
try:
leaderboard_lifetime = int(
- settings['xonstat.leaderboard_lifetime'])
+ request.registry.settings['xonstat.leaderboard_lifetime'])
except:
leaderboard_lifetime = 30
import sqlalchemy.sql.expression as expr\r
import time\r
from datetime import datetime, timedelta\r
-from pyramid.config import get_current_registry\r
from pyramid.response import Response\r
from sqlalchemy import desc\r
from webhelpers.paginate import Page, PageURL\r
"""\r
server_id = request.matchdict['id']\r
\r
- # get settings specific to this view\r
- settings = get_current_registry().settings\r
try: \r
leaderboard_lifetime = int(\r
- settings['xonstat.leaderboard_lifetime'])\r
+ request.registry.settings['xonstat.leaderboard_lifetime'])\r
except:\r
leaderboard_lifetime = 30\r
\r
import pyramid.httpexceptions\r
import re\r
import time\r
-from pyramid.config import get_current_registry\r
from pyramid.response import Response\r
from sqlalchemy import Sequence\r
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound\r
return (idfp, status)\r
\r
\r
-def has_minimum_real_players(player_events):\r
+def has_minimum_real_players(settings, player_events):\r
"""\r
Determines if the collection of player events has enough "real" players\r
to store in the database. The minimum setting comes from the config file\r
"""\r
flg_has_min_real_players = True\r
\r
- settings = get_current_registry().settings\r
try: \r
minimum_required_players = int(\r
settings['xonstat.minimum_required_players'])\r
matched = re.search("acc-(.*?)-cnt-fired", key)\r
if matched:\r
weapon_cd = matched.group(1)\r
+ seq = Sequence('player_weapon_stats_player_weapon_stats_id_seq')\r
+ pwstat_id = session.execute(seq)\r
pwstat = PlayerWeaponStat()\r
+ pwstat.player_weapon_stats_id = pwstat_id\r
pwstat.player_id = player.player_id\r
pwstat.game_id = game.game_id\r
pwstat.player_game_stat_id = pgstat.player_game_stat_id\r
pwstat.frags = int(round(float(\r
player_events['acc-' + weapon_cd + '-frags'])))\r
\r
+ log.debug(pwstat)\r
session.add(pwstat)\r
+ log.debug(pwstat)\r
pwstats.append(pwstat)\r
\r
return pwstats\r
(idfp, status) = verify_request(request)\r
if not idfp:\r
raise pyramid.httpexceptions.HTTPUnauthorized\r
-\r
+ \r
(game_meta, players) = parse_body(request) \r
- \r
+ \r
if not has_required_metadata(game_meta):\r
log.debug("Required game meta fields missing. "\\r
"Can't continue.")\r
raise pyramid.exceptions.HTTPUnprocessableEntity\r
- \r
+ \r
if not is_supported_gametype(game_meta['G']):\r
raise pyramid.httpexceptions.HTTPOk\r
\r
- if not has_minimum_real_players(players):\r
+ if not has_minimum_real_players(request.registry.settings, players):\r
log.debug("The number of real players is below the minimum. " + \r
"Stats will be ignored.")\r
raise pyramid.httpexceptions.HTTPOk\r
-\r
+ \r
server = get_or_create_server(session=session, hashkey=idfp, \r
name=game_meta['S'])\r
-\r
+ \r
gmap = get_or_create_map(session=session, name=game_meta['M'])\r
-\r
+ log.debug(gmap)\r
+ \r
game = create_game(session=session, \r
start_dt=datetime.datetime(\r
*time.gmtime(float(game_meta['T']))[:6]), \r
server_id=server.server_id, game_type_cd=game_meta['G'], \r
- map_id=gmap.map_id)\r
- \r
+ map_id=gmap.map_id)\r
+ log.debug(gmap)\r
+ \r
# find or create a record for each player\r
# and add stats for each if they were present at the end\r
# of the game\r
nick = player_events['n']\r
else:\r
nick = None\r
-\r
+ \r
if 'matches' in player_events and 'scoreboardvalid' \\r
- in player_events:\r
+ in player_events:\r
player = get_or_create_player(session=session, \r
hashkey=player_events['P'], nick=nick)\r
log.debug('Creating stats for %s' % player_events['P'])\r
create_player_stats(session=session, player=player, game=game, \r
player_events=player_events)\r
- \r
+ \r
session.commit()\r
log.debug('Success! Stats recorded.')\r
return Response('200 OK')\r