GithubHelp home page GithubHelp logo

scorekeepr's Introduction

scorekeepr

This is a very new, and very work-in-progress library for general baseball scorekeeping and game data.

Installation

npm install scorekeepr

API Reference

Check out the API reference here

Setting up a game

The base Scorekeepr class initializes a game that can take a initial game data:

import { Scorekeepr } from 'scorekeepr'

const scorekeeper = new Scorekeepr({
  homeTeam: { abbreviation: 'HT', fullName: 'The Home Team' },
  visitingTeam: { abbreviation: 'VT', fullName: 'The Visiting Team' },
  date: '2020-10-15',
  startTime: '7:30pm',
  location: 'The Stadium',
  // this is mostly for games from other sources (ie, Retrosheet) that have a unique id
  id: 'TheGameId',
  initialInningCount: 7,
  homeLineup: [
    { player: { name: 'Home Player 1' }, position: 1 },
    { player: { name: 'Home Player 2' }, position: 2 }
  ],
  visitingLineup: [
    { player: { name: 'Visiting Player 1' }, position: 1 },
    { player: { name: 'Visiting Player 2' }, position: 2 }
  ]
})

You can also set the game info after intialization:

import { Scorekeepr } from 'scorekeepr'

const gameInfo = {
  date: '2020-10-15',
  startTime: '7:30pm',
  location: 'The Stadium'
}
const sk = new Scorekeepr(gameInfo)

sk.updateGameInfo({
  homeTeam: { abbreviation: 'HT', fullName: 'The Home Team' }
})

If you already have full game data with substitutions and lineup changes, you can add that with the setPlayers method:

import { Scorekeepr } from 'scorekeepr'

const scorekeeper = new Scorekeepr()

sk.setPlayers({
  home: {
    batters: [
      [{ player: { name: 'Home Player 1' }, position: 3, inning: 0 }],
      [{ player: { name: 'Home Player 2' }, position: 3, inning: 1 }]
    ],
    pitchers: [
      {
        player: { name: 'Home Pitcher 1' },
        type: 'starter',
        inning: 0,
        stats: { er: 0 }
      },
      {
        player: { name: 'Home Pitcher 2' },
        type: 'reliever',
        inning: 1,
        stats: { er: 0 }
      }
    ]
  },
  visiting: {
    batters: [
      [
        {
          player: { name: 'Visting Player 1' },
          position: 3,
          inning: 0
        },
        {
          player: { name: 'Visting Player 1' },
          position: 3,
          inning: 1
        }
      ]
    ],
    pitchers: [
      {
        player: { name: 'Visting Pitcher 1' },
        inning: 0,
        type: 'starter',
        stats: { er: 0 }
      }
    ]
  }
})

Recording gameplay

Lineup substitutions

You can record player substitutions with either Scorekeepr.subPlayer or Scorekeepr.subPitcher. The difference is that subPlayer will add the player to both the batting lineup and pitchers list. subPitcher will only add the player to the pitchers list. So if you're using a DH or don't want relief pitchers in the batting lineup, tend towards using subPitcher

Recording game action

All game action currently goes through Scorekeepr.handleGameEvent. Currently, this method is a wide-open footgun that will accept really anything you want to do.

Generators

  • You can pass data directly into handleGameEvent, but I would reccomend leaning on the functions exposed through generators.actions and generators.gameEvents.
  • There are also 2 utility functions exposed in generators.utils - getGameEvent and getBases that take an override parameter generate a full game event and base movement that are very helpful
  • gameEvents are a level up from actions - they themselves typically contain an action from generators.actions & possibly additional data, and return a full gameEvent, which is what handleGameEvent accepts
  • it's very helpful to look at the tests here to see how handleGameEvent is used in orchestration with the generators

A simple example

This is how you would record a walk and a single that moved the runner to third

import { Scorekeepr, generators } from 'scorekeepr'
const sk = new Scorekeepr()
const { utils, actions } = generators

sk.handleGameEvent({
  event: utils.getGameEvent({
    pitches: {
      balls: 3,
      strikes: 0,
      pitchCount: 4
    },
    result: actions.pitcherResult('BB'),
    bases: utils.getBases({
      B: {
        endBase: 1,
        isAtBatResult: true
      }
    })
  }),
  inning: 0,
  lineupSpot: 0,
  team: 'visiting'
})

sk.handleGameEvent({
  event: utils.getGameEvent({
    pitches: {
      balls: 0,
      strikes: 0,
      pitchCount: 1
    },
    result: actions.hit(1),
    bases: utils.getBases({
      B: {
        endBase: 1,
        isAtBatResult: true
      },
      1: {
        endBase: 3
      }
    })
  }),
  inning: 0,
  lineupSpot: 1,
  team: 'visiting'
})

As you can see, it's pretty hard to use. Up next for this library is to abstract out different game actions so that it's a little easier.

Integrations

  • This library currently is mostly used for parsing Retrosheet data. The tools for that can be importing using import * as retrosheet from 'scorekeepr/retrosheet'

scorekeepr's People

Contributors

burdell avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

theredwillow

scorekeepr's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.