Skip to content

gkonto/understat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages