Exemplo n.º 1
0
 def post(self):
     """
         POST request for League Leaders
         Route: Route['vleagueleaders']
         Parameters:
             year: the year  (int)
             stat: the stat to order by (str)
             group_by_team: whether to group by team or not (int)
                            default=True
         Returns:
             status: 200
             mimetype: application/json
             data: list of Players
     """
     year = None
     stat = None
     group_by_team = True
     args = parser.parse_args()
     if args['year']:
         year = args['year']
     if args['stat'] and hit_validator(args['stat']):
         stat = args['stat']
     else:
         raise InvalidField(payload={'details': 'Invalid stat'})
     if args['group_by_team'] == 0:
         group_by_team = False
     if group_by_team:
         players = get_leaders(stat, year=year)
     else:
         players = get_leaders_not_grouped_by_team(stat, year=year)
     return Response(dumps(players),
                     status=200,
                     mimetype="application/json")
Exemplo n.º 2
0
    def update(self,
               player_id=None,
               team_id=None,
               game_id=None,
               rbi=None,
               hit=None,
               inning=None):
        """Update an existing bat.

        Raises:
            TeamDoesNotExist
            GameDoesNotExist
            PlayerDoesNotExist
            InvalidField
        """
        if team_id is not None and Team.query.get(team_id) is not None:
            self.team_id = team_id
        elif team_id is not None:
            raise TeamDoesNotExist(payload={'details': team_id})
        if game_id is not None and Game.query.get(game_id) is not None:
            self.game_id = game_id
        elif game_id is not None:
            raise GameDoesNotExist(payload={'details': game_id})
        if player_id is not None and Player.query.get(player_id) is not None:
            self.player_id = player_id
        elif player_id is not None:
            raise PlayerDoesNotExist(payload={'details': player_id})
        if rbi is not None and rbi_validator(rbi):
            self.rbi = rbi
        elif rbi is not None:
            raise InvalidField(payload={'details': "Bat - rbi"})
        if hit is not None and hit_validator(hit):
            self.classification = hit
        elif hit is not None:
            raise InvalidField(payload={'details': "Bat - hit"})
        if inning is not None and inning_validator(inning):
            self.inning = inning
        elif inning is not None:
            raise InvalidField(payload={'details': "Bat - inning"})
Exemplo n.º 3
0
 def update(self,
            player_id=None,
            team_id=None,
            game_id=None,
            rbi=None,
            hit=None,
            inning=None):
     '''
     update a existing bat
     Raises:
         TeamDoesNotExist
         GameDoesNotExist
         PlayerDoesNotExist
         InvalidField
     '''
     if team_id is not None and Team.query.get(team_id) is not None:
         self.team_id = team_id
     elif team_id is not None:
         raise TeamDoesNotExist(payload={'details':team_id})
     if game_id is not None and Game.query.get(game_id) is not None:
         self.game_id = game_id
     elif game_id is not None:
         raise GameDoesNotExist(payload={'details':game_id})
     if player_id is not None and Player.query.get(player_id) is not None:
         self.player_id = player_id
     elif player_id is not None:
         raise PlayerDoesNotExist(payload={'details':player_id})
     if rbi is not None and rbi_validator(rbi):
         self.rbi = rbi
     elif rbi is not None:
         raise InvalidField(payload={'details':"Bat - rbi"})
     if hit is not None and hit_validator(hit):
         self.hit = hit
     elif hit is not None:
         raise InvalidField(payload={'details':"Bat - hit"})
     if inning is not None and inning_validator(inning):
         self.inning = inning
     elif inning is not None:
         raise InvalidField(payload={'details':"Bat - inning"})
Exemplo n.º 4
0
    def __init__(self,
                 player_id,
                 team_id,
                 game_id,
                 classification,
                 inning=1,
                 rbi=0):
        """The constructor.

        Raises:
            PlayerDoesNotExist
            InvalidField
            TeamDoesNotExist
            GameDoesNotExist
        """
        # check for exceptions
        classification = classification.lower().strip()
        player = Player.query.get(player_id)
        if player is None:
            raise PlayerDoesNotExist(payload={'details': player_id})
        if not hit_validator(classification, player.gender):
            raise InvalidField(payload={'details': "Bat - hit"})
        if not rbi_validator(rbi):
            raise InvalidField(payload={'details': "Bat - rbi"})
        if not inning_validator(inning):
            raise InvalidField(payload={'details': "Bat - inning"})
        if Team.query.get(team_id) is None:
            raise TeamDoesNotExist(payload={'details': team_id})
        if Game.query.get(game_id) is None:
            raise GameDoesNotExist(payload={'details': game_id})
        # otherwise good and a valid object
        self.classification = classification
        self.rbi = rbi
        self.player_id = player_id
        self.team_id = team_id
        self.game_id = game_id
        self.inning = inning
Exemplo n.º 5
0
 def __init__(self,
              player_id,
              team_id,
              game_id,
              classification,
              inning=1,
              rbi=0):
     '''
     Raises:
         PlayerDoesNotExist
         InvalidField
         TeamDoesNotExist
         GameDoesNotExist
     '''
     # check for exceptions
     classification = classification.lower().strip()
     player = Player.query.get(player_id)
     if player is None:
         raise PlayerDoesNotExist(payload={'details':player_id})
     if not hit_validator(classification, player.gender):
         raise InvalidField(payload={'details':"Bat - hit"})
     if not rbi_validator(rbi):
         raise InvalidField(payload={'details':"Bat - rbi"})
     if not inning_validator(inning):
         raise InvalidField(payload={'details':"Bat - inning"})
     if Team.query.get(team_id) is None:
         raise TeamDoesNotExist(payload={'details':team_id})
     if Game.query.get(game_id) is None:
         raise GameDoesNotExist(payload={'details':game_id})
     # otherwise good and a valid object
     self.classification = classification
     self.rbi = rbi
     self.player_id = player_id
     self.team_id = team_id
     self.game_id = game_id
     self.inning = inning
Exemplo n.º 6
0
 def testHitValidator(self):
     test = 1
     self.assertEqual(hit_validator(test), False,
                      'Hit Validator: 1 was a valid Hit')
     test = "X"
     self.assertEqual(hit_validator(test), False,
                      'Hit Validator: X was a valid Hit')
     test = "S"
     self.assertEqual(hit_validator(test), True,
                      'Hit Validator: S was a invalid Hit')
     test = "ss"
     self.assertEqual(
         hit_validator(test), False,
         'Hit Validator:' + 'SS was a valid Hit for a non-specified gender')
     test = "ss"
     self.assertEqual(hit_validator(test, gender='f'), True,
                      'Hit Validator:' + 'SS was a invalid Hit for a girl')
     test = "ss"
     self.assertEqual(hit_validator(test, gender="m"), False,
                      'Hit Validator: SS was a invalid Hit for a guy')
     test = "hr"
     self.assertEqual(hit_validator(test, gender="m"), True,
                      'Hit Validator: HR was a invalid Hit for a guy')