Exemple #1
0
    def get_map(self, id):
        '''
        Provides details for a specific map based on the given map identifier.

        Args:
           id (string): The unique identifier of a map.

        Returns:
            map (object): Detailed information for a specific map.
        '''

        # Get the model for the requested map
        map_obj = model_mgr.get_map(id)
        if not map_obj: raise cherrypy.HTTPError(404)

        # Get the stats for the requested map
        map_stats = stat_mgr.get_map_stats(map_obj)

        # Build a list of column descriptors
        columns = [{
            'name': 'Players',
            'data': 'player'
        }, {
            'name': 'Score',
            'data': 'number',
            'sorted': False
        }, {
            'name': 'Kills',
            'data': 'number'
        }, {
            'name': 'Deaths',
            'data': 'number'
        }]

        # Build a list of map statistics
        rows = list()
        for player in map_stats.players:
            if player != models.players.EMPTY:
                object_stats = map_stats.players[player]
                player_tuple = {
                    'id': player.id,
                    'name': player.name,
                    'photo': player.photo_s
                }
                rows.append([
                    player_tuple, object_stats.score, object_stats.kills,
                    object_stats.deaths
                ])

        # Sort the results by score
        rows.sort(key=lambda r: r[1], reverse=True)

        return {
            'id': map_obj.id,
            'name': map_obj.name,
            'columns': columns,
            'rows': rows
        }
Exemple #2
0
    def on_score(self, e):

        # Get the current map
        current_game = model_mgr.get_game()
        current_map = model_mgr.get_map(current_game.map_id)
        map_stats = stat_mgr.get_map_stats(current_map)

        # Increment the total map score
        map_stats.score += e.value

        # Increment score count for the player
        if not e.player in map_stats.players:
            map_stats.players[e.player] = MapItemStats()
        map_stats.players[e.player].score += e.value
Exemple #3
0
    def on_death(self, e):

        # Get the current map
        current_game = model_mgr.get_game()
        current_map = model_mgr.get_map(current_game.map_id)
        map_stats = stat_mgr.get_map_stats(current_map)

        # Increment the total map deaths
        map_stats.deaths += 1

        # Increment the player deaths
        if not e.player in map_stats.players:
            map_stats.players[e.player] = MapItemStats()
        map_stats.players[e.player].deaths += 1
Exemple #4
0
    def on_kill(self, e):

        # Ignore suicides and team kills
        if not e.valid_kill:
            return

        # Get the current map
        current_game = model_mgr.get_game()
        current_map = model_mgr.get_map(current_game.map_id)
        map_stats = stat_mgr.get_map_stats(current_map)

        # Increment the total map kills
        map_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in map_stats.players:
            map_stats.players[e.attacker] = MapItemStats()
        map_stats.players[e.attacker].kills += 1
Exemple #5
0
    def get_map(self, id):
        '''
        Provides details for a specific map based on the given map identifier.

        Args:
           id (string): The unique identifier of a map.

        Returns:
            map (object): Detailed information for a specific map.
        '''

        # Get the model for the requested map
        map_obj = model_mgr.get_map(id)
        if not map_obj: raise cherrypy.HTTPError(404)

        # Get the stats for the requested map
        map_stats = stat_mgr.get_map_stats(map_obj)

        # Build a list of column descriptors
        columns = [{ 'name': 'Players', 'data': 'player' },
                { 'name': 'Score', 'data': 'number', 'sorted': False },
                { 'name': 'Kills', 'data': 'number' },
                { 'name': 'Deaths', 'data': 'number' }]

        # Build a list of map statistics
        rows = list()
        for player in map_stats.players:
            if player != models.players.EMPTY:
                object_stats = map_stats.players[player]
                player_tuple = {
                    'id': player.id,
                    'name': player.name,
                    'photo': player.photo_s
                }
                rows.append([player_tuple, object_stats.score,
                        object_stats.kills, object_stats.deaths])

        # Sort the results by score
        rows.sort(key=lambda r: r[1], reverse=True)

        return { 'id': map_obj.id, 'name': map_obj.name, 'columns' : columns,
                'rows': rows }