GithubHelp home page GithubHelp logo

lucacazzanti / tfutils Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 1.25 MB

A library for parsing and plotting Tracab soccer data from XML files

License: BSD 3-Clause "New" or "Revised" License

Jupyter Notebook 98.18% Python 1.75% Makefile 0.07%
heatmaps soccer soccer-analytics soccer-data xml tracab

tfutils's Introduction

tfutils

A library for parsing Tracab soccer data from XML files.

Utilities to parse, explore, and plot soccer data from XML files by data provider Tracab. Currently only TF05 XML files are supported. See also the companion blog post Main features:

  • Uses soccer sematics to access entitites like teams and players. Example:

    home_team = source.get_team('home')
    player = source.get_player('Lionel MESSI')
    
  • Intuitive interface to plotting heatmaps for teams and players. Example:

    p = source.team_heatmap(team='home', hm_type='overall')
    

    image

  • Retains the methods and attributes of xml.etree.ElementTree.ElementTree, from which it inherits, allowing low-level access to the underlying data. Example:

    home_team = source.find('HomeTeam')
    player = "Megan RAPINOE"
    query = ""Player/[@iPlayerId='{}']".format(player)
    team = source.find('HomeTeam')
    player_node = team.find(query)
    
    # ... gives the same result as
    player = " Megan RAPINOE"
    source.get_player(player)
    

At the moment only Tracab TF05 XML files are supported.

Typical usage:

from tfutils import TracabTF05Xml

# Parse and get basic facts about the macth
source = TracabTF05XML('./data/my_tracab_tf05_file.xml')
source.parse()
source.summary() # prints a summary of the soccer match data

Source file: ./data/my_tracab_tf05_file.xml
Home team name and ID:Syria, 43838
Away team name and ID: Mauritania, 43870
Match date: 2021-12-06 18:00:00
Match ID: 129650
Match duration: 98.614 minutes

# List of players ...
source.get_team_players('away')
{'id': ['431494',
  '391160',
  '431495',
  '433176',
  '436778',
  '431501',
  '393847',
  '431516',
  '395993',
  '431489',
  '392901',
  '431511',
  '431500',
  '433659',
  '431488'],
 'jersey': ['1',
  '2',
  '3',
  '4',
  '6',
  '7',
  '8',
  '9',
  '10',
  '12',
  '14',
  '17',
  '18',
  '21',
  '23'],
 'name': ["M'backe N'DIAYE",
  'El Mostapha DIAW',
  'Mohamedhen BEIBOU',
  'Harouna ABOU',
  'Gussouma FOFANA',
  'Idrissa THIAM',
  'Amadou NIASS',
  'Hemeya TANJI',
  'Adama BÀ',
  'Alassane DIOP',
  'Mohamed Dellah YALY',
  'Demba TRAWRE',
  'Mouhsine BODDA',
  'Ablaye SY',
  'Mohamed SOUEID']}

# ... you can also use the team name itself and put the resulting dictionary in a dataframe
team_players = source.get_team_players('Mauritania')
players_df = pd.DataFrame.from_dict(team_players)
players_df

image

p = source.team_possession_heatmap(team='away', hm_type='first-half')

image

p = source.player_heatmap(player='431495')

image

Installation

> git clone [email protected]:your_fork/tfutils.git
> cd tfutils
> pip install -r requirements.txt .

# ... or, to install the dev version:
> pip install -r requirements.txt -e .
 
# If you prefer make:
> make install 
# ... or ...
> make dev-install

tfutils's People

Contributors

lucacazzanti avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.