Exemplo n.º 1
0
    def test_update_9_teams_3_fields(self):
        gameday = DBSetup().create_empty_gameday()
        gameday.format = "9_3"
        gameday.save()
        group_A = DBSetup().create_teams('A', 3)
        group_B = DBSetup().create_teams('B', 3)
        group_C = DBSetup().create_teams('C', 3)
        groups = [group_A, group_B, group_C]
        DBSetup().create_playoff_placeholder_teams()
        sc = ScheduleCreator(gameday=Gameday.objects.get(pk=gameday.pk),
                             schedule=Schedule(gameday.format, groups))
        sc.create()

        qualify_games = Gameinfo.objects.filter(stage='Vorrunde')
        for game in qualify_games:
            update_gameresults(game)
        Gameinfo.objects.filter(stage='Vorrunde').update(status='beendet')

        su = ScheduleUpdate(gameday.pk, gameday.format)
        su.update()
        check_if_first_standing('PO').is_updated_as_expected_with(
            'B2', 'C2', 'C3')
        check_if_first_standing('P7').is_updated_as_expected_with(
            'A1', 'B1', 'B3')

        update_gameresults_by_standing_and_finish_game_for('PO')
        update_gameresults_and_finish_first_game_for_P7()
        su.update()
        check_if_first_standing('HF').is_updated_as_expected_with(
            'C2', 'C3', 'B2')
        check_if_first_standing('P7').is_updated_as_expected_with(
            'B1', 'C1', 'A2')
        check_if_first_standing('P5').is_updated_as_expected_with(
            'A2', 'B2', 'B1')

        update_gameresults_by_standing_and_finish_game_for('HF')
        update_gameresults_and_finish_first_game_for_P7()
        su.update()
        check_if_first_standing('P7').is_updated_as_expected_with(
            'C1', 'A1', 'C2')
        check_if_first_standing('P1').is_updated_as_expected_with(
            'B3', 'C3', 'A1')
        check_if_first_standing('P3').is_updated_as_expected_with(
            'A3', 'C2', 'C1')

        update_gameresults_by_standing_and_finish_game_for('P5')
        update_gameresults_and_finish_first_game_for_P7()
        update_gameresults_by_standing_and_finish_game_for('P3')
        update_gameresults_by_standing_and_finish_game_for('P1')

        gmw = GamedayModelWrapper(gameday.pk)
        DataFrameAssertion.expect(
            gmw.get_final_table()).to_equal_json('final_table_9_teams.json')
        DataFrameAssertion.expect(
            gmw.get_schedule()).to_equal_json('schedule_9_teams_3_fields.json')
Exemplo n.º 2
0
 def get_all_schedules(self):
     season = Season.objects.last()
     all_gamedays = Gameday.objects.filter(season__name=season)
     all_schedules = pd.DataFrame()
     for gameday in all_gamedays:
         try:
             gmw = GamedayModelWrapper(gameday.pk,
                                       ['gameday__name', 'gameday__date'])
             all_schedules = all_schedules.append(gmw.get_schedule(),
                                                  ignore_index=True)
         except Gameinfo.DoesNotExist:
             pass
     columns = [
         GAMEDAY_NAME, GAMEDAY_ID, SCHEDULED, OFFICIALS_NAME, GAMEINFO_ID,
         HOME, AWAY, STANDING, STAGE
     ]
     return all_schedules[columns]
Exemplo n.º 3
0
class GamedayService:
    @classmethod
    def create(cls, gameday_pk):
        try:
            return cls(gameday_pk)
        except Gameinfo.DoesNotExist:
            return EmptyGamedayService

    def __init__(self, pk):
        self.gmw = GamedayModelWrapper(pk)

    def get_schedule(self):
        schedule = self.gmw.get_schedule()
        columns = [SCHEDULED, FIELD, HOME, POINTS_HOME, POINTS_AWAY, AWAY, OFFICIALS_NAME, STANDING, STAGE, STATUS]
        schedule = schedule[columns]
        schedule[OFFICIALS_NAME] = schedule[OFFICIALS_NAME].apply('<i>{}</i>'.format)
        schedule[SCHEDULED] = pd.to_datetime(schedule[SCHEDULED], format='%H:%M:%S').dt.strftime('%H:%M')

        schedule = schedule.rename(columns=SCHEDULE_TABLE_HEADERS)
        return schedule

    def get_qualify_table(self):
        qualify_table = self.gmw.get_qualify_table()
        if qualify_table is '':
            return EmptyQualifyTable
        qualify_table = qualify_table[[STANDING, TEAM_NAME, POINTS, PF, PA, DIFF]]
        qualify_table = qualify_table.rename(columns=TABLE_HEADERS)
        return qualify_table

    def get_final_table(self):
        final_table = self.gmw.get_final_table()
        if final_table.empty:
            return final_table
        final_table = final_table[[DFFL, TEAM_NAME, POINTS, PF, PA, DIFF]]
        final_table = final_table.rename(columns=TABLE_HEADERS)
        return final_table

    def get_games_to_whistle(self, team):
        if team == '*':
            team = ''
        games_to_whistle = self.gmw.get_games_to_whistle(team)
        columns = [SCHEDULED, FIELD, OFFICIALS_NAME, STAGE, STANDING, HOME, POINTS_HOME, POINTS_AWAY, AWAY,
                   STATUS, ID_HOME, ID_AWAY, 'id']
        games_to_whistle = games_to_whistle[columns]
        games_to_whistle = games_to_whistle.rename(columns={OFFICIALS_NAME: OFFICIALS})
        return games_to_whistle