parent
9d3d614c20
commit
5cc3d31415
@ -0,0 +1,67 @@
|
|||||||
|
const { Injectable } = require('flitter-di')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A data patch which fetches all of the player stats for a range of
|
||||||
|
* weeks and creates WeeklyPlayerStat records for all players for all
|
||||||
|
* weeks.
|
||||||
|
*
|
||||||
|
* This builds the base of data we need to calculate the weekly team
|
||||||
|
* standings.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* P = require('./app/SeedWeeklyPlayerData.patch')
|
||||||
|
* p = _di.make(P)
|
||||||
|
* await p.run()
|
||||||
|
*
|
||||||
|
* @extends Injectable
|
||||||
|
*/
|
||||||
|
class SeedWeeklyPlayerDataPatch extends Injectable {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models', 'sports_data', 'output']
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the patch.
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
|
async run() {
|
||||||
|
const Player = this.models.get('Player')
|
||||||
|
const WeeklyPlayerStat = this.models.get('WeeklyPlayerStat')
|
||||||
|
const start_week = 1
|
||||||
|
const end_week = 17
|
||||||
|
|
||||||
|
// Clear existing data
|
||||||
|
await WeeklyPlayerStat.deleteMany()
|
||||||
|
|
||||||
|
// Populate the weekly player stats for all weeks in the range
|
||||||
|
for ( let week = start_week; week <= end_week; week += 1 ) {
|
||||||
|
this.output.info(`Building weekly player stats for week ${week}...`)
|
||||||
|
const player_stats = await this.sports_data.get_week_player_stats(week)
|
||||||
|
|
||||||
|
this.output.info(` - processing ${player_stats.length} stats`)
|
||||||
|
for ( const stat of player_stats ) {
|
||||||
|
const player = await Player.findOne({
|
||||||
|
'patch_data.player_id': stat.PlayerID,
|
||||||
|
})
|
||||||
|
|
||||||
|
if ( player ) {
|
||||||
|
const weekly_stat = new WeeklyPlayerStat({
|
||||||
|
player_id: player.id,
|
||||||
|
patch_player_id: stat.PlayerID,
|
||||||
|
week_num: week,
|
||||||
|
fantasy_points: stat.FantasyPoints,
|
||||||
|
})
|
||||||
|
|
||||||
|
await weekly_stat.save()
|
||||||
|
} else {
|
||||||
|
this.output.warn(` - Player ID ${stat.PlayerID} does not exist.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.output.success(` - complete`)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.output.success('Complete!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = SeedWeeklyPlayerDataPatch
|
@ -0,0 +1,18 @@
|
|||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
|
||||||
|
class Matchup extends Model {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models']
|
||||||
|
}
|
||||||
|
|
||||||
|
static get schema() {
|
||||||
|
return {
|
||||||
|
home_team_id: String,
|
||||||
|
visitor_team_id: String,
|
||||||
|
week_num: Number,
|
||||||
|
complete: { type: Boolean, default: false },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = Matchup
|
@ -0,0 +1,18 @@
|
|||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
|
||||||
|
class WeeklyPlayerStat extends Model {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models']
|
||||||
|
}
|
||||||
|
|
||||||
|
static get schema() {
|
||||||
|
return {
|
||||||
|
player_id: String,
|
||||||
|
week_num: Number,
|
||||||
|
patch_player_id: String,
|
||||||
|
fantasy_points: Number,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = WeeklyPlayerStat
|
@ -0,0 +1,19 @@
|
|||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
|
||||||
|
class WeeklyTeamStat extends Model {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models']
|
||||||
|
}
|
||||||
|
|
||||||
|
static get schema() {
|
||||||
|
return {
|
||||||
|
team_id: String,
|
||||||
|
lineup_id: String,
|
||||||
|
week_num: Number,
|
||||||
|
player_ids: [String],
|
||||||
|
fantasy_points: Number,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = WeeklyTeamStat
|
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
const settings_config = {
|
||||||
|
default_settings: [
|
||||||
|
{
|
||||||
|
key: 'in_draft_stage',
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'current_week',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = settings_config
|
Loading…
Reference in new issue