understat

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2025 License: MIT Imports: 2 Imported by: 0

README

Understat Statistics Module

The Understat Statistics Module is a Go library designed to fetch and process football data from the Understat website. It provides convenient APIs to retrieve player, game, and team statistics for specific leagues and years. This module provides an easy way to access and work with Understat data, making it suitable for developers, analysts, or anyone interested in football statistics.


Features

  • Player Statistics: Retrieve detailed data about players.
  • Game Statistics: Fetch game results and related statistics.
  • Team Statistics: Access team performance data.
  • Easy-to-use APIs for interacting with Understat data.
  • Comprehensive test suite for robust functionality.

Prerequisites

Ensure you have the following installed before using this module:

  • Go (version 1.23 or later)

  1. To install the Understat module, use the following go get command:
go get github.com/gkonto/understat
  1. Download and resolve dependencies
   go mod tidy

Usage

Example: Fetching Football Data

  1. Import the required packages:
import (
    "github.com/gkonto/understat"
    "github.com/gkonto/understat/model"
)
  1. Create an instance of UnderstatAPI:
api := understat.NewUnderstatAPI()
  1. Fetch and display data:
  • Players:
players, err := api.GetPlayers(model.League("EPL"), model.Year(2023))
if err != nil {
    fmt.Println("Error fetching players:", err)
    return
}
fmt.Println("Players:", players)

  • Games:
games, err := api.GetGames(model.League("EPL"), model.Year(2023))
if err != nil {
    fmt.Println("Error fetching games:", err)
    return
}
fmt.Println("Games:", games)
  • Teams:
teams, err := api.GetTeams(model.League("EPL"), model.Year(2023))
if err != nil {
    fmt.Println("Error fetching teams:", err)
    return
}
fmt.Println("Teams:", teams)

Caching mechanism

The UnderstatAPI uses a built-in caching mechanism to store data for each API call. Subsequent requests for the same data (e.g., the same league and year) will be retrieved much faster from the cache.

To clear the cache: Currently, the only way to clear the cache is to create a new UnderstatAPI instance:

api = understat.NewUnderstatAPI() // This resets the cache

This feature helps improve performance, especially when dealing with repeated queries.


Running Tests

To validate the functionality of the module, you can run the included test suite:

  1. Run all tests:
go test ./...
  1. For verbose output:
go test ./... -v
  1. Run specific test files:
go test ./internal/controller -v

License

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

Acknowledgements

  • Inspired by the comprehensive data on Understat.
  • Developed with Go for performance and simplicity.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UnderstatAPI

type UnderstatAPI struct {
	// contains filtered or unexported fields
}

func NewUnderstatAPI

func NewUnderstatAPI() *UnderstatAPI

func (*UnderstatAPI) GetGames

func (p *UnderstatAPI) GetGames(league model.League, year model.Year) (model.Games, error)

func (*UnderstatAPI) GetPlayers

func (p *UnderstatAPI) GetPlayers(league model.League, year model.Year) (model.Players, error)

func (*UnderstatAPI) GetTeams

func (p *UnderstatAPI) GetTeams(league model.League, year model.Year) (model.Teams, error)

Directories

Path Synopsis
cmd
profile command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL