Skip to main content

A package to allow analyzing soccer event data easily

Project description

scrapelytix

Welcome to Scrapelytix! This package allows you to scrape football event data and visualize various metrics like pass-maps, progressive passes, shot-maps. We will show you how to scrape whoscored, sofascore and fbref to gather data in the first place.

Installation

First, install the package using pip: pip install scrapelytix

Usage Guide

Step 1: Prepare the Data

To use Scrapelytix, you need to provide the URL of the match scorecard from the match center you want to scrape and your User-Agent.

Step 2: Scrape the Data

Here's a step-by-step guide to using Scrapelytix:

Import the Required Modules:

import re import json import pandas as pd import requests import numpy as np from Datawiz.extraction import pass_data, player_data from Datawiz.filter import analyze_passes, analyze_shots from Datawiz.plot import pass_network, prg_passes, shot_map

Prompt the User for the URL:

url = input("Enter the URL for pass data: ") url_shots = 'https://api.sofascore.com/api/v1/event/11352376/shotmap' HEADERS = { 'User-Agent': your user agent, 'Referer': "https://www.whoscored.com/", 'Accept-Language': "en-US,en;q=0.5", 'Accept-Encoding': "gzip, deflate, br", 'Connection': "keep-alive", 'Upgrade-Insecure-Requests': "1", 'TE': "Trailers" }

Extract Player and Pass Data:

players_df, df_passes = player_data(url, HEADERS) print(players_df.head()) print(df_passes.head())

Analyze Passes:

Extracting team ids

team_ids = df_passes['teamId'].unique()

Defining home and away colors for each team

home_colors = ['#FF0000', '#0000FF'] # Example colors (replace with actual colors) away_colors = ['#FFFFFF', '#FFFFFF'] # Example colors (replace with actual colors)

Creating DataFrame for clubs with team IDs and labels

df_clubs = pd.DataFrame({'Team ID': team_ids, 'Team Label': ['Team X', 'Team Y'], 'Team Name': ['Team X', 'Team Y'], 'Home Color': home_colors, 'Away Color': away_colors})

Assuming there are only two teams, you can assign home and away team IDs accordingly

home_team_id = team_ids[0] away_team_id = team_ids[1]

pass_between_home, pass_between_away, avg_loc_home, avg_loc_away, passes_home, passes_away, df_prg_home, df_comp_prg_home, df_uncomp_prg_home, df_prg_away, df_comp_prg_away, df_uncomp_prg_away = analyze_passes(df_passes, players_df, home_team_id, away_team_id)

Example print statements to verify the results

print("Passes Between Home Players:") print(pass_between_home.head())

print("Average Locations of Home Players:") print(avg_loc_home.head())

print("Home Team Progressive Passes:") print(df_prg_home.head())

Visualize the Data:

Pass Network Visualization

pass_network(pass_between_home, pass_between_away, avg_loc_home, avg_loc_away, home_team_id, away_team_id, df_clubs)

Progressive Passes Visualization

prg_passes(df_comp_prg_home, df_uncomp_prg_home, df_comp_prg_away, df_uncomp_prg_away, home_team_id, away_team_id, df_clubs)

Output Samples

To better illustrate the steps, you can include screenshots of the outputs after each significant step. This will help users understand the intermediate results and the final visualizations.

  1. Initial Data Extraction:

    • Player Data
    • Pass Data
  2. Pass Network Visualization:

    • Pass Network
  3. Progressive Passes Visualization:

    • Progressive Passes

Conclusion

Scrapelytix makes it easy to scrape football match data and visualize important statistics. By following the steps above, you can analyze and visualize data for any match you are interested in.

Feel free to explore the package and provide feedback or contributions on GitHub!

Contribution

Contributions are welcome! If you find any issues or have suggestions, please open an issue or create a pull request on the GitHub repository(https://github.com/gxdfather7/scrapelytix).

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Scrapelytix-0.0.2.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Scrapelytix-0.0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file Scrapelytix-0.0.2.tar.gz.

File metadata

  • Download URL: Scrapelytix-0.0.2.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.1

File hashes

Hashes for Scrapelytix-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d3182ddc6ad2de4e0f0434b5fbed6d337064756079ffe9d41a37bb313c81a9ad
MD5 c3f09371cf6d129317406a90366f0f58
BLAKE2b-256 7435a70245d17ecf7ff2b3f4eb3291a50e92545cb97cde36834e7522996a4975

See more details on using hashes here.

File details

Details for the file Scrapelytix-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: Scrapelytix-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.1

File hashes

Hashes for Scrapelytix-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce26b4d3cb395cf11022e8f4ecf0845c33125b6b909e5f8600768a6ab3601e64
MD5 c6a26aa5d08004dc81081ad5f973813e
BLAKE2b-256 15f06cf930b545923e7ebc22d54f5882375c90c9d2400aa63ee49c80d81f3c6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page