floodlight.io.opta
- floodlight.io.opta.get_opta_feedtype(filepath)[source]
Tries to extract the feed type from Opta’s XML feed.
This function assumes that the file follows Opta’s format of producing feeds. Thus it should have a “PRODUCTION HEADER” comment at the top of the file so that on line 6 it reads something like
production module: Opta::Feed::XML::Soccer::F24
.- Parameters
filepath (Union[str, Path]) – Full path to Opta XML file.
- Returns
feedtype – Returns the type of the feed as a string in case it finds it, e.g. ‘F24’, and None otherwise.
- Return type
str or None
- floodlight.io.opta.read_event_data_xml(filepath)[source]
Parse Opta’s f24 feed (containing match events) and extract event data and pitch information.
This function provides a high-level access to the particular f24 feed and will return event objects for both teams. The number of segments is inferred from the data, yet data for each segment is stored in a separate object.
- Parameters
filepath (str or pathlib.Path) – Full path to the XML feed.
- Returns
data_objects – Tuple of (nested) floodlight core objects with shape (events_objects, pitch).
events_objects
is a nested dictionary containingEvents
objects for each team and segment of the formevents_objects[segment][team] = Events
. For a typical league match with two halves and teams this dictionary looks like:{'HT1': {'Home': Events, 'Away': Events}, 'HT2': {'Home': Events, 'Away': Events}}
.pitch
is aPitch
object corresponding to the data.- Return type
Notes
Opta’s format of handling event data information involves an elaborate use of so called qualifiers, which attach additional information to certain events. There also exist a number of mappings that define which qualifiers may be attached to which kind of events. Parsing this information involves quite a bit of logic and is planned to be inclucded in further releases. As of now, qualifier information is parsed as a string in the qualifier column of the returned DataFrame and can be transformed to a dict of the form {qualifier_id: value}.