def run(self): timeout = 2 round_ = None while not self.stopped(): try: stat = live_stats_queue.get(True, 2) except Queue.Empty: continue if stat['type'] == 'kill': # Detect if is an autokill !!! # Check rank player = stat['data']['killer'] round_ = stat['data']['round'] if round_ is None: continue data = {} data['kstats'], data['vstats'], data['pstats'] = get_player_stats(player) score = get_player_score(player, data) if score > 0 and score in [x[1] for x in ranks]: # New rank new_rank = get_rank(player, data) rank_name = ranks[new_rank][0] msg = """%s is now "%s" """ % (player, rank_name) econ_command_queue.put({'type': 'broadcast', 'data': {'message': msg}}) # Check live achievements for key, achievement in achievement_livestat_list.items(): achievement(stat['data']) if stat['type'] == 'join': player = stat['data']['player'] rank = get_rank(player) rank_name = ranks[rank][0] msg = "WELCOME to the '%s' %s" % (rank_name, player) econ_command_queue.put({'type': 'broadcast', 'data': {'message': msg}})
def ladder(sort='score', context={}, gametype=None): context['page'] = 'ladder' context['sort'] = sort if sort not in ['kills', 'suicides', 'deaths', 'score', 'ratio', 'nickname']: redirect("/ladder") stats_by_players = get_stats(selected_gametype=gametype) stats_by_players = [(p, {'kills': sum(data['kills'].values()), 'suicides': data['suicides'], 'deaths': data['deaths'], 'rank': get_rank(p, data['score']), 'score': data['score'], 'ratio': sum(data['kills'].values()) / float(data['deaths']) if float(data['deaths']) != 0 else 0, } ) for p, data in stats_by_players.items()] if sort == 'nickname': context['stats_by_players'] = sorted([x for x in stats_by_players], key=lambda x: x[0]) else: context['stats_by_players'] = sorted([x for x in stats_by_players], key=lambda x: x[1][sort], reverse=True) return context
def player_stats(player=None, context={}, gametype=None): # session = request.environ.get('beaker.session') # gametype = session.get('gametype', None) # context['select_gametype'] = gametype if request.method == 'POST': player = request.params['player'] # Test player exists if not player in get_player_list(): context["not_found"] = player return context # context['fullserverstatus'] = twms.get_server_info() # if context['fullserverstatus']: # context['playernames'] = ", ".join([x['name'] for x in context['fullserverstatus']['players']]) # context['gametype'] = context['fullserverstatus']['gametype'] context['player'] = player context['kill_mapping'] = kill_mapping context['pickup_mapping'] = pickup_mapping context['pstats'] = get_player_items_stats(player) player_stats = get_stats(player, gametype) # context['kstats'] = player_stats['kills'] # context['vstats'] = player_stats['victims'] # TODO integrate weapon stats in get_stat function context['kstats'], context['vstats'], context['pstats'] = get_player_stats(player) context['kills'] = sum(player_stats.get('kills', {None: 0}).values()) context['suicides'] = player_stats.get('suicides', 0) context['rounds'] = player_stats.get('rounds', 0) context['teamkills'] = sum(player_stats.get('teamkills', {None: 0}).values()) context['flaggrab'] = player_stats.get('flaggrab', 0) context['flagreturn'] = player_stats.get('flagreturn', 0) context['flagcapture'] = player_stats.get('flagcapture', 0) context['score'] = player_stats['score'] context['deaths'] = player_stats['deaths'] context['ratio'] = context['kills'] / float(context['deaths']) if context['deaths'] > 0 else 0 rank_level = get_rank(player, context['score']) context['rank'] = (rank_level, ranks[rank_level][0], ranks[rank_level][1]) context['nextrank'] = (rank_level + 1, ranks[rank_level + 1][0], ranks[rank_level + 1][1]) context['map_list'] = dict([(x['name'], x['map']) for x in get_maps()]) # Favorite try: context['favorite_map'] = sorted([x for x in player_stats['maps'].items()], key=lambda x: x[1], reverse=True)[0] except: context['favorite_map'] = ("No data", 0) try: context['favorite_victim'] = sorted([x for x in context['kstats']['victim'].items()], key=lambda x: x[1], reverse=True)[0] except: context['favorite_victim'] = ("No data", 0) try: context['favorite_killer'] = sorted([x for x in context['vstats']['killer'].items()], key=lambda x: x[1], reverse=True)[0] except: context['favorite_killer'] = ("No data", 0) try: context['favorite_weapon'] = sorted([x for x in context['kstats']['weapon'].items()], key=lambda x: x[1], reverse=True)[0] except: context['favorite_weapon'] = ("No data", 0) # Places context['first_place'] = player_stats.get('first_place', 0) context['second_place'] = player_stats.get('second_place', 0) context['third_place'] = player_stats.get('third_place', 0) context['last_place'] = player_stats.get('last_place', 0) context['achievement_list'] = {} for achievement in achievement_player_list.items(): context['achievement_list'][achievement[0]] = achievement[1](player, gametype) return context