diff --git a/docs/quickstart/event_data.ipynb b/docs/quickstart/event_data.ipynb index 1eee22fe..97e00518 100644 --- a/docs/quickstart/event_data.ipynb +++ b/docs/quickstart/event_data.ipynb @@ -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, diff --git a/docs/quickstart/examples.ipynb b/docs/quickstart/examples.ipynb index 8826e462..eb268e48 100644 --- a/docs/quickstart/examples.ipynb +++ b/docs/quickstart/examples.ipynb @@ -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, diff --git a/docs/quickstart/state.ipynb b/docs/quickstart/state.ipynb index bfa8e1bb..cfea071d 100644 --- a/docs/quickstart/state.ipynb +++ b/docs/quickstart/state.ipynb @@ -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, diff --git a/docs/quickstart/tracking_data.ipynb b/docs/quickstart/tracking_data.ipynb index c946f6f4..7c0b05d8 100644 --- a/docs/quickstart/tracking_data.ipynb +++ b/docs/quickstart/tracking_data.ipynb @@ -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, diff --git a/kloppy/domain/models/pitch.py b/kloppy/domain/models/pitch.py index 582b01d2..fb75752b 100644 --- a/kloppy/domain/models/pitch.py +++ b/kloppy/domain/models/pitch.py @@ -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: diff --git a/kloppy/tests/test_metadata.py b/kloppy/tests/test_metadata.py new file mode 100644 index 00000000..1a7c00ab --- /dev/null +++ b/kloppy/tests/test_metadata.py @@ -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