コード例 #1
0
ファイル: vehicles.py プロジェクト: Hagrid78/bf2-stats
    def get_vehicle(self, id):
        '''
        Provides details for a specific vehicle based on the given vehicle
        identifier.

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

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

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

        # Get the stats for the requested vehicle
        vehicle_stats = stat_mgr.get_vehicle_stats(vehicle)

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

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

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

        return {
            'id': vehicle.id,
            'name': vehicle.name,
            'columns': columns,
            'rows': rows
        }
コード例 #2
0
    def on_death(self, e):

        # Get the vehicle used by the player
        vehicle_id = None
        if e.player in self.vehicles:
            vehicle_id = self.vehicles[e.player]
            del self.vehicles[e.player]
        player_vehicle = model_mgr.get_vehicle(vehicle_id)
        vehicle_stats = stat_mgr.get_vehicle_stats(player_vehicle)

        # Increment the total vehicle deaths
        vehicle_stats.deaths += 1

        # Increment the player deaths
        if not e.player in vehicle_stats.players:
            vehicle_stats.players[e.player] = VehicleItemStats()
        vehicle_stats.players[e.player].deaths += 1
コード例 #3
0
    def on_death(self, e):

        # Get the vehicle used by the player
        vehicle_id = None
        if e.player in self.vehicles:
            vehicle_id = self.vehicles[e.player]
            del self.vehicles[e.player]
        player_vehicle = model_mgr.get_vehicle(vehicle_id)
        vehicle_stats = stat_mgr.get_vehicle_stats(player_vehicle)

        # Increment the total vehicle deaths
        vehicle_stats.deaths += 1

        # Increment the player deaths
        if not e.player in vehicle_stats.players:
            vehicle_stats.players[e.player] = VehicleItemStats()
        vehicle_stats.players[e.player].deaths += 1
コード例 #4
0
ファイル: vehicles.py プロジェクト: chrisw1229/bf2-stats
    def get_vehicle(self, id):
        '''
        Provides details for a specific vehicle based on the given vehicle
        identifier.

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

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

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

        # Get the stats for the requested vehicle
        vehicle_stats = stat_mgr.get_vehicle_stats(vehicle)

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

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

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

        return { 'id': vehicle.id, 'name': vehicle.name, 'columns' : columns,
                'rows': rows }
コード例 #5
0
    def on_kill(self, e):

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

        # Store the vehicle of the victim for future use
        if e.victim.vehicle_id:
            self.vehicles[e.victim] = e.victim.vehicle_id

        # Get the vehicle for the attacker
        attacker_vehicle = model_mgr.get_vehicle(e.attacker.vehicle_id)
        attacker_vehicle_stats = stat_mgr.get_vehicle_stats(attacker_vehicle)

        # Increment the total vehicle kills
        attacker_vehicle_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in attacker_vehicle_stats.players:
            attacker_vehicle_stats.players[e.attacker] = VehicleItemStats()
        attacker_vehicle_stats.players[e.attacker].kills += 1
コード例 #6
0
    def on_kill(self, e):

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

        # Store the vehicle of the victim for future use
        if e.victim.vehicle_id:
            self.vehicles[e.victim] = e.victim.vehicle_id

        # Get the vehicle for the attacker
        attacker_vehicle = model_mgr.get_vehicle(e.attacker.vehicle_id)
        attacker_vehicle_stats = stat_mgr.get_vehicle_stats(attacker_vehicle)

        # Increment the total vehicle kills
        attacker_vehicle_stats.kills += 1

        # Increment the attacker kills
        if not e.attacker in attacker_vehicle_stats.players:
            attacker_vehicle_stats.players[e.attacker] = VehicleItemStats()
        attacker_vehicle_stats.players[e.attacker].kills += 1