Add logic for calculating projections & random offset

This commit is contained in:
Garrett Mills 2020-11-07 16:45:55 -06:00
parent ccf0792ac4
commit 77ad570834
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 6 additions and 3 deletions

View File

@ -37,7 +37,7 @@ class Lineup extends Model {
let points = 0 let points = 0
for ( const player of starting_players ) { for ( const player of starting_players ) {
points += (await player.points_for_week(this.week_num)).fantasy_points points += (await player.points_for_week(this.week_num))?.fantasy_points || 0
} }
return points return points

View File

@ -33,12 +33,15 @@ class Matchup extends Model {
const data = { const data = {
date: '2020-11-11', // TODO generate this in the matches patch date: '2020-11-11', // TODO generate this in the matches patch
team_1: home_team.team_name, team_1: home_team.team_name,
team_1_projection: 0, team_1_projection: await (await home_team.lineup())?.calculate_fantasy_points() + Math.round(Math.random() * (5 - (-5)) + (-5)),
team_2: visitor_team.team_name, team_2: visitor_team.team_name,
team_2_projection: 0, team_2_projection: await (await visitor_team.lineup())?.calculate_fantasy_points() + Math.round(Math.random() * (5 - (-5)) + (-5)),
} }
if ( data.team_1_projection < 0 ) data.team_1_projection = 0
if ( data.team_2_projection < 0 ) data.team_2_projection = 0
if ( this.complete ) { if ( this.complete ) {
const winner = this.home_team_score > this.visitor_team_score ? home_team : visitor_team const winner = this.home_team_score > this.visitor_team_score ? home_team : visitor_team