def player_hashkey_info_text(request): """ Provides detailed information on a specific player. Plain text. """ # UTC epoch now = timegm(datetime.datetime.utcnow().timetuple()) # All player_info fields are converted into JSON-formattable dictionaries player_info = player_hashkey_info_data(request) # gather all of the data up into aggregate structures player = player_info['player'] games_played = player_info['games_played'] overall_stats = player_info['overall_stats'] elos = player_info['elos'] ranks = player_info['ranks'] fav_maps = player_info['fav_maps'] most_recent_game = player_info['most_recent_game'] # one-offs for things needing conversion for text/plain player_joined = timegm(player.create_dt.timetuple()) player_joined_dt = player.create_dt alivetime = int( datetime_seconds(overall_stats['overall'].total_playing_time)) # this is a plain text response, if we don't do this here then # Pyramid will assume html request.response.content_type = 'text/plain' return { 'version': 1, 'now': now, 'player': player, 'hashkey': player_info['hashkey'], 'player_joined': player_joined, 'player_joined_dt': player_joined_dt, 'games_played': games_played, 'overall_stats': overall_stats, 'alivetime': alivetime, 'fav_maps': fav_maps, 'elos': elos, 'ranks': ranks, 'most_recent_game': most_recent_game, }
def player_hashkey_info_text(request): """ Provides detailed information on a specific player. Plain text. """ # UTC epoch now = timegm(datetime.datetime.utcnow().timetuple()) # All player_info fields are converted into JSON-formattable dictionaries player_info = player_hashkey_info_data(request) # gather all of the data up into aggregate structures player = player_info['player'] games_played = player_info['games_played'] overall_stats = player_info['overall_stats'] elos = player_info['elos'] ranks = player_info['ranks'] fav_maps = player_info['fav_maps'] most_recent_game = player_info['most_recent_game'] # one-offs for things needing conversion for text/plain player_joined = timegm(player.create_dt.timetuple()) player_joined_dt = player.create_dt alivetime = int(datetime_seconds(overall_stats['overall'].total_playing_time)) # this is a plain text response, if we don't do this here then # Pyramid will assume html request.response.content_type = 'text/plain' return { 'version': 1, 'now': now, 'player': player, 'hashkey': player_info['hashkey'], 'player_joined': player_joined, 'player_joined_dt': player_joined_dt, 'games_played': games_played, 'overall_stats': overall_stats, 'alivetime': alivetime, 'fav_maps': fav_maps, 'elos': elos, 'ranks': ranks, 'most_recent_game': most_recent_game, }
def player_hashkey_info_text(request): """ Provides detailed information on a specific player. Plain text. """ # UTC epoch now = timegm(datetime.datetime.utcnow().timetuple()) # All player_info fields are converted into JSON-formattable dictionaries player_info = player_hashkey_info_data(request) # gather all of the data up into aggregate structures player = player_info["player"] games_played = player_info["games_played"] overall_stats = player_info["overall_stats"] elos = player_info["elos"] ranks = player_info["ranks"] fav_maps = player_info["fav_maps"] most_recent_game = player_info["most_recent_game"] # one-offs for things needing conversion for text/plain player_joined = timegm(player.create_dt.timetuple()) player_joined_dt = player.create_dt alivetime = int(datetime_seconds(overall_stats["overall"].total_playing_time)) # this is a plain text response, if we don't do this here then # Pyramid will assume html request.response.content_type = "text/plain" return { "version": 1, "now": now, "player": player, "hashkey": player_info["hashkey"], "player_joined": player_joined, "player_joined_dt": player_joined_dt, "games_played": games_played, "overall_stats": overall_stats, "alivetime": alivetime, "fav_maps": fav_maps, "elos": elos, "ranks": ranks, "most_recent_game": most_recent_game, }
def get_overall_stats(player_id): """ Provides a breakdown of stats by gametype played by player_id. Returns a dictionary of namedtuples with the following members: - total_kills - total_deaths - k_d_ratio - last_played (last time the player played the game type) - last_played_epoch (same as above, but in seconds since epoch) - last_played_fuzzy (same as above, but in relative date) - total_playing_time (total amount of time played the game type) - total_playing_time_secs (same as the above, but in seconds) - total_pickups (ctf only) - total_captures (ctf only) - cap_ratio (ctf only) - total_carrier_frags (ctf only) - game_type_cd - game_type_descr The key to the dictionary is the game type code. There is also an "overall" game_type_cd which sums the totals and computes the total ratios. """ OverallStats = namedtuple('OverallStats', ['total_kills', 'total_deaths', 'k_d_ratio', 'last_played', 'last_played_epoch', 'last_played_fuzzy', 'total_playing_time', 'total_playing_time_secs', 'total_pickups', 'total_captures', 'cap_ratio', 'total_carrier_frags', 'game_type_cd', 'game_type_descr']) raw_stats = DBSession.query('game_type_cd', 'game_type_descr', 'total_kills', 'total_deaths', 'last_played', 'total_playing_time', 'total_pickups', 'total_captures', 'total_carrier_frags').\ from_statement( "SELECT g.game_type_cd, " "gt.descr game_type_descr, " "Sum(pgs.kills) total_kills, " "Sum(pgs.deaths) total_deaths, " "Max(pgs.create_dt) last_played, " "Sum(pgs.alivetime) total_playing_time, " "Sum(pgs.pickups) total_pickups, " "Sum(pgs.captures) total_captures, " "Sum(pgs.carrier_frags) total_carrier_frags " "FROM games g, " "cd_game_type gt, " "player_game_stats pgs " "WHERE g.game_id = pgs.game_id " "AND g.game_type_cd = gt.game_type_cd " "AND g.players @> ARRAY[:player_id] " "AND pgs.player_id = :player_id " "GROUP BY g.game_type_cd, game_type_descr " "UNION " "SELECT 'overall' game_type_cd, " "'Overall' game_type_descr, " "Sum(pgs.kills) total_kills, " "Sum(pgs.deaths) total_deaths, " "Max(pgs.create_dt) last_played, " "Sum(pgs.alivetime) total_playing_time, " "Sum(pgs.pickups) total_pickups, " "Sum(pgs.captures) total_captures, " "Sum(pgs.carrier_frags) total_carrier_frags " "FROM player_game_stats pgs " "WHERE pgs.player_id = :player_id " ).params(player_id=player_id).all() # to be indexed by game_type_cd overall_stats = {} for row in raw_stats: # individual gametype ratio calculations try: k_d_ratio = float(row.total_kills)/row.total_deaths except: k_d_ratio = None try: cap_ratio = float(row.total_captures)/row.total_pickups except: cap_ratio = None # everything else is untouched or "raw" os = OverallStats(total_kills=row.total_kills, total_deaths=row.total_deaths, k_d_ratio=k_d_ratio, last_played=row.last_played, last_played_epoch=timegm(row.last_played.timetuple()), last_played_fuzzy=pretty_date(row.last_played), total_playing_time=row.total_playing_time, total_playing_time_secs=int(datetime_seconds(row.total_playing_time)), total_pickups=row.total_pickups, total_captures=row.total_captures, cap_ratio=cap_ratio, total_carrier_frags=row.total_carrier_frags, game_type_cd=row.game_type_cd, game_type_descr=row.game_type_descr) 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, game_type_descr = os.game_type_descr) return overall_stats
def get_overall_stats(player_id): """ Provides a breakdown of stats by gametype played by player_id. Returns a dictionary of namedtuples with the following members: - total_kills - total_deaths - k_d_ratio - last_played (last time the player played the game type) - last_played_epoch (same as above, but in seconds since epoch) - last_played_fuzzy (same as above, but in relative date) - total_playing_time (total amount of time played the game type) - total_playing_time_secs (same as the above, but in seconds) - total_pickups (ctf only) - total_captures (ctf only) - cap_ratio (ctf only) - total_carrier_frags (ctf only) - game_type_cd - game_type_descr The key to the dictionary is the game type code. There is also an "overall" game_type_cd which sums the totals and computes the total ratios. """ OverallStats = namedtuple('OverallStats', [ 'total_kills', 'total_deaths', 'k_d_ratio', 'last_played', 'last_played_epoch', 'last_played_fuzzy', 'total_playing_time', 'total_playing_time_secs', 'total_pickups', 'total_captures', 'cap_ratio', 'total_carrier_frags', 'game_type_cd', 'game_type_descr' ]) raw_stats = DBSession.query('game_type_cd', 'game_type_descr', 'total_kills', 'total_deaths', 'last_played', 'total_playing_time', 'total_pickups', 'total_captures', 'total_carrier_frags').\ from_statement( "SELECT g.game_type_cd, " "gt.descr game_type_descr, " "Sum(pgs.kills) total_kills, " "Sum(pgs.deaths) total_deaths, " "Max(pgs.create_dt) last_played, " "Sum(pgs.alivetime) total_playing_time, " "Sum(pgs.pickups) total_pickups, " "Sum(pgs.captures) total_captures, " "Sum(pgs.carrier_frags) total_carrier_frags " "FROM games g, " "cd_game_type gt, " "player_game_stats pgs " "WHERE g.game_id = pgs.game_id " "AND g.game_type_cd = gt.game_type_cd " "AND g.players @> ARRAY[:player_id] " "AND pgs.player_id = :player_id " "GROUP BY g.game_type_cd, game_type_descr " "UNION " "SELECT 'overall' game_type_cd, " "'Overall' game_type_descr, " "Sum(pgs.kills) total_kills, " "Sum(pgs.deaths) total_deaths, " "Max(pgs.create_dt) last_played, " "Sum(pgs.alivetime) total_playing_time, " "Sum(pgs.pickups) total_pickups, " "Sum(pgs.captures) total_captures, " "Sum(pgs.carrier_frags) total_carrier_frags " "FROM player_game_stats pgs " "WHERE pgs.player_id = :player_id " ).params(player_id=player_id).all() # to be indexed by game_type_cd overall_stats = {} for row in raw_stats: # individual gametype ratio calculations try: k_d_ratio = float(row.total_kills) / row.total_deaths except: k_d_ratio = None try: cap_ratio = float(row.total_captures) / row.total_pickups except: cap_ratio = None # everything else is untouched or "raw" os = OverallStats(total_kills=row.total_kills, total_deaths=row.total_deaths, k_d_ratio=k_d_ratio, last_played=row.last_played, last_played_epoch=timegm( row.last_played.timetuple()), last_played_fuzzy=pretty_date(row.last_played), total_playing_time=row.total_playing_time, total_playing_time_secs=int( datetime_seconds(row.total_playing_time)), total_pickups=row.total_pickups, total_captures=row.total_captures, cap_ratio=cap_ratio, total_carrier_frags=row.total_carrier_frags, game_type_cd=row.game_type_cd, game_type_descr=row.game_type_descr) 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, game_type_descr=os.game_type_descr) return overall_stats
else: players = DBSession.query(distinct(Player.player_id)).\ filter(Player.player_id == PlayerElo.player_id).\ filter(Player.player_id == PlayerGameStat.player_id).\ filter(PlayerGameStat.create_dt > cutoff_dt).\ filter(Player.nick != None).\ filter(Player.player_id > 2).\ filter(Player.active_ind == True).\ all() playerdata = PlayerData() if len(players) > 0: stop = datetime.now() td = stop-start print "Query took %.2f seconds" % (datetime_seconds(td)) print "Creating badges for %d players ..." % len(players) start = datetime.now() data_time, render_time = 0,0 for player_id in players: req.matchdict['id'] = player_id sstart = datetime.now() playerdata.get_data(player_id) sstop = datetime.now() td = sstop-sstart data_time += datetime_seconds(td) sstart = datetime.now() for sk in skins:
else: players = DBSession.query(distinct(Player.player_id)).\ filter(Player.player_id == PlayerElo.player_id).\ filter(Player.player_id == PlayerGameStat.player_id).\ filter(PlayerGameStat.create_dt > cutoff_dt).\ filter(Player.nick != None).\ filter(Player.player_id > 2).\ filter(Player.active_ind == True).\ all() playerdata = PlayerData() if len(players) > 0: stop = datetime.now() td = stop - start print "Query took %.2f seconds" % (datetime_seconds(td)) print "Creating badges for %d players ..." % len(players) start = datetime.now() data_time, render_time = 0, 0 for player_id in players: req.matchdict['id'] = player_id sstart = datetime.now() playerdata.get_data(player_id) sstop = datetime.now() td = sstop - sstart data_time += datetime_seconds(td) sstart = datetime.now() for sk in skins: