npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nba-movement

v0.3.2

Published

The NBA's player movement API

Downloads

2

Readme

nba-movement (WIP)

This project is under active development. The API will not change but certain observable behaviors likely will. Use at your own risk!

A Node wrapper for easy access to the NBA's player movement API. see example/demo.js for code, or clone this project and run make demo.

Best used with nba

usage

npm install nba-movement

API

getMovementForPlay(Number eventId, String gameId, Function callback) - > void
getMovementForGame(String gameId) -> ReadableStream
Moment(Array tuple) -> MomentStruct

See below

Coordinate(Array tuple) -> CoordinateStruct

See below

Event(Object data) -> EventStruct

See below

Utils

This repo will also house a set of utility functions for working with player movement data. In fact I hope these contain most of the code in the repo, since the core data fetching feature is extremely minimal. Contributions or ideas for helpful utilities are very welcome. For consistency, I would impose only one loose constraint: that utilities should ideally take a data structure below as a parameter and also return one of these data structures. For instance, the closest util takes a Moment and returns a PlayerCoordinate. Obviously this doesn't fit for all cases; a possession util might take a Moment or Event and return a Number representing the possessing team's id.

Data

Data from stats.nba.com is presented in a hierarchy of "event", "moment", "coordinate". An "event" is something like a possession (although events seem to overlap a bit on the margins). An entire game has in the neighborhood of 350 to 400 events. A "moment" is an instant in time; the player tracking cameras capture 24 moments per second. So an event will have a few hundred moments. Finally, a "coordiante" is the exact position of a player or ball during a moment. There should be exactly 11 of these (10 players plus the ball) for each moment.

To save space, the raw NBA player movement API packs this data into tuples. Thanks to the work done here we can assign meaningful keys to each data point and create simple data objects.

Core types: (these types have exposed constructors, as noted above) Coordinate Moment Event

Component types: (these are internal, no need to construct directly) TeamInfo PlayerInfo

Coordinate

Coordinate comes in two flavors:

// BallCoordinate
{
  type: "ball"
  x: Number,
  y: Number,
  z: Number
}

// PlayerCoordinate
{
  type: "player"
  playerId: Number,
  teamId: Number,
  x: Number,
  y: Number
}

A little trick for pulling apart the coordinate list with ES6 destructuring and Lodash or Ramda:

// with Lodash
const [[ball], players] = _.partition(coordinates, {type: "ball"});
// or Ramda
const [[ball], players] = R.partition(R.whereEq({type: "ball"}), coordinates);

Moment

Moment shape:

{
  quarter: Number,
  timestamp: Number,
  gameClock: Number,
  shotClock: Number,
  coorinates: []Coordinate
}

Event

Event shape:

{
  gameId: String,
  gameDate: String,
  visitor: TeamInfo,
  home: TeamInfo,
  moments: []Moment
}

TeamInfo

TeamInfo shape:

{
  name: String,
  teamId: Number,
  abbreviation: String,
  players: []PlayerInfo
}

PlayerInfo

PlayerInfo shape:

{
  lastName: String,
  firstName: String,
  playerId: Number,
  jersey: String,
  position: String
}