コード例 #1
0
    def _gen_team_shot_range_md(self):
        update_zone(self.shot_df)
        update_range(self.shot_df)

        result_str_list = list()
        team_shot_range_df = self.shot_df.sort_values(['ZONE']).groupby(
            ['T1', 'RANGE'], as_index=False, sort=False).sum()

        for t in team_shot_range_df['T1'].unique():
            tsr_df = team_shot_range_df[team_shot_range_df['T1'].str.match(t)]
            update_range_stats(tsr_df)

            if t in self.id_table.keys():
                result_str_list.append(self.id_table[t])
            else:
                result_str_list.append(t)
            result_str_list.append('| Shot Range | Freq | FGM/A | eFG% |')
            result_str_list.append('|:---:|---:|---:|---:|')
            result_str_list.append(
                '|' + tsr_df[['RANGE', 'FREQ_STR', 'FGM/A', 'EFG_STR']].to_csv(
                    sep='|',
                    line_terminator='|\n|',
                    header=False,
                    float_format='%.1f',
                    encoding='utf-8',
                    index=False)[:-2])
            result_str_list.append('|Total||{fgm}/{fga}||'.format(
                fgm=int(tsr_df['FGM'].sum()), fga=int(tsr_df['FGA'].sum())))

        return '\n'.join(result_str_list) + '\n'
コード例 #2
0
def test_update_shot_v5():
    update_pbp_stats_v5_to_v7(shot_df, 'FMD', 'FUB')
    update_xy_v5(shot_df)
    update_zone(shot_df)
    update_range(shot_df)

    shot_dict = shot_df.to_dict(orient='records')
    assert shot_dict[0]['ZONE'] == 11
    assert shot_dict[1]['ZONE'] == 4
コード例 #3
0
    def _gen_player_shot_chart(self):
        update_zone(self.shot_df)

        player_shot_zone_df = self.shot_df.sort_values(['ZONE']).groupby(
            ['T1', 'C1', 'ZONE'], as_index=False, sort=False).sum()
        for t in player_shot_zone_df['T1'].unique():
            path = './output/{team}'.format(team=t)
            if not os.path.exists(path):
                os.mkdir(path)
            tsz_df = player_shot_zone_df[player_shot_zone_df['T1'].str.match(
                t)]
            for p in tsz_df['C1'].unique():
                psz_df = tsz_df[tsz_df['C1'].str.match(p)]
                filename = '{path}/{player}'.format(path=path, player=p)
                LOGGER.info('Generate Shot Chart to {filename}.png'.format(
                    filename=filename))
                FibaShotChartGenerator._gen_shot_chart(filename, psz_df)
コード例 #4
0
    def _gen_team_shot_chart(self):
        update_zone(self.shot_df)

        team_shot_zone_df = self.shot_df.sort_values(['ZONE']).groupby(
            ['T1', 'ZONE'], as_index=False, sort=False).sum()
        for t in team_shot_zone_df['T1'].unique():
            filename = './output/{team}'.format(team=t)
            LOGGER.info('Generate Shot Chart to {filename}.png'.format(
                filename=filename))
            tsz_df = team_shot_zone_df[team_shot_zone_df['T1'].str.match(t)]
            FibaShotChartGenerator._gen_shot_chart(filename, tsz_df)

        team_shot_zone_df = self.shot_df.sort_values(['ZONE']).groupby(
            ['OppTeamCode', 'ZONE'], as_index=False, sort=False).sum()
        for t in team_shot_zone_df['OppTeamCode'].unique():
            filename = './output/{team}_opp'.format(team=t)
            LOGGER.info('Generate Shot Chart to {filename}.png'.format(
                filename=filename))
            tsz_df = team_shot_zone_df[
                team_shot_zone_df['OppTeamCode'].str.match(t)]
            FibaShotChartGenerator._gen_shot_chart(filename, tsz_df)
コード例 #5
0
def test_update_zone():
    update_zone(ac_df)
    ac_dict = ac_df.to_dict(orient='records')

    assert ac_dict[0]['DISTANCE'] == 0
    assert ac_dict[1]['DISTANCE'] == 0.48404387134613663
    assert ac_dict[2]['DISTANCE'] == 7.198480742490043
    assert ac_dict[3]['DISTANCE'] == 6.829005701970896

    assert ac_dict[0]['ZONE'] == 0
    assert ac_dict[1]['ZONE'] == 0

    assert ac_dict[2]['ZONE'] == 12
    assert ac_dict[3]['ZONE'] == 11
    assert ac_dict[4]['ZONE'] == 9
    assert ac_dict[5]['ZONE'] == 13
    assert ac_dict[6]['ZONE'] == 10

    assert ac_dict[7]['ZONE'] == 2
    assert ac_dict[8]['ZONE'] == 1
    assert ac_dict[9]['ZONE'] == 3

    assert ac_dict[10]['ZONE'] == 4
    assert ac_dict[11]['ZONE'] == 8
    assert ac_dict[12]['ZONE'] == 7
    assert ac_dict[13]['ZONE'] == 6
    assert ac_dict[14]['ZONE'] == 5

    assert ac_dict[0]['FGA'] == 1
    assert ac_dict[0]['FGM'] == 0
    assert ac_dict[1]['FGA'] == 1
    assert ac_dict[1]['FGM'] == 1

    assert ac_dict[2]['FGA'] == 1
    assert ac_dict[2]['FGM'] == 0
    assert ac_dict[3]['FGA'] == 1
    assert ac_dict[3]['FGM'] == 1