db

package
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: 5 Imported by: 0

README

README

The nbagame/db package handles syncing data via the stats.nba.com APIs to a local MySQL database. I recommend syncing data locally if you plan on doing any significant work with the data.

Setting up

First, you must create a new MySQL database to populate with NBA data. We assume you name your database 'nbagame':

mysql -e "CREATE DATABASE nbagame"

Either allow all local users access to this database, or edit the dbconf.yml file with the parameters to connect to your new database.

Then, migrate the database by running

goose up

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	DB              *squalor.DB
	Games           *squalor.Model
	Officials       *squalor.Model
	Officiated      *squalor.Model
	Players         *squalor.Model
	Stats           *squalor.Model
	PlayerGameStats *squalor.Model
	TeamGameStats   *squalor.Model
	Teams           *squalor.Model
	Events          *squalor.Model
}

DB encapsulates a connection to an NBAGame database.

func New

func New(env string, confDirectory string) (*DB, error)

New creates a new connection to an NBAGame database. It takes an environment that should be defined in the goose dbconf.yml file.

func WithDSN

func WithDSN(driver, dsn string) (*DB, error)

WithDSN creates a new connection to an NBAGame database, using the specified MySQL driver and DSN.

func (*DB) RecordGameEvent

func (db *DB) RecordGameEvent(gameID data.GameID, evt *data.Event) error

func (*DB) RecordPlayerGameStats

func (db *DB) RecordPlayerGameStats(playerID int, gameID data.GameID, teamID int, stats *data.Stats) error

RecordPlayerGameStats records stats about a player's performance in an individual game. It performs a lookup first to ensure that the player's stats haven't already been synced. If they have, it will update them.

func (*DB) RecordTeamGameStats

func (db *DB) RecordTeamGameStats(teamID int, gameID data.GameID, stats *data.Stats) error

RecordTeamGameStats records stats about a team's performance in an individual game. It performs a lookup first to ensure that the team's stats haven't already been synced. If they have, it will update them.

type Event

type Event struct {
	GameID             data.GameID `db:"game_id"`
	Seq                int         `db:"seq"`
	EventType          string      `db:"event_type"`
	Period             int         `db:"period"`
	ScoreHome          int         `db:"score_home"`
	ScoreVisitor       int         `db:"score_visitor"`
	PeriodTime         int         `db:"period_time"`
	WallClock          string      `db:"wall_clock"`
	Player1ID          *int        `db:"player1_id"`
	Player2ID          *int        `db:"player2_id"`
	Player3ID          *int        `db:"player3_id"`
	HomeDescription    *string     `db:"home_description"`
	NeutralDescription *string     `db:"neutral_description"`
	VisitorDescription *string     `db:"visitor_description"`
}

Event is a db model for the data.Event type.

Directories

Path Synopsis
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