Comments (14)
Agreed, if it's something you need help with I can probably cleanup the simple node server I started with and put in a PR sometime this weekend.
from espn-fantasy-football-api.
Here's a script I wrote with the client to calculate the best possible lineup each team could have started for a week:
const _ = require('lodash');
const { Client } = require('./node-dev');
const myClient = new Client({
// your deets here
});
class Psychic {
static filterPosition(boxscorePlayer, position) {
return (
boxscorePlayer.position === position ||
_.includes(boxscorePlayer.player.eligiblePositions, position)
);
}
static handleNonFlexPosition(lineup, position) {
const players = _.filter(lineup, (player) => this.filterPosition(player, position));
const sortedPlayers = _.sortBy(players, ['totalPoints']);
return _.last(sortedPlayers);
}
static analyzeLineup(lineup, score) {
let bestSum = 0;
const bestRoster = [];
let numChanges = 0;
const bestQB = this.handleNonFlexPosition(lineup, 'QB')
bestRoster.push(bestQB.player.fullName);
bestSum += bestQB.totalPoints;
if (bestQB.position === 'Bench') {
numChanges += 1;
}
const bestDefense = this.handleNonFlexPosition(lineup, 'D/ST')
bestRoster.push(bestDefense.player.fullName);
bestSum += bestDefense.totalPoints;
if (bestDefense.position === 'Bench') {
numChanges += 1;
}
const bestKicker = this.handleNonFlexPosition(lineup, 'K')
bestRoster.push(bestKicker.player.fullName);
bestSum += bestKicker.totalPoints;
if (bestKicker.position === 'Bench') {
numChanges += 1;
}
const flexPlayers = _.filter(lineup, (player) => this.filterPosition(player, 'RB') ||
this.filterPosition(player, 'WR') ||
this.filterPosition(player, 'TE')
);
const sortedFlexPlayers = _.sortBy(flexPlayers, ['totalPoints']);
const flexPos = { RB: 2, WR: 2, TE: 1, FLEX: 1 };
while (_.sum(_.values(flexPos)) && !_.isEmpty(sortedFlexPlayers)) {
const player = sortedFlexPlayers.pop();
const acceptPlayer = () => {
bestRoster.push(player.player.fullName);
bestSum += player.totalPoints;
if (player.position === 'Bench') {
numChanges += 1;
}
}
if (flexPos.RB && _.includes(player.player.eligiblePositions, 'RB')) {
acceptPlayer();
flexPos.RB -= 1;
} else if (flexPos.WR && _.includes(player.player.eligiblePositions, 'WR')) {
acceptPlayer();
flexPos.WR -= 1;
} else if (flexPos.TE && _.includes(player.player.eligiblePositions, 'TE')) {
acceptPlayer();
flexPos.TE -= 1;
} else if (flexPos.FLEX) {
acceptPlayer();
flexPos.FLEX -= 1;
}
}
return {
bestSum,
bestRoster,
currentScore: score,
numChanges
};
}
static runForWeek({ seasonId, matchupPeriodId, scoringPeriodId }) {
const bestLineups = {};
return myClient.getBoxscoreForWeek({ seasonId, matchupPeriodId, scoringPeriodId }).then((boxes) => {
_.forEach(boxes, (box) => {
bestLineups[box.awayTeamId] = this.analyzeLineup(box.awayRoster, box.awayScore);
bestLineups[box.homeTeamId] = this.analyzeLineup(box.homeRoster, box.homeScore);
});
return bestLineups;
});
}
}
Psychic.runForWeek({ seasonId: 2019, matchupPeriodId: 4, scoringPeriodId: 4 }).then((result) => {
console.log(result);
return result;
});
from espn-fantasy-football-api.
@Seth-Duncan I was just messing around with a React chrome extension boilerplate and the ESPN api integrated so maybe that will help you get your Vue app running. If you're not sure how to setup a Node server, it might be best to start with a Vue boilerplate that incorporates all of that for you already (like I've done):
https://github.com/jamigibbs/espn-fantasy-chrome-extension/blob/master/src/pages/Popup/Popup.jsx
from espn-fantasy-football-api.
Is this something you currently need, or are you requesting this to help the next person because you had alot of trouble getting it working?
I'm asking because if you already went through it, then write it up yourself and post it here. @mkreiser is obviously busy, and any help we can give is great!
If you need some help, post your questions and I and others will try to help you through it.
from espn-fantasy-football-api.
Thanks for the responses!
I’m not able to write this but I can test/review/pr against someone else’s work after the fact; by following the dummies guide to interface my private league.
from espn-fantasy-football-api.
I'm not a nodejs novice, but I am a bit mystified by the usage examples in the README. I'm used to using require
not import
, so I'm not sure what to do about the syntax error that import { ... } from 'espn-fantasy-football-api/node';
causes. Google suggests that nodejs only has experimental support for ES6 modules, but I can't figure out what that means for this situation. A brief usage example for command line nodejs would really help.
from espn-fantasy-football-api.
agreed. I think a ticket I opened not long ago had an example someone gave me. For now, look that up.
from espn-fantasy-football-api.
Thanks, I found this on the v3 upgrade issue, which worked for me:
const { Client } = require("espn-fantasy-football-api/node");
const myClient = new Client({ leagueId: my league id here });
Dropping it here for anyone else who has the same problem and finds this thread.
from espn-fantasy-football-api.
I’m holding onto hope that @ReeceLangerock swoops in and posts an example :)
from espn-fantasy-football-api.
Thanks for everything here, this is truly amazing! Would it be possible to post an example showing how to pull in boxscores for a specific matchupPeriodID? I'm on the verge of understanding getBoxscoreForWeek(), but for some reason seem to be missing something obvious.
from espn-fantasy-football-api.
Does anyone have a simple example of how to spin up the NodeJS server and call basic methods for a private league (I'm not asking for posted creds or cookies). I'm trying to utilize this in a Vue.js app on localhost to create a custom live FF stats viewer for my league and can't seem to even get passed the ability to set cookies and make a simple call for even getting league info.
Thanks for any help at all.
from espn-fantasy-football-api.
@jamigibbs Thank you Jami!
I'll take a look at this and try and incorporate it to my Vue app. One question, are you running this off localhost? I only ask because I get JS Errors from trying to set Cookies when running this on localhost via npm serve.
Thank you again!
from espn-fantasy-football-api.
I am new to NodeJs and trying to learn by creating a simple web app for my Fantasy League. I am also interested in just a basic example that shows how to run some of these methods. Like getBoxScore for example.
Thanks!
from espn-fantasy-football-api.
Added the Psychic script to the README in #241
from espn-fantasy-football-api.
Related Issues (20)
- Points don't reflect live game counts HOT 4
- Transactions HOT 4
- espn_s2 cookie no longer exists?
- Any way to determine league name?
- Scoreboard Data from older years HOT 3
- Client missing from documentation? HOT 2
- Add Projected Points and Score for Week for Free Agents
- Expanding to other fantasy sports HOT 2
- Beginner's Help HOT 1
- Has anyone been able to pull live projected points out of the response? HOT 2
- getTeamsAtWeek returning error with years before 2018 HOT 2
- ESPN-Fantasy-Football-API --> Magic Mirror Module
- Add Typescript Types
- Feat: Add addtional biographical information
- Feat: allow customizable filters when fetching players
- Get Matchup / Scoring Period Dynamically HOT 2
- Draft Order HOT 1
- Question: is the maintainer still active? HOT 4
- Team information has last season's names HOT 4
- How to fix: TypeError: Client is not a constructor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espn-fantasy-football-api.