Skip to content

Commit

Permalink
Merge pull request #77 from BenjaminLarrousse/add_length_width_to_pit…
Browse files Browse the repository at this point in the history
…chdim

Add length and width to PitchDimensions
  • Loading branch information
koenvo authored Dec 22, 2020
2 parents 3f541aa + d567d40 commit 9f659dd
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
15 changes: 14 additions & 1 deletion docs/quickstart/event_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.5.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
15 changes: 14 additions & 1 deletion docs/quickstart/examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.5.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
15 changes: 14 additions & 1 deletion docs/quickstart/state.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.5.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
15 changes: 14 additions & 1 deletion docs/quickstart/tracking_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.5.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
16 changes: 16 additions & 0 deletions kloppy/domain/models/pitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ class PitchDimensions:
x_per_meter: float = None
y_per_meter: float = None

@property
def length(self) -> float:
return (
(self.x_dim.max - self.x_dim.min) / self.x_per_meter
if self.x_per_meter
else None
)

@property
def width(self) -> float:
return (
(self.y_dim.max - self.y_dim.min) / self.y_per_meter
if self.y_per_meter
else None
)


@dataclass(frozen=True)
class Point:
Expand Down
21 changes: 21 additions & 0 deletions kloppy/tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from kloppy.domain import Dimension, PitchDimensions


class TestPitchdimensions:
def test_pitchdimensions_properties(self):
pitch_without_scale = PitchDimensions(
x_dim=Dimension(-100, 100), y_dim=Dimension(-50, 50)
)

assert pitch_without_scale.length is None
assert pitch_without_scale.width is None

pitch_with_scale = PitchDimensions(
x_dim=Dimension(-100, 100),
y_dim=Dimension(-50, 50),
x_per_meter=20 / 12,
y_per_meter=10 / 8,
)

assert pitch_with_scale.length == 120
assert pitch_with_scale.width == 80

0 comments on commit 9f659dd

Please sign in to comment.