Metadata-Version: 2.1
Name: rugbypy
Version: 1.0.0
Summary: Repository for rugby data analytics
Home-page: https://github.com/seanyboi/rugbypy
Author: seanyboi
Author-email: oconnorjamessean@gmail.com
License: Apache Software License 2.0
Keywords: nbdev jupyter notebook python
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: fastcore
Requires-Dist: pandas (>=2.0.3)
Requires-Dist: black
Requires-Dist: pyarrow (>=13.0.0)
Requires-Dist: requests
Provides-Extra: dev

rugbypy
================

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

`rugbypy` is a Python package that aims to make rugby data more
available to aid in the development of rugby analytics. Currently we
only have 2023 data available with previous years coming soon!

![PyPI - Downloads](https://img.shields.io/pypi/dm/rugbypy)

## Requirements

python version 3.8

## Install

``` sh
pip install rugbypy
```

## How to use

### Match Stats

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

``` python
matches = fetch_matches(date="20230101")
matches
```

    Fetching matches on date:20230101...

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>match_id</th>
      <th>competition_id</th>
      <th>home_team_id</th>
      <th>away_team_id</th>
      <th>date</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>595735</td>
      <td>267979</td>
      <td>25907</td>
      <td>25901</td>
      <td>20230101</td>
    </tr>
  </tbody>
</table>
</div>

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

``` python
match_details = fetch_match_details(match_id="595735")
match_details
```

    Fetching match details for match_id:595735...

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>match_id</th>
      <th>date</th>
      <th>competition_id</th>
      <th>competition</th>
      <th>venue_id</th>
      <th>venue</th>
      <th>city_played</th>
      <th>home_team</th>
      <th>away_team</th>
      <th>home_team_id</th>
      <th>away_team_id</th>
      <th>completed</th>
      <th>is_tournament</th>
      <th>played_on_grass</th>
      <th>attendance</th>
      <th>home_team_form</th>
      <th>away_team_form</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>595735</td>
      <td>20230101</td>
      <td>267979</td>
      <td>Premiership Rugby</td>
      <td>26070</td>
      <td>cinch Stadium at Franklin's Gardens</td>
      <td>Northampton</td>
      <td>Northampton Saints</td>
      <td>Harlequins</td>
      <td>25907</td>
      <td>25901</td>
      <td>True</td>
      <td>True</td>
      <td>True</td>
      <td>None</td>
      <td>LLWWL</td>
      <td>WLWLL</td>
    </tr>
  </tbody>
</table>
</div>

### Team Stats

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

``` python
team_stats = fetch_team_stats(team_id="25901", date="20230108")
team_stats
```

    Fetching team stats for team_id:25901 on date:20230108...

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>team</th>
      <th>game_date</th>
      <th>team_id</th>
      <th>team_vs</th>
      <th>team_vs_id</th>
      <th>clean_breaks</th>
      <th>conversion_goals</th>
      <th>defenders_beaten</th>
      <th>kick_percent_success</th>
      <th>kicks</th>
      <th>...</th>
      <th>scrums_total</th>
      <th>scrums_won</th>
      <th>tackles</th>
      <th>territory</th>
      <th>total_free_kicks_conceded</th>
      <th>total_lineouts</th>
      <th>tries</th>
      <th>turnover_knock_on</th>
      <th>turnovers_conceded</th>
      <th>yellow_cards</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Harlequins</td>
      <td>20230108</td>
      <td>25901</td>
      <td>Sale Sharks</td>
      <td>25908</td>
      <td>3.0</td>
      <td>0.0</td>
      <td>24.0</td>
      <td>0.5</td>
      <td>0.0</td>
      <td>...</td>
      <td>7.0</td>
      <td>5.0</td>
      <td>125.0</td>
      <td>0.41</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>2.0</td>
      <td>8.0</td>
      <td>17.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
<p>1 rows × 40 columns</p>
</div>

### 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.

``` python
player_manifest = fetch_all_players()
player_manifest.head()
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>player_id</th>
      <th>player_name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>246815</td>
      <td>Will Edwards</td>
    </tr>
    <tr>
      <th>1</th>
      <td>158708</td>
      <td>Tommaso Allan</td>
    </tr>
    <tr>
      <th>2</th>
      <td>299436</td>
      <td>Oscar Beard</td>
    </tr>
    <tr>
      <th>3</th>
      <td>299031</td>
      <td>Fin Baxter</td>
    </tr>
    <tr>
      <th>4</th>
      <td>298485</td>
      <td>Jordan Els</td>
    </tr>
  </tbody>
</table>
</div>

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

``` python
individual_player = fetch_player(name="johnny sexton")
individual_player
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>player_id</th>
      <th>player_name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>267</th>
      <td>149315</td>
      <td>Anthony Watson</td>
    </tr>
    <tr>
      <th>294</th>
      <td>16004</td>
      <td>Johnny Sexton</td>
    </tr>
    <tr>
      <th>796</th>
      <td>291349</td>
      <td>Ayden Johnstone</td>
    </tr>
  </tbody>
</table>
</div>

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

``` python
player_stats = fetch_player_stats(player_id="16004")
player_stats
```

    Fetching all player stats for player_id:16004...

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>player_id</th>
      <th>game_date</th>
      <th>name</th>
      <th>team</th>
      <th>team_id</th>
      <th>competition_id</th>
      <th>competition</th>
      <th>team_vs</th>
      <th>team_vs_id</th>
      <th>weight</th>
      <th>...</th>
      <th>rucks_won</th>
      <th>runs</th>
      <th>tackles</th>
      <th>total_free_kicks_conceded</th>
      <th>total_lineouts</th>
      <th>tries</th>
      <th>try_assists</th>
      <th>turnover_knock_on</th>
      <th>turnovers_conceded</th>
      <th>yellow_cards</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>16004</td>
      <td>20230204</td>
      <td>Johnny Sexton</td>
      <td>Ireland</td>
      <td>3</td>
      <td>180659</td>
      <td>Six Nations Championship</td>
      <td>4</td>
      <td>Wales</td>
      <td>92.0</td>
      <td>...</td>
      <td>3.0</td>
      <td>8.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>0</th>
      <td>16004</td>
      <td>20230211</td>
      <td>Johnny Sexton</td>
      <td>Ireland</td>
      <td>3</td>
      <td>180659</td>
      <td>Six Nations Championship</td>
      <td>9</td>
      <td>France</td>
      <td>92.0</td>
      <td>...</td>
      <td>1.0</td>
      <td>5.0</td>
      <td>3.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>0</th>
      <td>16004</td>
      <td>20230312</td>
      <td>Johnny Sexton</td>
      <td>Ireland</td>
      <td>3</td>
      <td>180659</td>
      <td>Six Nations Championship</td>
      <td>2</td>
      <td>Scotland</td>
      <td>92.0</td>
      <td>...</td>
      <td>2.0</td>
      <td>5.0</td>
      <td>9.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>0</th>
      <td>16004</td>
      <td>20230318</td>
      <td>Johnny Sexton</td>
      <td>Ireland</td>
      <td>3</td>
      <td>180659</td>
      <td>Six Nations Championship</td>
      <td>1</td>
      <td>England</td>
      <td>92.0</td>
      <td>...</td>
      <td>6.0</td>
      <td>9.0</td>
      <td>5.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>0</th>
      <td>16004</td>
      <td>20230909</td>
      <td>Johnny Sexton</td>
      <td>Ireland</td>
      <td>3</td>
      <td>164205</td>
      <td>Rugby World Cup</td>
      <td>12</td>
      <td>Romania</td>
      <td>92.0</td>
      <td>...</td>
      <td>0.0</td>
      <td>5.0</td>
      <td>4.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>0</th>
      <td>16004</td>
      <td>20230916</td>
      <td>Johnny Sexton</td>
      <td>Ireland</td>
      <td>3</td>
      <td>164205</td>
      <td>Rugby World Cup</td>
      <td>16</td>
      <td>Tonga</td>
      <td>92.0</td>
      <td>...</td>
      <td>1.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
<p>6 rows × 40 columns</p>
</div>


