Exemplo n.º 1
0
 def test_result_choices_to_dict(self):
     self.assertEqual(ChoicesFormatter.result_choices_to_dict(), {
         '選択': '',
         '勝': 1,
         '負': 2,
         '分': 3
     })
Exemplo n.º 2
0
    def create_previous_game_pitched(self) -> float:
        """1試合前に投げたイニングを取得する

        Returns:
            float: 1試合前に投げたイニングを返す ex)7.2

        Notes:
            練習試合、または登板していない場合は0を返す
        """
        competition_choices = c.competition_choices_to_dict()
        # GamesとPitcherResultsは必ず存在するのでチェックしない
        if Games.objects.latest(
                'pk').competition_type == competition_choices['練習試合']:
            return 0

        previous_game = Games.objects.filter(
            competition_type__gt=competition_choices['練習試合']).latest('pk')
        pr = PitcherResults.objects.select_related(
            'player_id', 'game_id').filter(game_id=previous_game,
                                           player_id=self.player_id)

        if pr.exists():
            pr_latest = pr.latest('pk')
            return p.innings_conversion_for_display(
                pr_latest.innings_pitched, pr_latest.innings_pitched_fraction)
        else:
            return 0
Exemplo n.º 3
0
 def test_unique_key_check(self):
     """(year, period)"""
     period = ChoicesFormatter.period_choices_to_dict()
     Teams(year=1985, period=period['夏']).save()
     Teams(year=1985, period=period['秋']).save()
     self.assertEqual(Teams.objects.count(), 2)
     with self.assertRaises(Exception):
         Teams(year=1985, period=period['夏']).save()
Exemplo n.º 4
0
 def test_unique_key_check(self):
     """team_id"""
     period = ChoicesFormatter.period_choices_to_dict()
     Teams(year=1985, period=period['夏']).save()
     Teams(year=1985, period=period['秋']).save()
     t1 = Teams.objects.get(year=1985, period=period['夏'])
     with self.assertRaises(Exception):
         TeamTotalResults(team=t1).save()
Exemplo n.º 5
0
 def test_rank_choices_to_dict(self):
     self.assertEqual(ChoicesFormatter.rank_choices_to_dict(), {
         '選択': '',
         '弱小': 1,
         'そこそこ': 2,
         '中堅': 3,
         '強豪': 4,
         '名門': 5
     })
Exemplo n.º 6
0
 def test_competition_choices_to_dict(self):
     self.assertEqual(ChoicesFormatter.competition_choices_to_dict(), {
         '選択': '',
         '練習試合': 1,
         '県大会': 2,
         '地区大会': 3,
         '甲子園': 4,
         'センバツ': 5
     })
Exemplo n.º 7
0
 def test_is_sable_auto_update(self):
     """is_disable_auto_update=Falseの場合、各種自動更新を行う"""
     period = ChoicesFormatter.period_choices_to_dict()
     ModelSettings(is_disable_auto_update=False).save()
     Teams(year=1985, period=period['夏']).save()
     self.assertEqual(TeamsTotalResultsTests.objects.count(), 1)
     Players(admission_year=1985, name="桑田", position=1).save()
     self.assertEqual(FielderTotalResults.objects.count(), 1)
     self.assertEqual(PitcherTotalResults.objects.count(), 1)
Exemplo n.º 8
0
 def test_position_choices_to_dict(self):
     self.assertEqual(ChoicesFormatter.position_choices_to_dict(), {
         '選択': '',
         '投': 1,
         '捕': 2,
         '一': 3,
         '二': 4,
         '三': 5,
         '遊': 6,
         '外': 7
     })
Exemplo n.º 9
0
 def test_round_choices_to_dict(self):
     self.assertEqual(
         ChoicesFormatter.round_choices_to_dict(), {
             '選択': '',
             '練習試合': 1,
             '1回戦': 2,
             '2回戦': 3,
             '3回戦': 4,
             '準々決勝': 5,
             '準決勝': 6,
             '決勝': 7
         })
Exemplo n.º 10
0
 def test_unique_key_check(self):
     """(game_id, player_id)"""
     period = ChoicesFormatter.period_choices_to_dict()
     competition_choices = ChoicesFormatter.competition_choices_to_dict()
     round_choices = ChoicesFormatter.round_choices_to_dict()
     # データセット
     Teams(year=1985, period=period['夏']).save()
     t1 = Teams.objects.latest('pk')
     Players(admission_year=1985, name="桑田", position=1).save()
     Players(admission_year=1985, name="清原", position=1).save()
     Games(team_id=t1,
           competition_type=competition_choices['県大会'],
           competition_round=round_choices['1回戦'],
           score=1,
           run=0).save()
     g1 = Games.objects.latest('pk')
     p1 = Players.objects.get(name="桑田")
     p2 = Players.objects.get(name="清原")
     PitcherResults(game_id=g1, player_id=p1).save()
     PitcherResults(game_id=g1, player_id=p2).save()
     self.assertEqual(PitcherResults.objects.count(), 2)
     with self.assertRaises(Exception):
         PitcherResults(game_id=g1, player_id=p1).save()
Exemplo n.º 11
0
    def test_create_default_competition_type(self):
        """
        現在のチームに紐づくGamesのレコードが存在しない場合 -> 2(県大会)
        現在のそのチームに紐づくGamesのレコードが存在する場合
            最新が練習試合 -> 2(県大会)
            練習試合以外 -> 基本は同じ値を設定する
                例外:
                    夏 and 県大会 and 決勝 and 勝 であれば次は甲子園
                    秋 and 県大会 and 2回戦 and 勝 であれば次は地区大会
                    秋 and 地区大会 and 2回戦 であれば次はセンバツ
                妥協:
                    1回戦、3回戦がない場合は考慮しない
        """
        period = ChoicesFormatter.period_choices_to_dict()
        competition_choices = ChoicesFormatter.competition_choices_to_dict()
        round_choices = ChoicesFormatter.round_choices_to_dict()

        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])
        # 夏のチーム
        Teams(year=1985, period=period['夏']).save()

        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        t1 = Teams.objects.latest('pk')
        Games(team_id=t1,
              competition_type=competition_choices['練習試合'],
              competition_round=round_choices['練習試合']).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        Games(team_id=t1,
              competition_type=competition_choices['県大会'],
              competition_round=round_choices['2回戦'],
              score=1,
              run=0).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        Games(team_id=t1,
              competition_type=competition_choices['県大会'],
              competition_round=round_choices['2回戦'],
              score=0,
              run=1).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        Games(team_id=t1,
              competition_type=competition_choices['県大会'],
              competition_round=round_choices['決勝'],
              score=1,
              run=0).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['甲子園'])

        Games(team_id=t1,
              competition_type=competition_choices['県大会'],
              competition_round=round_choices['決勝'],
              score=0,
              run=1).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        # 秋のチーム
        Teams(year=1985, period=period['秋']).save()
        t2 = Teams.objects.latest('pk')
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        Games(team_id=t2,
              competition_type=competition_choices['県大会'],
              competition_round=round_choices['2回戦'],
              score=0,
              run=1).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['県大会'])

        Games(team_id=t2,
              competition_type=competition_choices['県大会'],
              competition_round=round_choices['2回戦'],
              score=1,
              run=0).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['地区大会'])

        Games(team_id=t2,
              competition_type=competition_choices['地区大会'],
              competition_round=round_choices['2回戦'],
              score=0,
              run=1).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['地区大会'])

        Games(team_id=t2,
              competition_type=competition_choices['地区大会'],
              competition_round=round_choices['2回戦'],
              score=1,
              run=0).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['センバツ'])

        Games(team_id=t2,
              competition_type=competition_choices['センバツ'],
              competition_round=round_choices['2回戦'],
              score=1,
              run=0).save()
        self.assertEqual(
            DefaultValueExtractor.create_default_competition_type(),
            competition_choices['センバツ'])
Exemplo n.º 12
0
 def test_period_choices_to_dict(self):
     self.assertEqual(ChoicesFormatter.period_choices_to_dict(), {
         '選択': '',
         '夏': 1,
         '秋': 2
     })