Code Monkey home page Code Monkey logo

rugbypy's Introduction

rugbypy

rugbypy is a Python package that aims to make rugby data more available to aid in the development of rugby analytics.

Data is updated daily 5AM UTC! Currently we only have 2023 data available with previous years coming soon.

PyPI - Downloads

Requirements

python version 3.8

Install

pip install rugbypy

How to use

Match Stats

You can fetch all the matches that occured on a particular date with:

from rugbypy.match import *
matches = fetch_matches(date="20230101")
matches
Fetching matches on date:20230101...
match_id competition_id home_team_id home_team away_team_id away_team date
0 595735 267979 25907 Northampton Saints 25901 Harlequins 20230101

Then using that match id you can feed it into the match details function:

from rugbypy.match import *
match_details = fetch_match_details(match_id="595735")
match_details
Fetching match details for match_id:595735...
match_id date season competition_id competition venue_id venue city_played home_team away_team home_team_id away_team_id completed is_tournament played_on_grass attendance home_team_form away_team_form
0 595735 20230101 2023 267979 Premiership Rugby 26070 cinch Stadium at Franklin's Gardens Northampton Northampton Saints Harlequins 25907 25901 True True True None LLWWL WLWLL

Team Stats

You can then fetch the team stats for a particular team on a particular date with:

from rugbypy.team import *
team_stats = fetch_team_stats(team_id="25901", date="20230108")
team_stats
Fetching team stats for team_id:25901 on date:20230108...
team game_date team_id team_vs team_vs_id match_id players clean_breaks conversion_goals defenders_beaten ... scrums_total scrums_won tackles territory total_free_kicks_conceded total_lineouts tries turnover_knock_on turnovers_conceded yellow_cards
0 Harlequins 20230108 25901 Sale Sharks 25908 595741 [158708, 299436, 299031, 298485, 295117, 29477... 3.0 0.0 24.0 ... 7.0 5.0 125.0 0.41 0.0 11.0 2.0 8.0 17.0 0.0

1 rows ร— 42 columns

Player Stats

We have the ability to fetch player stats for all the games they have bene involved in. We firstly identify the `player_id`` of a player by searching our player manifest file.

from rugbypy.player import *
player_manifest = fetch_all_players()
player_manifest.head()
player_id player_name
0 246815 Will Edwards
1 158708 Tommaso Allan
2 299436 Oscar Beard
3 299031 Fin Baxter
4 298485 Jordan Els

Or we can search for a certain player through our similarity tool:

from rugbypy.player import *
individual_player = fetch_player(name="johnny sexton")
individual_player
player_id player_name
267 149315 Anthony Watson
294 16004 Johnny Sexton
796 291349 Ayden Johnstone

We can also fetch the player stats for any player using their player_ids. In this example we fetch Johnny Sextons player stats:

from rugbypy.player import *
player_stats = fetch_player_stats(player_id="16004")
player_stats
Fetching all player stats for player_id:16004...
player_id game_date name team team_id competition_id competition match_id team_vs team_vs_id ... rucks_won runs tackles total_free_kicks_conceded total_lineouts tries try_assists turnover_knock_on turnovers_conceded yellow_cards
0 16004 20230204 Johnny Sexton Ireland 3 180659 Six Nations Championship 596205 Wales 4 ... 3.0 8.0 7.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0
0 16004 20230211 Johnny Sexton Ireland 3 180659 Six Nations Championship 596208 France 9 ... 1.0 5.0 3.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0 16004 20230312 Johnny Sexton Ireland 3 180659 Six Nations Championship 596216 Scotland 2 ... 2.0 5.0 9.0 0.0 0.0 0.0 0.0 0.0 2.0 0.0
0 16004 20230318 Johnny Sexton Ireland 3 180659 Six Nations Championship 596219 England 1 ... 6.0 9.0 5.0 0.0 0.0 0.0 0.0 1.0 2.0 0.0
0 16004 20230909 Johnny Sexton Ireland 3 164205 Rugby World Cup 596156 Romania 12 ... 0.0 5.0 4.0 0.0 0.0 2.0 0.0 0.0 0.0 0.0
0 16004 20230916 Johnny Sexton Ireland 3 164205 Rugby World Cup 596166 Tonga 16 ... 1.0 1.0 2.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0
0 16004 20230923 Johnny Sexton Ireland 3 164205 Rugby World Cup 596175 South Africa 5 ... 1.0 3.0 11.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

7 rows ร— 41 columns

rugbypy's People

Contributors

seanyboi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rugbypy's Issues

Example in readme returns error

Firstly thank you so much for this! It will be really useful for me if I can get it working :P

When using the example in the readme, I receive the below error:
No match information for matches played on 20230101 either because no matches took place or rugbypy does not have access to the match data - <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)>. Please raise if neither.

This also happens for any other valid dates I have tried.

Game Scores

Hey!

I love your datasets and how clean they are! Great work!

I was wondering whether you have the scores available though? Perhaps I'm just not looking in the right places?

Include turnovers won in stats

Hi Sean,

Firstly thanks for this very helpful dataset, it's been very interesting to use.

I'm curious if it's possible to add turnovers won by a player into the data, I'm interested at looking at jackal stats, but it's not currently tracked.

Thanks

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.