Last active
December 25, 2018 20:35
-
-
Save rovolution/a9324ace426ffd820609c3cbbfdc7d0c to your computer and use it in GitHub Desktop.
Fantasy Football: Take the output from ff-highest-score.js and determine the payout amounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script is used to determine the payout amounts for my fantasy football league. | |
The script assumes the following payout rules: | |
- Buy-in: $125 | |
- Highest points per week - $15 for 16 weeks | |
- Highest points for entire season - $100 | |
- 3rd: $125 | |
- 2nd: $335 | |
- 1st: $700 | |
Instructions: | |
- Log-in and navigate to your league's homepage. Make sure you are on the Championship round tab where the top place finishers are listed in order (Standings -> Playoffs -> Championship) | |
- Right-click and open Developer Tools | |
- Copy/paste the script contents into the Console and press enter to load the script into the page | |
- Execute the script within the Console by invoking the function: | |
getPaymentsForSeason({ highestWeeklyScoresData, usernameToTotalScoreMap }); | |
- highestWeeklyScoresData | |
- an array of arrays (each weeks data is in an array) | |
- Each week array contains the following structure: [week, name, score] | |
- Ex: [[1, "Bob's Team", 10], [2, "Moon Slayers", 1]] | |
- usernameToTotalScoreMap | |
- a map of the following structure: username (String) to total score (Float) | |
- Ex: {"Bob's Team": 100, "Moon Slayers": 200 }; | |
- The script will print to the Console a table with two columns: username (String), payout (Float) | |
*/ | |
function getPaymentsForSeason({ highestWeeklyScoresData, usernameToTotalScoreMap }) { | |
let userToPayoutMap = {}; | |
const WEEKLY_WINNER_MONEY = 15; | |
const TOP_SEASON_SCORER_MONEY = 100; | |
const FIRST_PLACE_MONEY = 700; | |
const SECOND_PLACE_MONEY = 335; | |
const THIRD_PLACE_MONEY = 125; | |
// Highest points per week | |
highestWeeklyScoresData.forEach((week) => { | |
const [,weekWinner,] = week; | |
_addMoneyToUser(weekWinner, WEEKLY_WINNER_MONEY); | |
}); | |
// Highest points for entire season | |
const topScorerSeason = Object.keys(usernameToTotalScoreMap).reduce((topScorer, user) => { | |
const totalScore = usernameToTotalScoreMap[user]; | |
const newTopScorer = (totalScore > topScorer.score) ? {score: totalScore, name: user} : topScorer; | |
return newTopScorer; | |
}, {score: -1, name: null}); | |
_addMoneyToUser(topScorerSeason.name, TOP_SEASON_SCORER_MONEY); | |
// Top 3 | |
document.querySelectorAll("#winners_table > tbody td.Bdr.Linkable a:nth-of-type(2)").forEach((elem, index) => { | |
const name = elem.innerText; | |
if (index === 0) { | |
_addMoneyToUser(name, FIRST_PLACE_MONEY); | |
} | |
else if (index === 1) { | |
_addMoneyToUser(name, SECOND_PLACE_MONEY); | |
} | |
else if (index === 2) { | |
_addMoneyToUser(name, THIRD_PLACE_MONEY); | |
} | |
}); | |
console.log("======================") | |
console.log("Payouts for the Season") | |
console.table(userToPayoutMap); | |
console.log("======================") | |
/* Helpers */ | |
function _addMoneyToUser(name, money) { | |
if (userToPayoutMap[name]) { | |
userToPayoutMap[name] += money; | |
} | |
else { | |
userToPayoutMap[name] = money; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment