I have some X Y Geospatial Cordinate Data For a Rugby match but there is no data on where the Ball is located. This is my problem! Therefore we have to determine using the X Y Player movements and some event data where the ball is moving for each 0.1 seconds time interval. I have mapped the Event Data (Shown by columns 'Team', 'Player', 'Event', 'Outcome') to the XY Player Tracking Data (Shown by 'X_Plr1', 'Y_Plr1'). I'm looking to fill in the ball positon columndepending on th event information. An assumption we can make it that the direction is linear. If the ball is passed from player 1 to player 2 between two x.y positions (14.11, 25.55) at index 1 and travelling in linear direction to Player two at index 5. So the example above would cover a PASS. However from index position 5 to index position 9 the ball is instead being dribbled by Player2 and hence the balls position would simply mirror where Player 2 had moved from Index 5 to Index 9. I'm trying to determine how to fill Ball Position column depending on what the event data says in essence! Any help would be great!
0 Team Player Event Outcome Time X_Plr1 X_Plr2 Y_Plr1 Y_Plr2 Ball Position
1 Team1 Player1 Pass Success 0.0 14.11 4.99 25.55 30.01
2 NaN NaN NaN NaN 0.1 14.21 5.03 25.34 30.06
3 NaN NaN NaN NaN 0.2 14.31 5.07 26.11 30.10
4 NaN NaN NaN NaN 0.3 14.33 5.11 26.01 30.12
5 Team1 Player2 Received Success 0.4 14.35 5.13 26.24 30.44
6 NaN NaN NaN NaN 0.1 14.21 5.10 26.13 30.97
7 NaN NaN NaN NaN 0.2 14.31 5.07 25.99 31.11
8 NaN NaN NaN NaN 0.3 14.33 5.11 25.97 31.23
9 Team1 Player2 Pass Success 0.4 14.21 5.16 25.92 31.89
Here is a potential solution. I tried to make the function names descriptive so it is easier to see the approach. Essentially loop through only the
df
rows where there is an event, and calculate ball position for the block of rows that starts with one event and ends with the next event after it. If an event block is for a pass, then use linear interpolation between the two player positions, as you described. If an event block is for a player that received a pass and is dribbling, then fill in ball position with the dribbling player's position. The output is a new column,BallPosition
, which contains a two value tuple with the X and Y position of the ball. Here is the code:The code block has some comments regarding assumptions, etc.
Output df: