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

Missing "Result" Attribute makes Live Opta parsing impossible #321

Closed
wants to merge 5 commits into from

Conversation

UnravelSports
Copy link
Contributor

Hi!

A really simple fix here. When loading opta event data (as shown below) for an incomplete f7 (read: during live matches) we get an AttributeError.

dataset = opta.load(
    f7_data="f7.xml",
    f24_data="f24.xml"
)

Error looks as follows:

Traceback (most recent call last):
  File "/workspaces/kloppy/_dev.py", line 3, in <module>
    dataset = opta.load(
  File "/workspaces/kloppy/kloppy/_providers/opta.py", line 35, in load
    return deserializer.deserialize(
  File "/workspaces/kloppy/kloppy/infra/serializers/event/opta/deserializer.py", line 729, in deserialize
    match_result_type = list(match_result_path.find(f7_root))[
  File "src/lxml/objectpath.pxi", line 55, in lxml.objectify.ObjectPath.__call__
  File "src/lxml/objectpath.pxi", line 219, in lxml.objectify._find_object_path
AttributeError: no such child: Result

Normally, in a completed game we'd have a Result tag that looks something like this:

<Result Type="Aggregate" Winner="t12345" />

But, because the game is not finished yet there simply is no "Result" tag.

Doing a simple try / except block like below resolves this issue and creates a correct Kloppy EventDataset.

try:
              match_result_type = list(match_result_path.find(f7_root))[
                  0
              ].attrib["Type"]
          except AttributeError:
              match_result_type = None

Not 100% sure if using a try-except block here is the best solution, but it works.

@UnravelSports
Copy link
Contributor Author

Great, it's still including some stupid commits from a year ago that are totally irrelevent.....

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.

1 participant