Skip to content
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bb7d854
added BasketballDataset class
not-heavychevy Apr 10, 2025
2abeeff
added BasketballPitchDimensions class
not-heavychevy Apr 10, 2025
bd59522
added graph settings
not-heavychevy Apr 10, 2025
8a83938
added optimized graph converter
not-heavychevy Apr 10, 2025
f5071c6
added ball handling
not-heavychevy Apr 10, 2025
26d6d85
added init files
not-heavychevy Apr 10, 2025
f2d164b
bugfix dataset load() bug
not-heavychevy Apr 10, 2025
d86c0af
added tests
not-heavychevy Apr 10, 2025
d1c0c73
added additional fields computation
not-heavychevy Apr 10, 2025
64f5ee3
BasketballDataset inherits from DefaultDataset
not-heavychevy Apr 12, 2025
835cd59
bugfix
not-heavychevy Apr 12, 2025
98f09ae
files read with kloppy.io
not-heavychevy Apr 19, 2025
0502aa7
added norm parameters
not-heavychevy Apr 19, 2025
d2f6b52
refactor: move get_dataframe to DefaultDataset
not-heavychevy Apr 20, 2025
53ea444
created post_init
not-heavychevy Apr 20, 2025
3482bf9
added self.settings to BasketballDataset
not-heavychevy Apr 20, 2025
51a6657
added add_dummy_labels и add_graph_ids
not-heavychevy Apr 20, 2025
1352f80
rewritten tests for dataset.py
not-heavychevy Apr 21, 2025
b0fc5c1
Refactor BasketballPitchDimensions
not-heavychevy Apr 25, 2025
1e04bfd
added tests for BasketballPitchDimensions
not-heavychevy Apr 25, 2025
627fae8
Refactor BasketballGraphSettings
not-heavychevy Apr 25, 2025
1bdd740
added tests for BasketballGraphSettings
not-heavychevy Apr 25, 2025
7c64156
Merge PitchDimensions and GraphSettings
not-heavychevy Apr 25, 2025
a70739c
graph_settings test update
not-heavychevy Apr 25, 2025
ebe0914
import bugs fix
not-heavychevy Apr 25, 2025
2dcd3fb
graph_converter refactoring
not-heavychevy Apr 26, 2025
4b96024
dataset separator bugfix
not-heavychevy Apr 26, 2025
af3a02a
added tests for graph_converter
not-heavychevy Apr 26, 2025
8a47337
moved the functionality to “features”
not-heavychevy Apr 26, 2025
633afca
tests update
not-heavychevy Apr 26, 2025
7463b1e
tests fix
not-heavychevy Apr 26, 2025
dcfa8e4
Deprecate speed/acceleration thresholds
not-heavychevy Apr 26, 2025
1b5bc3b
unify data/settings access on DefaultDataset
not-heavychevy Apr 26, 2025
7eb2081
Refactor _convert to use polars methods
not-heavychevy Apr 26, 2025
b0b9d72
Add unified graph-export API to GraphConverter
not-heavychevy Apr 26, 2025
e55d30e
added new tests for public export API
not-heavychevy Apr 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge PitchDimensions and GraphSettings
  • Loading branch information
not-heavychevy committed Apr 25, 2025
commit 7c641569aef733ae76ab69c25d940b7e55f5b5f1
64 changes: 53 additions & 11 deletions unravel/basketball/graphs/graph_settings.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,76 @@
from dataclasses import dataclass, field
from typing import Union

from kloppy.domain import Dimension, Unit

from unravel.utils.objects.default_graph_settings import DefaultGraphSettings
from unravel.utils.features import (
AdjacencyMatrixType,
AdjacenyMatrixConnectType,
PredictionLabelType,
)
from .pitch_dimensions import BasketballPitchDimensions

@dataclass
class BasketballPitchDimensions:
"""
Defines the physical dimensions of a basketball court.
Default values are based on official NBA court dimensions.
"""
court_length: float = 94.0
court_width: float = 50.0
three_point_radius: float = 23.75

standardized: bool = False
unit: Unit = Unit.FEET

x_dim: Dimension = field(init=False)
y_dim: Dimension = field(init=False)
basket_x: float = field(init=False)
basket_y: float = field(init=False)

def __post_init__(self):
self.x_dim = Dimension(min=0.0, max=self.court_length)
self.y_dim = Dimension(min=0.0, max=self.court_width)
self.basket_x = self.x_dim.max - 4.0
self.basket_y = (self.y_dim.max + self.y_dim.min) / 2.0

def as_dict(self) -> dict:
return {
"court_length": self.court_length,
"court_width": self.court_width,
"three_point_radius": self.three_point_radius,
"standardized": self.standardized,
"unit": self.unit,
"x_dim": {"min": self.x_dim.min, "max": self.x_dim.max},
"y_dim": {"min": self.y_dim.min, "max": self.y_dim.max},
"basket_x": self.basket_x,
"basket_y": self.basket_y,
}

@dataclass(kw_only=True)
class BasketballGraphSettings(DefaultGraphSettings):
"""
Configuration settings for converting NBA tracking data into graph representations.
Inherits from DefaultGraphSettings to leverage common functionality.
"""
# Sport-specific settings
pitch_dimensions: BasketballPitchDimensions
# Embed pitch dimensions with default factory for convenience
pitch_dimensions: BasketballPitchDimensions = field(default_factory=BasketballPitchDimensions)

# Basketball-specific overrides
ball_carrier_threshold: float = 5.0
defending_team_node_value: float = 0.0
attacking_team_node_value: float = 1.0

def __post_init__(self):
# Validate pitch_dimensions type
# Ensure correct type
if not isinstance(self.pitch_dimensions, BasketballPitchDimensions):
raise TypeError("pitch_dimensions must be a BasketballPitchDimensions instance")
# Validate node value ranges
if not (0.0 <= self.defending_team_node_value <= 1.0):
raise ValueError("defending_team_node_value must be between 0 and 1")
if not (0.0 <= self.attacking_team_node_value <= 1.0):
raise ValueError("attacking_team_node_value must be between 0 and 1")
# Perform default settings validation
super().__post_init__()
# Validate node-value bounds
for name, val in [
("defending_team_node_value", self.defending_team_node_value),
("attacking_team_node_value", self.attacking_team_node_value),
]:
if not (0.0 <= val <= 1.0):
raise ValueError(f"{name} must be between 0 and 1")
# Call base class checks (self_loop, adjacency types, labels, etc.)
super().__post_init__()