Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statistics attribute to DataRecord #302

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

DriesDeprest
Copy link
Contributor

Related to: #280.

I've started with adding support for xG statistics and wanted to get initial feedback on the implementation prior to expanding it to also parse OB values of StatsBomb and potentially other statistics.

So happy to hear your thoughts @probberechts @koenvo @JanVanHaaren

@DriesDeprest
Copy link
Contributor Author

It seems that for Python versions < 3.10, we get: TypeError: dataclass() got an unexpected keyword argument 'kw_only'.
But even for Python versions >= 3.10, we get: TypeError: non-default argument 'end_timestamp' follows default argument. But more generally this is the result of defining the default statistics argument in the DataRecord class prior to non-default arguments for classes which inherit from DataRecord, such as Event.

I'm not sure what the right way is to handle this, so any help is greatly appreciated, thanks.

@koenvo
Copy link
Contributor

koenvo commented Aug 1, 2024

# Conflicts:
#	kloppy/infra/serializers/event/statsbomb/specification.py
@DriesDeprest
Copy link
Contributor Author

@koenvo @JanVanHaaren this implementation works for you guys?

return event_cls(**relevant_kwargs)
event = event_cls(**relevant_kwargs)

statistics = all_kwargs.get("statistics", [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this to be passed via kwargs, a couple of lines above. Like freeze_frame

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how it would work.

statistics: Optional[List[Statistic]] = field(
        init=False, default_factory=list
    )

In my implementation, the statistics cannot be initialized on creation, but only after. Thus, we cannot pass it as kwargs on creation, right?

The reason why I have put init=False is because otherwise it complains about TypeError: non-default argument follows default argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem, however, with my current implementation is that the statistics of an event gets reset to [] when the dataclasses replace() method is being executed on an event as the result of e.g. a transformation.

Any idea how to properly handle the statistics?

Copy link
Contributor Author

@DriesDeprest DriesDeprest Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koenvo could you review my latest commit? Thanks!

@koenvo
Copy link
Contributor

koenvo commented Oct 8, 2024

Nice. Some minor comments.

@DriesDeprest
Copy link
Contributor Author

Resolved the comments, can you check again?

# Conflicts:
#	kloppy/infra/serializers/event/statsbomb/helpers.py
#	kloppy/infra/serializers/event/statsbomb/specification.py
#	kloppy/infra/serializers/event/statsperform/deserializer.py
#	kloppy/infra/serializers/tracking/statsperform.py
#	kloppy/infra/serializers/tracking/tracab/tracab_json.py
@DriesDeprest
Copy link
Contributor Author

@koenvo merge conflicts are resolved! Ready to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants