Пример #1
0
    def make_dataset(play, event_frame, metrica_attack, metrica_defence, bokeh_attack, bokeh_defence, field_dimen = (106.,68.,), new_grid_size = 500):

        params = mpc.default_model_params(3) 

        event = events_df.loc[[(play, int(event_frame))]]
        tracking_frame = event['Start Frame'][0]

        att_frame = bokeh_attack.loc[(play,tracking_frame)]
        att_player_frame = att_frame[att_frame['player'] != "ball"]
        att_player_frame['Shirt Number'] = att_player_frame['player'].map(int).map(shirt_mapping[play]).fillna("")

        def_frame = bokeh_defence.loc[(play,tracking_frame)]
        def_player_frame = def_frame[def_frame['player'] != "ball"]
        def_player_frame['Shirt Number'] = def_player_frame['player'].map(int).map(shirt_mapping[play]).fillna("")

        ball_frame = att_frame[att_frame['player'] == "ball"]

        PPCF,xgrid,ygrid = pvm.lastrow_generate_pitch_control_for_event(play,event_frame, events_df, metrica_attack, metrica_defence, params, field_dimen = (106.,68.,), n_grid_cells_x = 50)
        PT = pvm.generate_relevance_at_event(play,event_frame, events_df, PPCF, params)
        PS = pvm.generate_scoring_opportunity(field_dimen = (106.,68.,),n_grid_cells_x = 50)
        PPV = pvm.generate_pitch_value(PPCF,PT,PS,field_dimen = (106.,68.,),n_grid_cells_x = 50)
        RPPV = pvm.generate_relative_pitch_value(play, event_frame, events_df, metrica_attack, PPV, xgrid, ygrid)

        xgrid_new = np.linspace( -field_dimen[0]/2., field_dimen[0]/2., new_grid_size)
        ygrid_new = np.linspace( -field_dimen[1]/2., field_dimen[1]/2., new_grid_size)

        PPCF_int = interpolate.interp2d(xgrid, ygrid, PPCF, kind = 'cubic')
        PPCF_new = PPCF_int(xgrid_new, ygrid_new)
        PPCF_dict = dict(image = [PPCF_new],x = [xgrid.min()],y = [ygrid.min()],dw = [field_dimen[0]], dh = [field_dimen[1]])
        PT_int = interpolate.interp2d(xgrid, ygrid, PT, kind = 'cubic')
        PT_new = PT_int(xgrid_new, ygrid_new)
        PT_dict = dict(image = [PT_new],x = [xgrid.min()],y = [ygrid.min()],dw = [field_dimen[0]], dh = [field_dimen[1]])
        PS_int = interpolate.interp2d(xgrid, ygrid, PS, kind = 'cubic')
        PS_new = PS_int(xgrid_new, ygrid_new)
        PS_dict = dict(image = [PS_new],x = [xgrid.min()],y = [ygrid.min()],dw = [field_dimen[0]], dh = [field_dimen[1]])
        PPV_int = interpolate.interp2d(xgrid, ygrid, PPV, kind = 'cubic')
        PPV_new = PPV_int(xgrid_new, ygrid_new)
        PPV_dict = dict(image = [PPV_new],x = [xgrid.min()],y = [ygrid.min()],dw = [field_dimen[0]], dh = [field_dimen[1]])
        RPPV_int = interpolate.interp2d(xgrid, ygrid, RPPV, kind = 'cubic')
        RPPV_new = RPPV_int(xgrid_new, ygrid_new)
        RPPV_dict = dict(image = [RPPV_new],x = [xgrid.min()],y = [ygrid.min()],dw = [field_dimen[0]], dh = [field_dimen[1]])


        event_src = ColumnDataSource(event)
        att_src = ColumnDataSource(att_player_frame)
        def_src = ColumnDataSource(def_player_frame)
        ball_src = ColumnDataSource(ball_frame)
        PPCF_src = ColumnDataSource(PPCF_dict)
        PT_src = ColumnDataSource(PT_dict)
        PS_src = ColumnDataSource(PS_dict)
        PPV_src = ColumnDataSource(PPV_dict)
        RPPV_src = ColumnDataSource(RPPV_dict)

        return event_src, att_src, def_src, ball_src, PPCF_src, PT_src, PS_src, PPV_src, RPPV_src, xgrid, ygrid
Пример #2
0
def generate_surfaces_at_event(play,
                               event_frame,
                               events,
                               tracking_attack,
                               tracking_defence,
                               params,
                               field_dimen=(
                                   106.,
                                   68.,
                               ),
                               n_grid_cells_x=50):

    import pitch_value_model as pvm

    PPCF, xgrid, ygrid = pvm.lastrow_generate_pitch_control_for_event(
        (play, event_frame),
        events,
        tracking_attack,
        tracking_defence,
        params,
        field_dimen=(
            106.,
            68.,
        ),
        n_grid_cells_x=50)
    PT = pvm.generate_relevance_at_event((play, event_frame), events, PPCF,
                                         params)
    PS = pvm.generate_scoring_opportunity(field_dimen=field_dimen,
                                          n_grid_cells_x=n_grid_cells_x)
    PPV = pvm.generate_pitch_value(PPCF,
                                   PT,
                                   PS,
                                   field_dimen=field_dimen,
                                   n_grid_cells_x=n_grid_cells_x)
    RPPV = pvm.generate_relative_pitch_value(play, event_frame, events,
                                             tracking_attack, PPV, xgrid,
                                             ygrid)

    return PPCF, PT, PS, PPV, RPPV, xgrid, ygrid