nbagame

package module
v0.0.0-...-52847de Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2016 License: GPL-2.0 Imports: 3 Imported by: 0

README

nbagame

A Go client to retrieve NBA statistics from stats.nba.com. The client also supports syncing data to a mysql database.

GoDoc

Russ

nbaapi.com

If you're just looking for an API for the NBA, check out the nbaapi.com repo that uses nbagame to sync its database.

Overview

The endpoints exposed by nba.com are not intended for public consumption, and no public documentation exists. This package attempts to wrap these endpoints in a clean, well-documented interface.

teams, err := nbagame.Client.Teams()
if err != nil {
  panic(err)
}

for _, team := range teams {
  fmt.Printf("%s, %s - %v\n", team.Name, team.City, team.Wins)
}

Database Syncing

NBAGame is most useful as a means to populate a MySQL database with up-to-date NBA statistics. The nbagame/db/sync package provides a programmatic interface for syncing data. If you don't need the programmatic interface or will be using a language other than go, you can use the command-line tool in the nbagame/cmd package. First, follow the directions in the nbagame/db README to setup your MySQL database and your goose dbconf.yml configuration file. If you have permissions to create new MySQL databases and access them without credentials, you can create the database by running

mysql -e "CREATE DATABASE nbagame"
go get bitbucket.org/liamstask/goose/cmd/goose
goose up

Once your database is constructed, go install ./cmd/... to install the command-line utilities.

To sync data to the entire database, run the following command:

nbagamesync -season="2015-16"

By default, the command-line tool only loads data from the current season (except for players, which will load all historical players too). If you want to load data from a particular season, add the season flag.

nbagamesync -season="2015-16"

If you don't want to sync everything, specify which entities you want to sync as arguments, ex:

nbagamesync teams games

Once you've loaded the data, open a MySQL client and try querying. Here's a sample query that calculates average blocks per game by team.

SELECT teams.id, teams.name, AVG(stats.blocks) AS avg_blocks_per_game
FROM teams
LEFT JOIN team_game_stats ON teams.id = team_game_stats.team_id
LEFT JOIN stats ON team_game_stats.stats_id = stats.id
GROUP BY teams.id ORDER BY avg_blocks_per_game DESC;

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}
var (
	DefaultClient *Client = &Client{
		requester: &endpoints.DefaultRequester,
	}
)

func (*Client) BoxScore

func (c *Client) BoxScore(season data.Season, gameID string) (*data.BoxScore, error)

BoxScore returns the box score for the given game.

func (*Client) GameDetails

func (c *Client) GameDetails(gameID string) (*data.GameDetails, error)

GameDetails returns detailed information about the given game.

func (*Client) GamePlayByPlay

func (c *Client) GamePlayByPlay(season data.Season, gameID string) ([]*data.Event, error)

GamePlayByPlay returns a play-by-play list of events for a game.

func (*Client) Games

func (c *Client) Games(season data.Season) ([]data.GameID, error)

Games returns the game IDs of all of the games played in the season, including playoff games.

func (*Client) GamesByDate

func (c *Client) GamesByDate(date time.Time) ([]*data.Game, error)

GamesByDate retrieves all the NBA games happening on the given date.

func (*Client) GamesPlayedBy

func (c *Client) GamesPlayedBy(season data.Season, teamID int) ([]data.GameID, error)

GamesPlayedBy returns the IDs of all games played by the given team so far in the provided season. Unfortunately, the stats.nba.com API does not provide upcoming games.

func (*Client) HistoricalPlayers

func (c *Client) HistoricalPlayers() ([]*data.Player, error)

HistoricalPlayers returns a slice of all players from all time.

func (*Client) PlayerDetails

func (c *Client) PlayerDetails(playerID int) (*data.PlayerDetails, error)

Details returns detailed information about a player. It does not include stats about the player's performance.

func (*Client) Players

func (c *Client) Players(season data.Season) ([]*data.Player, error)

Players retrieves a slice of all players in the NBA in the provided season.

func (*Client) Teams

func (c *Client) Teams() ([]*data.Team, error)

Teams returns a slice of all the current NBA teams.

Directories

Path Synopsis
cmd
db
sync
This package handles syncing NBA stats from the stats.nba.com endpoints into a MySQL database.
This package handles syncing NBA stats from the stats.nba.com endpoints into a MySQL database.

Jump to

Keyboard shortcuts

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