SoccerViz


NameSoccerViz JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryA Package to allow analyzing soccer event data easily
upload_time2024-02-15 11:22:35
maintainer
docs_urlNone
authorAthal Akbar
requires_python>=3.8,<=3.12.1
licenseUnlicensed
keywords python soccer soccer analysis passing network
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Installation

Use the package manager [pip](pypi.org) to install 
        
        pip install SoccerViz==0.1.0

Import the necessary Libraries and SoccerViz Package
    
    import re
    import json
    import pandas as pd
    import requests
    from bs4 import BeautifulSoup
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.colors import to_rgba
    import matplotlib.patheffects as path_effects
    from mplsoccer import VerticalPitch, Pitch, FontManager
    from highlight_text import ax_text
    
    #SoccerViz Package
    from SoccerViz import plot,extract,datafilter

Scrape event data from **[WhoScored](whoscored.com)** **_ONLY_** inorder to use it for data analysis and visualization, you would have to fill in the following parameters according to
your liking, below example is given follow it and keep in mind the instructions given too with the code.
    
    
    #This is an example URL from Whoscored.com similar to the below one
    
    url = 'https://www.whoscored.com/Matches/1729462/Live/England-Premier-League-2023-2024-Arsenal-Liverpool'  #This is an example URL from Whoscored.com
    url_shots = 'https://api.sofascore.com/api/v1/event/11352376/shotmap'  
    #This^ is taken from the Sofascore API you can do the same by watching Mckay Johns Tutorial on how to fetch API of shotmaps from Sofascore.

    #Put your USER AGENT in the HEADERS parameter, you can find yours on "https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending"
    
    HEADERS = {
            'User-Agent': "#your user agent"
        }

    headers_shots = { 'Accept': '*/*',
    'Sec-Fetch-Site': 'same-site',
    'Accept-Language': 'en-GB,en;q=0.9',
    # 'Accept-Encoding': 'gzip, deflate, br',
    'Sec-Fetch-Mode': 'cors',
    'Cache-Control': 'max-age=0',
    'Origin': 'https://www.sofascore.com',
    'User-Agent': "same user agent used in normal Headers", 
    'Connection': 'keep-alive',
    'Referer': 'https://www.sofascore.com/',
    'Host': 'api.sofascore.com',
    'Sec-Fetch-Dest': 'empty',
      }   

    shots = requests.get(url_shots, headers=headers_shots)

    #Call the extract functions to get Pass Dataframe,Players Dataframe of the particular match
    
    
    df = extract.pass_data(url,HEADERS)
    players_df = extract.player_data(url,HEADERS)
    
    #You can find the TEAM Id's of the clubs on their WhoScored page html tags by clicking on the club logos
    
    home_team_id=13 #Arsenal Team ID
    away_team_id=26 #Liverpool Team ID

Download the EPL Club data excel file which is present in the repository and assign df_clubs to the file location

    df_clubs = pd.read_excel('#file_local_location')

After scrapping the event data and assembling into DataFrames, you will need to filter the data according to the teams and players.

    #Filter all the data according to the teams by calling the function into DataFrames(their names are pretty self explanatory)

    #You can use and call any dataframe you would like to analyze in raw tables and columns i.e. in a DataFrame form
    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 = datafilter.analyze_passes(df, players_df, home_team_id, away_team_id)

    #Same goes for the shots of the match
    df1_missed,df2_missed,df1_saved,df2_saved,df1_goal,df2_goal,df1_block,df2_block,totalxG1,totalxG2=datafilter.analyze_shots(shots)


Now finally, you can plot the pass network map for both the teams to analyze and visualize by calling the function

    #Call the function and manually put in the home and away team names
    
    plot = plot.pass_network(pass_between_home, pass_between_away, avg_loc_home,avg_loc_away,hometeam_name,awayteam_name)
    
![test1.png](SoccerViz%2Ftest1.png)

Plotting Prg Passes
    
    #Call the function and put in home and away team names
    plot = plot.prg_passes(df_comp_prg_home, df_uncomp_prg_home, df_comp_prg_away, df_uncomp_prg_away, hometeam_name,
                    awayteam_name)
![test.png](SoccerViz%2Ftest.png)

Plotting Shot Maps
    
    #Call the function 
    plot = plot.shot_map(df1_missed, df2_missed, df1_saved, df2_saved, df1_goal, df2_goal, df1_block, df2_block, home_team_id,
                 away_team_id, df_clubs, totalxG1, totalxG2)
    
![test4.png](SoccerViz%2Ftest4.png)

Credits

    Huge Shoutout to the guys at Mplsoccer, do check their package out also, and also checkout Mckay Johns Youtube Channel, which helped me alot in learning python and football analytics
    
    And please don't forget to drop me feedback on Twitter/X, @athalakbar13.

Enjoy!!

    

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "SoccerViz",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<=3.12.1",
    "maintainer_email": "",
    "keywords": "python,soccer,soccer analysis,passing network",
    "author": "Athal Akbar",
    "author_email": "athalkhan13@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2d/c5/4aebda4c61d042706c8ad4aa445f6a1ecfdaa0d3f2e85d702ee4e8655954/SoccerViz-0.1.1.tar.gz",
    "platform": null,
    "description": "Installation\n\nUse the package manager [pip](pypi.org) to install \n        \n        pip install SoccerViz==0.1.0\n\nImport the necessary Libraries and SoccerViz Package\n    \n    import re\n    import json\n    import pandas as pd\n    import requests\n    from bs4 import BeautifulSoup\n    import numpy as np\n    import matplotlib.pyplot as plt\n    from matplotlib.colors import to_rgba\n    import matplotlib.patheffects as path_effects\n    from mplsoccer import VerticalPitch, Pitch, FontManager\n    from highlight_text import ax_text\n    \n    #SoccerViz Package\n    from SoccerViz import plot,extract,datafilter\n\nScrape event data from **[WhoScored](whoscored.com)** **_ONLY_** inorder to use it for data analysis and visualization, you would have to fill in the following parameters according to\nyour liking, below example is given follow it and keep in mind the instructions given too with the code.\n    \n    \n    #This is an example URL from Whoscored.com similar to the below one\n    \n    url = 'https://www.whoscored.com/Matches/1729462/Live/England-Premier-League-2023-2024-Arsenal-Liverpool'  #This is an example URL from Whoscored.com\n    url_shots = 'https://api.sofascore.com/api/v1/event/11352376/shotmap'  \n    #This^ is taken from the Sofascore API you can do the same by watching Mckay Johns Tutorial on how to fetch API of shotmaps from Sofascore.\n\n    #Put your USER AGENT in the HEADERS parameter, you can find yours on \"https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending\"\n    \n    HEADERS = {\n            'User-Agent': \"#your user agent\"\n        }\n\n    headers_shots = { 'Accept': '*/*',\n    'Sec-Fetch-Site': 'same-site',\n    'Accept-Language': 'en-GB,en;q=0.9',\n    # 'Accept-Encoding': 'gzip, deflate, br',\n    'Sec-Fetch-Mode': 'cors',\n    'Cache-Control': 'max-age=0',\n    'Origin': 'https://www.sofascore.com',\n    'User-Agent': \"same user agent used in normal Headers\", \n    'Connection': 'keep-alive',\n    'Referer': 'https://www.sofascore.com/',\n    'Host': 'api.sofascore.com',\n    'Sec-Fetch-Dest': 'empty',\n      }   \n\n    shots = requests.get(url_shots, headers=headers_shots)\n\n    #Call the extract functions to get Pass Dataframe,Players Dataframe of the particular match\n    \n    \n    df = extract.pass_data(url,HEADERS)\n    players_df = extract.player_data(url,HEADERS)\n    \n    #You can find the TEAM Id's of the clubs on their WhoScored page html tags by clicking on the club logos\n    \n    home_team_id=13 #Arsenal Team ID\n    away_team_id=26 #Liverpool Team ID\n\nDownload the EPL Club data excel file which is present in the repository and assign df_clubs to the file location\n\n    df_clubs = pd.read_excel('#file_local_location')\n\nAfter scrapping the event data and assembling into DataFrames, you will need to filter the data according to the teams and players.\n\n    #Filter all the data according to the teams by calling the function into DataFrames(their names are pretty self explanatory)\n\n    #You can use and call any dataframe you would like to analyze in raw tables and columns i.e. in a DataFrame form\n    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 = datafilter.analyze_passes(df, players_df, home_team_id, away_team_id)\n\n    #Same goes for the shots of the match\n    df1_missed,df2_missed,df1_saved,df2_saved,df1_goal,df2_goal,df1_block,df2_block,totalxG1,totalxG2=datafilter.analyze_shots(shots)\n\n\nNow finally, you can plot the pass network map for both the teams to analyze and visualize by calling the function\n\n    #Call the function and manually put in the home and away team names\n    \n    plot = plot.pass_network(pass_between_home, pass_between_away, avg_loc_home,avg_loc_away,hometeam_name,awayteam_name)\n    \n![test1.png](SoccerViz%2Ftest1.png)\n\nPlotting Prg Passes\n    \n    #Call the function and put in home and away team names\n    plot = plot.prg_passes(df_comp_prg_home, df_uncomp_prg_home, df_comp_prg_away, df_uncomp_prg_away, hometeam_name,\n                    awayteam_name)\n![test.png](SoccerViz%2Ftest.png)\n\nPlotting Shot Maps\n    \n    #Call the function \n    plot = plot.shot_map(df1_missed, df2_missed, df1_saved, df2_saved, df1_goal, df2_goal, df1_block, df2_block, home_team_id,\n                 away_team_id, df_clubs, totalxG1, totalxG2)\n    \n![test4.png](SoccerViz%2Ftest4.png)\n\nCredits\n\n    Huge Shoutout to the guys at Mplsoccer, do check their package out also, and also checkout Mckay Johns Youtube Channel, which helped me alot in learning python and football analytics\n    \n    And please don't forget to drop me feedback on Twitter/X, @athalakbar13.\n\nEnjoy!!\n\n    \n",
    "bugtrack_url": null,
    "license": "Unlicensed",
    "summary": "A Package to allow analyzing soccer event data easily",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [
        "python",
        "soccer",
        "soccer analysis",
        "passing network"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "725d7a17b3b88c9bdc410d77785d598a5f1a187ced15ecdb9d8fdeb855858149",
                "md5": "faace0d7653963a48d948bda6bcd5930",
                "sha256": "63c272a1e2a70199c3dc255c38c6e98fb0cbbf0061b6e591906aa754fd6325e0"
            },
            "downloads": -1,
            "filename": "SoccerViz-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "faace0d7653963a48d948bda6bcd5930",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<=3.12.1",
            "size": 8918,
            "upload_time": "2024-02-15T11:22:33",
            "upload_time_iso_8601": "2024-02-15T11:22:33.579037Z",
            "url": "https://files.pythonhosted.org/packages/72/5d/7a17b3b88c9bdc410d77785d598a5f1a187ced15ecdb9d8fdeb855858149/SoccerViz-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2dc54aebda4c61d042706c8ad4aa445f6a1ecfdaa0d3f2e85d702ee4e8655954",
                "md5": "9110aaa8b52f04ec8ba640d15f8c74c7",
                "sha256": "c592116f40144db7da282d1b41e2f700eae9df4af042a967a566dbb5507aaf91"
            },
            "downloads": -1,
            "filename": "SoccerViz-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9110aaa8b52f04ec8ba640d15f8c74c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<=3.12.1",
            "size": 10017,
            "upload_time": "2024-02-15T11:22:35",
            "upload_time_iso_8601": "2024-02-15T11:22:35.366204Z",
            "url": "https://files.pythonhosted.org/packages/2d/c5/4aebda4c61d042706c8ad4aa445f6a1ecfdaa0d3f2e85d702ee4e8655954/SoccerViz-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-15 11:22:35",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "soccerviz"
}
        
Elapsed time: 0.23914s