|
from datasets import Dataset, GeneratorBasedBuilder, DatasetInfo, Features, Value, SplitGenerator, Sequence |
|
import pandas as pd |
|
import tensorflow as tf |
|
import csv |
|
import sys |
|
import ast |
|
import json |
|
import yaml |
|
|
|
class Euro2020Dataset(GeneratorBasedBuilder): |
|
VERSION = "1.0.0" |
|
|
|
def _info(self): |
|
return DatasetInfo( |
|
description="This dataset contains highly detailed information on each of the 51 matches in the UEFA Euro 2020 tournament composed and aggregated from 6 original csv files. Each row represents the information for each match and the columns constitute a wide range of variables on basic match information, referee information and statistics, match events in different phases of a match, team line-up and squad information, team statistics and player statistics on different areas of the game, and player-based pre-match information.", |
|
features=Features({ |
|
"HomeTeamName": Value("string"), |
|
"AwayTeamName": Value("string"), |
|
"DateandTimeCET": Value("string"), |
|
"MatchID": Value("int64"), |
|
"RoundName": Value("string"), |
|
"Stage": Value("string"), |
|
"MatchDay": Value("int64"), |
|
"Session": Value("int64"), |
|
"MatchMinute": Value("int64"), |
|
"InjuryTime": Value("int64"), |
|
"NumberofPhases": Value("int64"), |
|
"Phase": Value("int64"), |
|
"ScoreHome": Value("int64"), |
|
"ScoreAway": Value("int64"), |
|
"MatchStatus": Value("string"), |
|
"StadiumID": Value("int64"), |
|
"RefereeWebName": Value("string"), |
|
"NumberofMatchesRefereedPostMatch": Value("int64"), |
|
"TotalNumberofMatchesRefereed": Value("int64"), |
|
"NumberofMatchesRefereedinGroupStage": Value("int64"), |
|
"NumberofMatchesRefereedinKnockoutStage": Value("int64"), |
|
"AssistantRefereeWebName": Value("string"), |
|
"Humidity": Value("int64"), |
|
"Temperature": Value("int64"), |
|
"WindSpeed": Value("int64"), |
|
"MatchEvent": Features({ |
|
"1-First Half": Sequence(Features({ |
|
"Event": Value("string"), |
|
"Minute": Value("int64"), |
|
"Phase": Value("int64"), |
|
"InjuryMinute": Value("int64"), |
|
"TeamFromID": Value("float"), |
|
"TeamToID": Value("float"), |
|
"PlayerFromID": Value("float"), |
|
"PlayerToID": Value("float"), |
|
"Time": Value("string"), |
|
"MatchEventAttribute": Value("string"), |
|
|
|
})), |
|
"2-Second Half": Sequence(Features({ |
|
"Event": Value("string"), |
|
"Minute": Value("int64"), |
|
"Phase": Value("int64"), |
|
"InjuryMinute": Value("int64"), |
|
"TeamFromID": Value("float"), |
|
"TeamToID": Value("float"), |
|
"PlayerFromID": Value("float"), |
|
"PlayerToID": Value("float"), |
|
"Time": Value("string"), |
|
"MatchEventAttribute": Value("string"), |
|
})), |
|
"3-Extra Time First Half": Sequence(Features({ |
|
"Event": Value("string"), |
|
"Minute": Value("int64"), |
|
"Phase": Value("int64"), |
|
"InjuryMinute": Value("int64"), |
|
"TeamFromID": Value("float"), |
|
"TeamToID": Value("float"), |
|
"PlayerFromID": Value("float"), |
|
"PlayerToID": Value("float"), |
|
"Time": Value("string"), |
|
"MatchEventAttribute": Value("string"), |
|
})), |
|
"4-Extra Time Second Half": Sequence(Features({ |
|
"Event": Value("string"), |
|
"Minute": Value("int64"), |
|
"Phase": Value("int64"), |
|
"InjuryMinute": Value("int64"), |
|
"TeamFromID": Value("float"), |
|
"TeamToID": Value("float"), |
|
"PlayerFromID": Value("float"), |
|
"PlayerToID": Value("float"), |
|
"Time": Value("string"), |
|
"MatchEventAttribute": Value("string"), |
|
})), |
|
"5-Penalty Shootout": Sequence(Features({ |
|
"Event": Value("string"), |
|
"Minute": Value("int64"), |
|
"Phase": Value("int64"), |
|
"InjuryMinute": Value("int64"), |
|
"TeamFromID": Value("float"), |
|
"TeamToID": Value("float"), |
|
"PlayerFromID": Value("float"), |
|
"PlayerToID": Value("float"), |
|
"Time": Value("string"), |
|
"MatchEventAttribute": Value("string"), |
|
})), |
|
}), |
|
"TeamLineUps": Features({ |
|
"HomeTeamLineUp": Features({ |
|
"Starting11": Sequence(Features({ |
|
"Country": Value("string"), |
|
"ID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"ShortName": Value("string"), |
|
"Role": Value("string"), |
|
"JerseyNumber": Value("string"), |
|
"IsGoalkeeper": Value("string"), |
|
"JerseyName": Value("string"), |
|
"IsCaptain": Value("string"), |
|
"TacticX": Value("string"), |
|
"TacticY": Value("string"), |
|
"Numorder": Value("string"), |
|
"IsBooked": Value("float"), |
|
})), |
|
"Benched Players": Sequence(Features({ |
|
"Country": Value("string"), |
|
"ID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"ShortName": Value("string"), |
|
"Role": Value("string"), |
|
"JerseyNumber": Value("string"), |
|
"IsGoalkeeper": Value("string"), |
|
"JerseyName": Value("string"), |
|
"IsCaptain": Value("string"), |
|
"TacticX": Value("string"), |
|
"TacticY": Value("string"), |
|
"Numorder": Value("string"), |
|
"IsBooked": Value("float"), |
|
})), |
|
"Staff": Sequence(Features({ |
|
"Country": Value("string"), |
|
"ID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"ShortName": Value("string"), |
|
"Role": Value("string"), |
|
})), |
|
}), |
|
"AwayTeamLineUp": Features({ |
|
"Starting11": Sequence(Features({ |
|
"Country": Value("string"), |
|
"ID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"ShortName": Value("string"), |
|
"Role": Value("string"), |
|
"JerseyNumber": Value("string"), |
|
"IsGoalkeeper": Value("string"), |
|
"JerseyName": Value("string"), |
|
"IsCaptain": Value("string"), |
|
"TacticX": Value("string"), |
|
"TacticY": Value("string"), |
|
"Numorder": Value("string"), |
|
"IsBooked": Value("float"), |
|
})), |
|
"Benched Players": Sequence(Features({ |
|
"Country": Value("string"), |
|
"ID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"ShortName": Value("string"), |
|
"Role": Value("string"), |
|
"JerseyNumber": Value("string"), |
|
"IsGoalkeeper": Value("string"), |
|
"JerseyName": Value("string"), |
|
"IsCaptain": Value("string"), |
|
"TacticX": Value("string"), |
|
"TacticY": Value("string"), |
|
"Numorder": Value("string"), |
|
"IsBooked": Value("float"), |
|
})), |
|
"Staff": Sequence(Features({ |
|
"Country": Value("string"), |
|
"ID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"ShortName": Value("string"), |
|
"Role": Value("string"), |
|
})), |
|
}), |
|
}), |
|
"TeamStats": Features({ |
|
"HomeTeamStats": Features({ |
|
"attacking": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"coverage&speed": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"defending": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"goalkeeping": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"matches played": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"possession": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"time stats": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"violation&foul&discipline": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
}), |
|
"AwayTeamStats": Features({ |
|
"attacking": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"coverage&speed": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"defending": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"goalkeeping": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"matches played": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"possession": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"time stats": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"violation&foul&discipline": Sequence(Features({ |
|
"TeamID": Value("int64"), |
|
"TeamName": Value("string"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
}), |
|
}), |
|
"PlayerStats": Features({ |
|
"HomeTeamPlayerStats": Features({ |
|
"attacking": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"coverage&speed": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"defending": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"goalkeeping": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"matches played": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"possession": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"time stats": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"violation&foul&discipline": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
}), |
|
"AwayTeamPlayerStats": Features({ |
|
"attacking": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"coverage&speed": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"defending": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"goalkeeping": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"matches played": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"possession": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"time stats": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
"violation&foul&discipline": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"PlayerName": Value("string"), |
|
"PlayerSurname": Value("string"), |
|
"IsGoalkeeper": Value("bool"), |
|
"PlayedTime": Value("int64"), |
|
"StatsID": Value("int64"), |
|
"StatsName": Value("string"), |
|
"Value": Value("string"), |
|
"Rank": Value("int64"), |
|
})), |
|
}), |
|
}), |
|
"PlayerPreMatchInfo": Features({ |
|
"HomeTeamPlayerInfo": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"JerseyName": Value("string"), |
|
"ShortName": Value("string"), |
|
"GoalScored": Value("float"), |
|
"CleanSheet": Value("float"), |
|
"SuspendedIfBooked": Value("bool"), |
|
"Role": Value("string"), |
|
})), |
|
"AwayTeamPlayerInfo": Sequence(Features({ |
|
"PlayerID": Value("int64"), |
|
"OfficialName": Value("string"), |
|
"OfficialSurname": Value("string"), |
|
"JerseyName": Value("string"), |
|
"ShortName": Value("string"), |
|
"GoalScored": Value("float"), |
|
"CleanSheet": Value("float"), |
|
"SuspendedIfBooked": Value("bool"), |
|
"Role": Value("string"), |
|
})), |
|
}), |
|
}), |
|
supervised_keys=None, |
|
homepage = "https://data.world/cervus/uefa-euro-2020", |
|
citation="""@dataset{UEFA Euro 2020, |
|
creator={Mikhail Zhilkin @cervus}, |
|
year={2021}, |
|
}""" |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
file_url = "https://drive.google.com/uc?id=1RKoAQwq68LASd4ret_OKYUkF4B4m6hnu" |
|
downloaded_file = dl_manager.download(file_url) |
|
|
|
return [ |
|
SplitGenerator( |
|
name="train", |
|
gen_kwargs={"filepath": downloaded_file}, |
|
), |
|
] |
|
|
|
|
|
csv.field_size_limit(sys.maxsize) |
|
|
|
def _generate_examples(self, filepath): |
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f) |
|
for id, row in enumerate(reader): |
|
|
|
match_event_str = row["MatchEvent"] |
|
match_event = yaml.safe_load(match_event_str) |
|
|
|
team_linup_str = row["TeamLineUps"] |
|
team_linup_replaced = team_linup_str.replace(": nan", ": None") |
|
team_linup = ast.literal_eval(team_linup_replaced) |
|
|
|
team_stats_str = row["TeamStats"] |
|
team_stats = yaml.safe_load(team_stats_str) |
|
|
|
player_stats_str = row["PlayerStats"] |
|
player_stats_replaced = player_stats_str.replace('"', '\"') |
|
player_stats = yaml.safe_load(player_stats_replaced) |
|
|
|
pre_match_str = row["PlayerPreMatchInfo"] |
|
pre_match_info = yaml.safe_load(pre_match_str) |
|
|
|
yield id, { |
|
"HomeTeamName": row["HomeTeamName"], |
|
"AwayTeamName": row["AwayTeamName"], |
|
"DateandTimeCET": row["DateandTimeCET"], |
|
"MatchID": row["MatchID"], |
|
"RoundName": row["RoundName"], |
|
"Stage": row["Stage"], |
|
"MatchDay": row["MatchDay"], |
|
"Session": row["Session"], |
|
"MatchMinute": row["MatchMinute"], |
|
"InjuryTime": row["InjuryTime"], |
|
"NumberOfPhases": row["NumberOfPhases"], |
|
"Phase": row["Phase"], |
|
"ScoreHome": row["ScoreHome"], |
|
"ScoreAway": row["ScoreAway"], |
|
"MatchStatus": row["MatchStatus"], |
|
"StadiumID": row["StadiumID"], |
|
"RefereeWebName": row["RefereeWebName"], |
|
"NumberofMatchesRefereedPostMatch": row["NumberofMatchesRefereedPostMatch"], |
|
"TotalNumberofMatchesRefereed": row["TotalNumberofMatchesRefereed"], |
|
"NumberofMatchesRefereedinGroupStage": row["NumberofMatchesRefereedinGroupStage"], |
|
"NumberofMatchesRefereedinKnockoutStage": row["NumberofMatchesRefereedinKnockoutStage"], |
|
"AssistantRefereeWebName": row["AssistantRefereeWebName"], |
|
"Humidity": row["Humidity"], |
|
"Temperature": row["Temperature"], |
|
"WindSpeed": row["WindSpeed"], |
|
"MatchEvent": match_event, |
|
"TeamLineUps": team_linup, |
|
"TeamStats": team_stats, |
|
"PlayerStats": player_stats, |
|
"PlayerPreMatchInfo": pre_match_info, |
|
} |
|
|
|
|