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

espn-ff-utilities

v0.4.0

Published

A module that utilizes ESPN's fantasy football API structure to provide useful data about a teams performance on a weekly basis

Downloads

2

Readme

espn-ff-utilities

Overview

A library for extracting useful metrics from ESPN's v3 fantasy football API. The API isn't well documented so it's mostly been figured out by inspecting network calls on the ESPN fantasy website. If you are looking to utilize this package you will need information using the following URL. http://fantasy.espn.com/apis/v3/games/ffl/seasons/<year>/segments/0/leagues/<leagueId>?view=mBoxscore&view=mMathcupScore&view=mTeams&view=mSettings

Some notes about the endpoint

  • League Id can be obtained by logging in to ESPN's fantasy website and finding it in the URL
  • To fetch responses from this URL you will need the SWID and espn_s2 cookies from the .espn.com domain
  • For now this package only works with the information provided from the query parameters specified above as well as a specified scoringPeriodId query parameter to fetch results for past weeks.

Relevant Fields

This module uses information from the settings and schedule fields of the response. The teams and scoringPeriodId fields are not used directly by this module but are helpful for providing this module with the necessary information.

Functions

adjustedVictories

adjustedVictories(
    scoringPeriodId: number,
    teamId: number,
    schedule: Array<Matchup>
) => number

Calculates the number of victories a team would have secured if they played every other team in the league that week. For example:

Team 1: 105pts, Team 2: 110pts, Team 3: 100pts

Team 1 adjusted victories = 1Team 2 adjusted victories = 2Team 3 adjusted victories = 0

bestWeeklyScore

bestWeeklyScore(
        scoringPeriodId: number,
        teamId: number,
        schedule: Array<Matchup>,
        settings: Settings
) => number

Calculates the highest possible score a team could have achieved during a given week given the league's roster settings.

realWeeklyScore

realWeeklyScore(
    scoringPeriodId: number,
    teamId: number,
    schedule: Array<Matchup>
) => number

Find a teams actual posted score for a given scoring period.

recordVersus

recordVersus(
    scoringPeriodId: number,
    teamId: number,
    opposingIds: Array<number>,
    schedule: Array<Matchup>
) => { wins: number, losses: number }

Calculates a team's record against a given array of opponents up to a specified scoring period.

  • Note: Passing an empty array to opposingIds will calculate the team's record against all opponents up to the given scoring period

didWin

didWin(
    scoringPeriodId: number,
    teamId: number,
    schedule: Array<Matchup>
) => boolean

Determines if a team won their matchup in a given scoring period.

Initialization

All functions are provided in their raw form through the default import:

import { adjustedVictories, bestWeeklyScore } from 'espn-ff-utilities';
...
adjustedVictories(scoringPeriodId, teamId, schedule);
bestWeeklyScore(scoringPeriodId, teamId, schedule, settings);

There are also different initialization options

init

init(
    schedule: Array<Matchup>,
    settings: Settings
) => InitializedFns

This option pre-sets the schedule and settings for all future function calls.

import { init as espnFfInit } from 'espn-ff-utilities';

const { 
    adjustedVictories, 
    bestWeeklyScore,
    realWeeklyScore,
    recordVersus,
    didWin,
} = espnFfInit(scoringPeriodId, schedule, settings);
...
adjustedVictories(scoringPeriodId, teamId);
bestWeeklyScore(scoringPeriodId, teamId);
realWeeklyScore(scoringPeriodId, teamId);
recordVersus(scoringPeriodId, teamId, opposingIds);
didWin(scoringPeriodId, teamId);

initForScoringPeriod

initForScoringPeriod(
    scoringPeriodId: number,
    schedule: Array<Matchup>,
    settings: Settings
) => InitializedWithSpiFns

This option pre-sets the schedule, setting, and scoring period for all future function calls.

import { initForScoringPeriod as espnFfInit } from 'espn-ff-utilities';

const { 
    adjustedVictories, 
    bestWeeklyScore,
    realWeeklyScore,
    recordVersus,
    didWin,
} = espnFfInit(scoringPeriodId, schedule, settings);
...
adjustedVictories(teamId);
bestWeeklyScore(teamId);
realWeeklyScore(teamId);
recordVersus(teamId, opposingIds);
didWin(teamId);