Populate player stats when weekly player data patch is run
This commit is contained in:
parent
27f8f5e4dc
commit
d85570600a
@ -60,6 +60,10 @@ class SeedWeeklyPlayerDataPatch extends Injectable {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await weekly_stat.save()
|
await weekly_stat.save()
|
||||||
|
|
||||||
|
if ( week === 1 || !player.seed_stats || Object.values(player.seed_stats).length < 1 ) {
|
||||||
|
player.seed_stats = await weekly_stat.to_api()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.output.warn(` - Player ID ${stat.PlayerID} does not exist.`)
|
this.output.warn(` - Player ID ${stat.PlayerID} does not exist.`)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class Teams extends Controller {
|
|||||||
*/
|
*/
|
||||||
async get_my_team_players(req, res, next) {
|
async get_my_team_players(req, res, next) {
|
||||||
const players = await req.user_team.players()
|
const players = await req.user_team.players()
|
||||||
return res.api(await Promise.all(players.map(x => x.to_api())))
|
return res.api(await Promise.all(players.map(x => x.to_api(true))))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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)
|
points += (await player.points_for_week(this.week_num)).fantasy_points
|
||||||
}
|
}
|
||||||
|
|
||||||
return points
|
return points
|
||||||
@ -188,7 +188,7 @@ class Lineup extends Model {
|
|||||||
// Find the player instance and cast it to an API object
|
// Find the player instance and cast it to an API object
|
||||||
const player_inst = starting_players.find(x => x.id === player.player_id)
|
const player_inst = starting_players.find(x => x.id === player.player_id)
|
||||||
build_starting_players.push({
|
build_starting_players.push({
|
||||||
...(await player_inst.to_api()),
|
...(await player_inst.to_api(true)),
|
||||||
position: player.position
|
position: player.position
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ class Lineup extends Model {
|
|||||||
const build_benched_players = []
|
const build_benched_players = []
|
||||||
for ( const player of bench_players ) {
|
for ( const player of bench_players ) {
|
||||||
// Cast the starting player to an API object
|
// Cast the starting player to an API object
|
||||||
const obj = await player.to_api()
|
const obj = await player.to_api(true)
|
||||||
obj.position = 'B'
|
obj.position = 'B'
|
||||||
build_benched_players.push(obj)
|
build_benched_players.push(obj)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ const { Model } = require('flitter-orm')
|
|||||||
*/
|
*/
|
||||||
class Player extends Model {
|
class Player extends Model {
|
||||||
static get services() {
|
static get services() {
|
||||||
return [...super.services, 'output', 'models']
|
return [...super.services, 'output', 'models', 'sports_data']
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -35,6 +35,8 @@ class Player extends Model {
|
|||||||
experience_string: String,
|
experience_string: String,
|
||||||
age: Number,
|
age: Number,
|
||||||
photo_url: String,
|
photo_url: String,
|
||||||
|
|
||||||
|
seed_stats: Object,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +98,9 @@ class Player extends Model {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
async to_api() {
|
async to_api(with_stats = false) {
|
||||||
|
const stat = with_stats ? await this.points_for_week() : undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
number: this.player_number,
|
number: this.player_number,
|
||||||
@ -104,7 +108,7 @@ class Player extends Model {
|
|||||||
position: this.fantasy_position,
|
position: this.fantasy_position,
|
||||||
team_name: this.patch_data.patch_team_name,
|
team_name: this.patch_data.patch_team_name,
|
||||||
image: this.photo_url,
|
image: this.photo_url,
|
||||||
stats: {}, // TODO - populate some stats!
|
stats: (await stat?.to_api()) || this.seed_stats || {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,17 @@ class WeeklyPlayerStat extends Model {
|
|||||||
sacks: Number,
|
sacks: Number,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async to_api() {
|
||||||
|
return {
|
||||||
|
'Passing Attempts': this.passing_attempts,
|
||||||
|
'Passing Completions': this.passing_completions,
|
||||||
|
'Passing Yards': this.passing_yards,
|
||||||
|
'Fumbles': this.fumbles,
|
||||||
|
'Kick Returns': this.kick_returns,
|
||||||
|
'Sacks': this.sacks,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = exports = WeeklyPlayerStat
|
module.exports = exports = WeeklyPlayerStat
|
||||||
|
Loading…
Reference in New Issue
Block a user