示例#1
0
    def from_api_data(cls, raw_matchup_info, team_id):
        now = datetime.now()
        week_start = datetime.strptime(raw_matchup_info['week_start'],
                                       "%Y-%m-%d")
        week_end = datetime.strptime(raw_matchup_info['week_end'], "%Y-%m-%d")
        has_started = (week_start < now)
        is_complete = (week_end < now)
        is_tied = None if not is_complete else bool(
            raw_matchup_info['is_tied'])

        matchup_kwargs = {
            'week' : raw_matchup_info['week'],
            'week_start' : week_start,
            'week_end' : week_end,
            'has_started' : has_started,
            'is_complete' : is_complete,
            'is_tied' : is_tied,
            'won' : None if (not is_complete or is_tied)\
                else bool(raw_matchup_info['winner_team_key'][(raw_matchup_info['winner_team_key'].rfind(".") + 1):] == team_id),
            'stats' : None if not has_started else Stats.from_api_data(raw_matchup_info['stats'])
        }

        return cls(**matchup_kwargs)
示例#2
0
    def test_from_api_data(self):
        stats_dict = {"stats": [
            {
                "stat": {
                    "stat_id": "1",
                    "value": "8"
                }
            },
            {
                "stat": {
                    "stat_id": "2",
                    "value": "16"
                }
            },
            {
                "stat": {
                    "stat_id": "5",
                    "value": "20"
                }
            },
            {
                "stat": {
                    "stat_id": "14",
                    "value": "97"
                }
            },
            {
                "stat": {
                    "stat_id": "31",
                    "value": "27"
                }
            },
            {
                "stat": {
                    "stat_id": "32",
                    "value": "33"
                }
            },
            {
                "stat": {
                    "stat_id": "19",
                    "value": "2"
                }
            },
            {
                "stat": {
                    "stat_id": "22",
                    "value": "2"
                }
            },
            {
                "stat": {
                    "stat_id": "23",
                    "value": "1.00"
                }
            },
            {
                "stat": {
                    "stat_id": "24",
                    "value": "45"
                }
            },
            {
                "stat": {
                    "stat_id": "27",
                    "value": "0"
                }
            }
        ]}

        result = Stats.from_api_data(stats_dict['stats'])
        self.assertEqual(result.goals, 8)
        self.assertEqual(result.assists, 16)
        self.assertEqual(result.penalty_minutes, 20)
        self.assertEqual(result.shots_on_goal, 97)
        self.assertEqual(result.hits, 27)
        self.assertEqual(result.blocks, 33)
        self.assertEqual(result.wins, 2)
        self.assertEqual(result.goalie_ga, 2)
        self.assertEqual(result.goalie_gaa, 1.00)
        self.assertEqual(result.goalie_sa, 45)
        self.assertEqual(result.goalie_so, 0)