예제 #1
0
파일: teams.py 프로젝트: Hagrid78/bf2-stats
    def get_team(self, id):
        '''
        Provides details for a specific team based on the given team identifier.

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

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

        # Get the model for the requested team
        team = model_mgr.get_team(id)
        if not team: raise cherrypy.HTTPError(404)

        # Get the stats for the requested team
        team_stats = stat_mgr.get_team_stats(team)

        # 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 team statistics
        rows = list()
        for player in team_stats.players:
            if player != models.players.EMPTY:
                object_stats = team_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': team.id,
            'name': team.name,
            'columns': columns,
            'rows': rows
        }
예제 #2
0
    def on_score(self, e):

        # Get the team for the player
        player_team = model_mgr.get_team(e.player.team_id)
        team_stats = stat_mgr.get_team_stats(player_team)

        # Increment the total team score
        team_stats.score += e.value

        # Increment score count for the player
        if not e.player in team_stats.players:
            team_stats.players[e.player] = TeamItemStats()
        team_stats.players[e.player].score += e.value
예제 #3
0
    def on_death(self, e):

        # Get the team for the player
        player_team = model_mgr.get_team(e.player.team_id)
        team_stats = stat_mgr.get_team_stats(player_team)

        # Increment the total team deaths
        team_stats.deaths += 1

        # Increment the player deaths
        if not e.player in team_stats.players:
            team_stats.players[e.player] = TeamItemStats()
        team_stats.players[e.player].deaths += 1
예제 #4
0
    def on_score(self, e):

        # Get the team for the player
        player_team = model_mgr.get_team(e.player.team_id)
        team_stats = stat_mgr.get_team_stats(player_team)

        # Increment the total team score
        team_stats.score += e.value

        # Increment score count for the player
        if not e.player in team_stats.players:
            team_stats.players[e.player] = TeamItemStats()
        team_stats.players[e.player].score += e.value
예제 #5
0
    def on_death(self, e):

        # Get the team for the player
        player_team = model_mgr.get_team(e.player.team_id)
        team_stats = stat_mgr.get_team_stats(player_team)

        # Increment the total team deaths
        team_stats.deaths += 1

        # Increment the player deaths
        if not e.player in team_stats.players:
            team_stats.players[e.player] = TeamItemStats()
        team_stats.players[e.player].deaths += 1
예제 #6
0
    def on_kill(self, e):

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

        # Get the team for the attacker
        attacker_team = model_mgr.get_team(e.attacker.team_id)
        team_stats = stat_mgr.get_team_stats(attacker_team)

        # Increment the total team kills
        team_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in team_stats.players:
            team_stats.players[e.attacker] = TeamItemStats()
        team_stats.players[e.attacker].kills += 1
예제 #7
0
    def on_kill(self, e):

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

        # Get the team for the attacker
        attacker_team = model_mgr.get_team(e.attacker.team_id)
        team_stats = stat_mgr.get_team_stats(attacker_team)

        # Increment the total team kills
        team_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in team_stats.players:
            team_stats.players[e.attacker] = TeamItemStats()
        team_stats.players[e.attacker].kills += 1
예제 #8
0
    def get_team(self, id):
        """
        Provides details for a specific team based on the given team identifier.

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

        Returns:
            team (object): Detailed information for a specific team.
        """

        # Get the model for the requested team
        team = model_mgr.get_team(id)
        if not team:
            raise cherrypy.HTTPError(404)

        # Get the stats for the requested team
        team_stats = stat_mgr.get_team_stats(team)

        # 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 team statistics
        rows = list()
        for player in team_stats.players:
            if player != models.players.EMPTY:
                object_stats = team_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": team.id, "name": team.name, "columns": columns, "rows": rows}