Write patch for generating weekly matchup results

This commit is contained in:
2020-11-07 13:22:15 -06:00
parent feadc6201d
commit eee8d9a6a3
4 changed files with 62 additions and 0 deletions

View File

@@ -32,6 +32,17 @@ class Lineup extends Model {
}
}
async calculate_fantasy_points() {
const starting_players = await this.players_in_starting()
let points = 0
for ( const player of starting_players ) {
points += await player.points_for_week(this.week_num)
}
return points
}
/**
* Given a team, fetch the latest draft lineup for that team.
* This will also update the lineup record so that it includes all players

View File

@@ -15,6 +15,16 @@ class Matchup extends Model {
visitor_team_score: Number,
}
}
async home_team() {
const Team = this.models.get('Team')
return Team.findById(this.home_team_id)
}
async visitor_team() {
const Team = this.models.get('Team')
return Team.findById(this.visitor_team_id)
}
}
module.exports = exports = Matchup

View File

@@ -81,6 +81,11 @@ class Player extends Model {
})
}
async points_for_week(week_num) {
const WeeklyPlayerStat = this.models.get('WeeklyPlayerStat')
return WeeklyPlayerStat.findOne({ week_num, player_id: this.id })
}
async is_obligated() {
const Team = this.models.get('Team')
const teams = await Team.find()