From 0bddc312dc029e8c13cd09d57fc369b1852d7c54 Mon Sep 17 00:00:00 2001 From: driesdeprest Date: Mon, 28 Oct 2024 10:03:31 +0100 Subject: [PATCH] recognize referee player type and handle accordingly --- .../infra/serializers/tracking/statsperform.py | 17 ++++++++++++++--- .../tests/files/statsperform_tracking_ma25.txt | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kloppy/infra/serializers/tracking/statsperform.py b/kloppy/infra/serializers/tracking/statsperform.py index c95046fc..1cf413d5 100644 --- a/kloppy/infra/serializers/tracking/statsperform.py +++ b/kloppy/infra/serializers/tracking/statsperform.py @@ -19,6 +19,7 @@ TrackingDataset, attacking_direction_from_frame, ) +from kloppy.exceptions import DeserializationError from kloppy.utils import performance_logging from kloppy.infra.serializers.event.statsperform.parsers import get_parser @@ -96,15 +97,25 @@ def _frame_from_framedata(cls, teams_list, period, frame_data): for player_data in player_info: player_data = player_data.split(",") - team_side_id = int(player_data[0]) + raw_team_side_id = int(player_data[0]) player_id = player_data[1] jersey_no = int(player_data[2]) x = float(player_data[3]) y = float(player_data[4]) + # Field players have id 0, 1 + if raw_team_side_id in [0, 1]: + team_side_id = raw_team_side_id # Goalkeepers have id 3 and 4 - if team_side_id > 2: - team_side_id = team_side_id - 3 + elif raw_team_side_id in [3, 4]: + team_side_id = raw_team_side_id - 3 + # Referees have id 2 + elif raw_team_side_id == 2: + continue + else: + raise DeserializationError( + f"Unexpected team side id {raw_team_side_id}" + ) team = teams_list[team_side_id] player = team.get_player_by_id(player_id) diff --git a/kloppy/tests/files/statsperform_tracking_ma25.txt b/kloppy/tests/files/statsperform_tracking_ma25.txt index 4b71fbf3..7f69eb15 100644 --- a/kloppy/tests/files/statsperform_tracking_ma25.txt +++ b/kloppy/tests/files/statsperform_tracking_ma25.txt @@ -89,5 +89,5 @@ 1598187606200;6200,2,0:0,a2s2c6anax9wnlsw1s6vunl5h,9,66.074,35.263;0,28x7i681wkjueanvkevew3bh1,17,57.533,24.73;0,4rlw04tze791jwt623h5ikg5x,26,37.165,50.894;0,72m5u1rlgh6e229zpfvp7f5jp,11,56.565,67.502;0,3djmsd2atvq16ysmocq7twsfd,20,30.799,41.437;0,dmrj53hcw8vcffxx0lfudbob9,2,37.405,11.317;0,aipyotc87m5bdvmvizd5n69k9,8,55.174,50.009;0,ct32113pfx5q9avf2c0x208ru,37,52.491,1.57;0,5g5wwp5luxo1rz1kp6chvz0x6,32,31.691,25.184;0,b0wb7gf04synxlkq7o8gvzkoa,22,42.75,41.405;1,9nhlgi0k783bq8a2704bu6n6d,7,53.564,44.821;1,976riwm0dz0e74d4l28y3ttcl,5,64.396,41.295;1,3sc349yey596xp2j6xlyt0frp,32,65.845,13.949;1,19djqex4nu3lz6vw08f3fwv6x,3,61.011,56.618;1,fe4b3ric67hz0hhih3tjf2eh,24,45.577,50.88;1,72d5uxwcmvhd6mzthxuvev1sl,2,66.011,31.464;1,8j2vmplbpj983xbxibhyvidx,8,49.894,18.36;1,8qmm84tue6kuz8e5nhhdhmz8p,15,55.71,31.465;1,3mqhkh4iz4kesvmqui3hupgmi,11,43.074,32.381;1,e6ok0deqkoe80184iu509gzu2,27,46.193,44.575;3,6wfwy94p5bm0zv3aku0urfq39,40,15.461,33.905;4,6ekdnbnk56xlxforb5owt3dn9,1,95.061,33.729;:33.3,27.31,0; 1598187606300;6300,2,0:0,a2s2c6anax9wnlsw1s6vunl5h,9,66.222,35.177;0,28x7i681wkjueanvkevew3bh1,17,57.625,24.512;0,4rlw04tze791jwt623h5ikg5x,26,37.21,50.924;0,72m5u1rlgh6e229zpfvp7f5jp,11,56.806,67.487;0,3djmsd2atvq16ysmocq7twsfd,20,30.883,41.415;0,dmrj53hcw8vcffxx0lfudbob9,2,37.373,11.158;0,aipyotc87m5bdvmvizd5n69k9,8,55.424,49.979;0,ct32113pfx5q9avf2c0x208ru,37,52.388,1.487;0,5g5wwp5luxo1rz1kp6chvz0x6,32,31.783,25.141;0,b0wb7gf04synxlkq7o8gvzkoa,22,42.885,41.138;1,9nhlgi0k783bq8a2704bu6n6d,7,53.705,44.473;1,976riwm0dz0e74d4l28y3ttcl,5,64.458,41.012;1,3sc349yey596xp2j6xlyt0frp,32,65.809,13.545;1,19djqex4nu3lz6vw08f3fwv6x,3,61.202,56.343;1,fe4b3ric67hz0hhih3tjf2eh,24,45.764,50.684;1,72d5uxwcmvhd6mzthxuvev1sl,2,66.016,31.061;1,8j2vmplbpj983xbxibhyvidx,8,49.952,18.189;1,8qmm84tue6kuz8e5nhhdhmz8p,15,55.762,30.999;1,3mqhkh4iz4kesvmqui3hupgmi,11,42.948,32.095;1,e6ok0deqkoe80184iu509gzu2,27,46.179,44.201;3,6wfwy94p5bm0zv3aku0urfq39,40,15.534,33.777;4,6ekdnbnk56xlxforb5owt3dn9,1,94.962,33.718;:33.21,26.995,0; 1598187606400;6400,2,0:0,a2s2c6anax9wnlsw1s6vunl5h,9,66.359,35.09;0,28x7i681wkjueanvkevew3bh1,17,57.711,24.288;0,4rlw04tze791jwt623h5ikg5x,26,37.266,50.945;0,72m5u1rlgh6e229zpfvp7f5jp,11,57.05,67.478;0,3djmsd2atvq16ysmocq7twsfd,20,30.965,41.395;0,dmrj53hcw8vcffxx0lfudbob9,2,37.349,10.999;0,aipyotc87m5bdvmvizd5n69k9,8,55.669,49.938;0,ct32113pfx5q9avf2c0x208ru,37,52.276,1.425;0,5g5wwp5luxo1rz1kp6chvz0x6,32,31.885,25.069;0,b0wb7gf04synxlkq7o8gvzkoa,22,43.024,40.854;1,9nhlgi0k783bq8a2704bu6n6d,7,53.857,44.125;1,976riwm0dz0e74d4l28y3ttcl,5,64.538,40.746;1,3sc349yey596xp2j6xlyt0frp,32,65.753,13.164;1,19djqex4nu3lz6vw08f3fwv6x,3,61.403,56.084;1,fe4b3ric67hz0hhih3tjf2eh,24,45.958,50.493;1,72d5uxwcmvhd6mzthxuvev1sl,2,66.026,30.66;1,8j2vmplbpj983xbxibhyvidx,8,50.008,17.993;1,8qmm84tue6kuz8e5nhhdhmz8p,15,55.819,30.524;1,3mqhkh4iz4kesvmqui3hupgmi,11,42.827,31.806;1,e6ok0deqkoe80184iu509gzu2,27,46.166,43.833;3,6wfwy94p5bm0zv3aku0urfq39,40,15.605,33.654;4,6ekdnbnk56xlxforb5owt3dn9,1,94.863,33.706;:32.71,25.44,0; -1598187606500;6500,2,0:0,a2s2c6anax9wnlsw1s6vunl5h,9,66.487,35.002;0,28x7i681wkjueanvkevew3bh1,17,57.792,24.059;0,4rlw04tze791jwt623h5ikg5x,26,37.335,50.96;0,72m5u1rlgh6e229zpfvp7f5jp,11,57.299,67.476;0,3djmsd2atvq16ysmocq7twsfd,20,31.048,41.376;0,dmrj53hcw8vcffxx0lfudbob9,2,37.337,10.84;0,aipyotc87m5bdvmvizd5n69k9,8,55.908,49.884;0,ct32113pfx5q9avf2c0x208ru,37,52.156,1.386;0,5g5wwp5luxo1rz1kp6chvz0x6,32,31.999,24.969;0,b0wb7gf04synxlkq7o8gvzkoa,22,43.169,40.555;1,9nhlgi0k783bq8a2704bu6n6d,7,54.023,43.781;1,976riwm0dz0e74d4l28y3ttcl,5,64.638,40.495;1,3sc349yey596xp2j6xlyt0frp,32,65.676,12.813;1,19djqex4nu3lz6vw08f3fwv6x,3,61.613,55.843;1,fe4b3ric67hz0hhih3tjf2eh,24,46.159,50.309;1,72d5uxwcmvhd6mzthxuvev1sl,2,66.042,30.263;1,8j2vmplbpj983xbxibhyvidx,8,50.063,17.769;1,8qmm84tue6kuz8e5nhhdhmz8p,15,55.883,30.038;1,3mqhkh4iz4kesvmqui3hupgmi,11,42.713,31.513;1,e6ok0deqkoe80184iu509gzu2,27,46.156,43.47;3,6wfwy94p5bm0zv3aku0urfq39,40,15.675,33.533;4,6ekdnbnk56xlxforb5owt3dn9,1,94.763,33.697;:32.605,24.855,0; +1598187606500;6500,2,0:0,a2s2c6anax9wnlsw1s6vunl5h,9,66.487,35.002;0,28x7i681wkjueanvkevew3bh1,17,57.792,24.059;0,4rlw04tze791jwt623h5ikg5x,26,37.335,50.96;0,72m5u1rlgh6e229zpfvp7f5jp,11,57.299,67.476;0,3djmsd2atvq16ysmocq7twsfd,20,31.048,41.376;0,dmrj53hcw8vcffxx0lfudbob9,2,37.337,10.84;0,aipyotc87m5bdvmvizd5n69k9,8,55.908,49.884;0,ct32113pfx5q9avf2c0x208ru,37,52.156,1.386;0,5g5wwp5luxo1rz1kp6chvz0x6,32,31.999,24.969;0,b0wb7gf04synxlkq7o8gvzkoa,22,43.169,40.555;1,9nhlgi0k783bq8a2704bu6n6d,7,54.023,43.781;1,976riwm0dz0e74d4l28y3ttcl,5,64.638,40.495;1,3sc349yey596xp2j6xlyt0frp,32,65.676,12.813;1,19djqex4nu3lz6vw08f3fwv6x,3,61.613,55.843;1,fe4b3ric67hz0hhih3tjf2eh,24,46.159,50.309;1,72d5uxwcmvhd6mzthxuvev1sl,2,66.042,30.263;1,8j2vmplbpj983xbxibhyvidx,8,50.063,17.769;1,8qmm84tue6kuz8e5nhhdhmz8p,15,55.883,30.038;1,3mqhkh4iz4kesvmqui3hupgmi,11,42.713,31.513;1,e6ok0deqkoe80184iu509gzu2,27,46.156,43.47;2,6wfwy94p5bm0zv3aku0urfq38,0,0,0;3,6wfwy94p5bm0zv3aku0urfq39,40,15.675,33.533;4,6ekdnbnk56xlxforb5owt3dn9,1,94.763,33.697;:32.605,24.855,0; 1598187606600;6600,2,0:;:32.605,24.855,0;