Exemple #1
0
    def __init__(self, sport):
        self.sport = sport
        self.verbose = False
        self.debug_limit = 0
        self.pbp_parent_api = 'pbp'
        self.stats_parent_api = 'stats'
        self.delay_seconds = 5
        self.delay_seconds_behind = 0

        ssm = SiteSportManager()
        self.site_sport = ssm.get_site_sport(self.sport)
        self.player_class = ssm.get_player_class(self.site_sport)
    def handle(self, *args, **options):
        """
        calculate a single players salary (for debugging purposes) using
        the sports main salary algorithm.

        this command will infer the sport using SiteSportManager
        so all that needs to be specified is the player srid!
        """

        # collect the player srids passed as arguments
        player_srids = []
        for srid in options['player']:
            player_srids.append(srid)

        player_srid = player_srids[0] # get the first one
        print('looking for player:', str(player_srid))

        # find the sports.<sport>.models.Player object
        ssm = SiteSportManager()
        player = None
        site_sport = None # the sport (the string name) of the sport the player was found in
        for sport in SiteSportManager.SPORTS:
            site_sport = ssm.get_site_sport(sport)
            player_class = ssm.get_player_class(site_sport)
            try:
                player = player_class.objects.get(srid=player_srid)
                break
            except player_class.DoesNotExist:
                #self.stdout.write('checked %s for Player object but they werent found'%sport)
                pass

        # hopefully we found the player by now
        if player is None:
            self.stdout.write('player [%s] not found in any sport!' % player_srid)
            return
        # else:
        #     self.stdout.write('player:', str(player))

        # generate the salary for this player specifically, printing out all the player stats
        # objects used and the weighting involved in the calculations for debugging purposes.
        sg = SportSalaryGenerator(sport=site_sport.name, debug_srid=player_srid)
        sg.generate_salaries()
Exemple #3
0
    def get_player_array_from_player_ids_array(player_ids, site_sport):
        """
        Creates and returns an array of :class:`sports.models.Player` objects based
        on the player_ids array.

        :param player_ids: an ordered list of :class:`sports.models.Player` ids
            for the lineup.
        :return: an array of :class:`sports.models.Player` objects

        :raise :class:`lineup.exception.DuplicatePlayerException`: If there are
            duplicate ids in the player_ids list
        """
        ssm = SiteSportManager()
        player_class = ssm.get_player_class(site_sport)

        #
        # Check if there are duplicate players
        if len(set(player_ids)) != len(player_ids):
            raise DuplicatePlayerException()

        players = player_class.objects.filter(pk__in=player_ids)
        return sorted(players, key=lambda player: player_ids.index(player.pk))
Exemple #4
0
    def create_player_stats_model(self, game_srid, player_srid,
                                  my_player_stats_instance):
        """
        create a new PlayerStats model instance from the fields of the 'mongo_obj'
        :param mongo_obj:
        :return:
        """

        site_sport_manager = SiteSportManager()
        site_sport = site_sport_manager.get_site_sport('nfl')
        player_model_class = site_sport_manager.get_player_class(site_sport)
        game_model_class = site_sport_manager.get_game_class(site_sport)

        try:
            player = player_model_class.objects.get(srid=player_srid)
        except player_model_class.DoesNotExist:
            # if they were never in the database, they wont be in draft group and we should not
            # deal with that here! - Probably means they are defensive players.
            return

        player_stats_model_class = self.get_player_stats_model_class()

        # get new instance
        player_stats = player_stats_model_class()

        # set all properties with these fieldnames to 0
        player_stats.position = player.position  # use the position from their Player object
        player_stats.srid_game = game_srid
        player_stats.game = game_model_class.objects.get(srid=game_srid)
        player_stats.srid_player = player_srid
        player_stats.player = player

        for fieldname, var in my_player_stats_instance.get_vars().items():
            setattr(player_stats, fieldname, var)
            player_stats.save()

        logger.info(
            'Missing PlayerStats model created for player: %s | srid: %s' %
            (player, player_srid))
 def get_player_model_class(self):
     if self.player_model_class is None:
         ssm = SiteSportManager()
         site_sport = ssm.get_site_sport(self.sport)
         self.player_model_class = ssm.get_player_class(site_sport)
     return self.player_model_class
 def get_player_model_class(self, sport):
     ssm = SiteSportManager()
     site_sport = ssm.get_site_sport(sport)
     sport_player_model_class = ssm.get_player_class(site_sport)
     return sport_player_model_class