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

askretro

v0.1.5

Published

Experimental, customizable event driven retrosheet event file processor for developing applications that analyze historical major league baseball data.

Downloads

18

Readme

askRetro

Experimental, customizable event driven retrosheet event file processor for developing applications that analyze historical major league baseball data.

Askretro traverses each event file line by line and maintains the state of the game as each event (play, substitution, etc) occurs. It also emits events to which users can subscribe using callbacks that process the current game state and event information.

Installation

npm install askRetro

Game state

AskRetro maintains the game state at all times. The state object contains the following fields:

Field | Description ----- | ----------- id | The retrosheet id of the game (eg, ANA201704070) previousPlay | The play information from the previous line of the file presentPlay | The play information from the line currently being processed baseRunners | The baserunner object (see below) lineups | The lineup objects (see below - 0 = visiting team, 1 = home team) inning | The current inning outs | The current number of outs currentBatter | The retrosheet id of the current batter (eg., maybc001) score | The score object (0 = visiting team, 1 = home team) battingTeam | The team currently batting (0 = visiting team, 1 = home team)

baseRunners

Field | Description | Default ----- | ----------- | ------- 0 | retrosheet id of the batter | N/A 1 | retrosheet id of the runner on first | null 2 | retrosheet id of the runner on | null 3 | retrosheet id of the runner on third | null

batting lineup

Field | Description | Default ----- | ----------- | ------- 0 | retrosheet id of the pitcher when a designated hitter is used | null 1 | retrosheet id of the first batter 2 | retrosheet id of the second batter 3 | retrosheet id of the third batter 4 | retrosheet id of the fourth batter 5 | retrosheet id of the fifth batter 6 | retrosheet id of the sixth batter 7 | retrpsheet id of the seventh batter 8 | retrosheet id of the eight batter 9 | retrosheet id of the ninth batter

fielding lineup

Field | Description | Default ----- | ----------- | ------- 1 | retrosheet id of the pitcher 2 | retrosheet id of the catcher 3 | retrosheet id of the first baseman 4 | retrosheet id of the second baseman 5 | retrosheet id of the third baseman 6 | retrosheet id of the shortstop 7 | retrosheet id of the left fielder 8 | retrosheet id of the center fielder 9 | retrosheet id of the right fielder 10 | retrosheet id of the designated hitter (if applicable) 11 | retrosheet id of a pinch hitter (when applicable) 12 | retrosheet id of a pinch runner (when applicable)

Example state object
{
  id:'ANA201504120',
  previousPlay:{
    inning:2,
    team:0,
    id:'riosa002',
    count:'01',
    pitches:'CX',
    playInfo:'S9/L.1-2'
  },
  presentPlay:{
    inning:2,
    team:0,
    id:'peres002',
    count:'00',
    pitches:'X',
    playInfo:'S8/G.2-H;1-2'
  },
  baseRunners:{
    0:'peres002',
    1:'riosa002',
    2:'morak001',
    3:null
  },
  lineups:{
    0:{
      batting:{
        0:'venty001',
        1:'escoa003',
        2:'mousm001',
        3:'cainl001',
        4:'hosme001',
        5:'morak001',
        6:'riosa002',
        7:'peres002',
        8:'orlap001',
        9:'infao001'
      },
      fielding:{
        1:'venty001',
        2:'peres002',
        3:'hosme001',
        4:'infao001',
        5:'mousm001',
        6:'escoa003',
        7:'orlap001',
        8:'cainl001',
        9:'riosa002',
        10:'morak001'
      }
    },
    1:{
      batting:{
        0:'wilsc004',
        1:'aybae001',
        2:'troum001',
        3:'pujoa001',
        4:'joycm001',
        5:'freed001',
        6:'cronc002',
        7:'iannc001',
        8:'cowgc001',
        9:'featt001'
      },
      fielding:{
        1:'wilsc004',
        2:'iannc001',
        3:'pujoa001',
        4:'featt001',
        5:'freed001',
        6:'aybae001',
        7:'joycm001',
        8:'troum001',
        9:'cowgc001',
        10:'cronc002'
      }
    }
  },
  inning:2,
  outs:0,
  currentBatter:'peres002',
  score:{
    0:0,
    1:1
  },
  battingTeam:0

Available events

  • newGame: triggered when a new game id is detected in the file, just before the game state is reset
  • newInning: triggered at the end of an inning just before the inning is reset in the game state
  • lineupChange: triggered once for each starter at the beginning of the game and again each time there is a substitution during the game.
  • processInfo: triggered when the processor encounters an 'info' line in the file
  • processStart: triggered when the processor encounters a 'start' line in the file
  • processPlay: triggered when the processor encounters a 'play' line in the file
  • processSub: triggered when the processor encounters a 'sub' line in the file
  • end: triggered at the end of the game
  • out: triggered whenever an out occurs
  • run: triggered whenever a run is scored
  • rbi: triggered whenever an rbi is credited to the hitter
  • advanceRunners: triggered just before runners advance on any given play
  • balk: triggered when the pitcher is charged with a balk
  • caughtStealing: triggered when a runner is caught stealing
  • defensiveIndifference: triggered when a runner is awarded a base due to defensive indifference
  • hit: triggered when the batter gets a hit (single, double, triple, home run)
  • hitByPitch: triggered when the batter is hit by a pitch
  • error: triggered when a fielding error occurs
  • flyBallOut: triggered when the batter hits into a fly ball out
  • groundBallOut: triggered when the batter hits into a ground ball out
  • otherAction: triggered when something strange happens
  • pickoff: triggered when a runner is picked off a base
  • stolenBase: triggered when a runner steals a base
  • strikeout: triggered when a batter strikes out
  • walk: triggered when a batter walks
  • wildPitch: triggered when a pitcher is charged with a wild pitch
  • beforeFileLoad: triggered just before a new file is loaded
  • afterFileLoad: triggered after a file loads

Examples

Walk through all games from 2017 and console log all homeruns

'use strict';
const askRetro = require('askretro');

const startYear = 2017;
const endYear = 2017;

askRetro.configuration.configure({ startYear, endYear, loggingLevel: 'error' });

const logHomer = (hitter) => {
  console.log(`${hitter} just hit a home run!`);
}

const hit = (state, info) => {
  const play = info.playInfo;
  if (/^(H|HR)[1-9]*?$/.test(play)) logHomer(state.currentBatter);
};

askRetro.subscribe('hit', hit);

askRetro.processFiles()
  .then(() => {
    console.log('done');
  })
  .catch(err => {
    console.log(err);
  })