Write patch to pull in weekly player data to database; start player/team stat models
This commit is contained in:
@@ -6,7 +6,17 @@ const axios = require('axios').default;
|
||||
*/
|
||||
class SportsDataService extends Service {
|
||||
static get services() {
|
||||
return [...super.services, 'configs']
|
||||
return [...super.services, 'configs', 'models', 'utility']
|
||||
}
|
||||
|
||||
async is_draft_stage() {
|
||||
const Setting = this.models.get('models::setting')
|
||||
return !!this.utility.infer(await Setting.get('in_draft_stage'))
|
||||
}
|
||||
|
||||
async current_play_week() {
|
||||
const Setting = this.models.get('models::setting')
|
||||
return !!this.utility.infer(await Setting.get('current_week'))
|
||||
}
|
||||
|
||||
async get_team_players(team_key) {
|
||||
@@ -17,14 +27,18 @@ class SportsDataService extends Service {
|
||||
return this.get_request('Teams')
|
||||
}
|
||||
|
||||
async get_request(path) {
|
||||
const response = await axios.get(this.url(path))
|
||||
async get_request(path, base = 'scores') {
|
||||
const response = await axios.get(this.url(path, base))
|
||||
return response.data
|
||||
}
|
||||
|
||||
url(path) {
|
||||
async get_week_player_stats(week_num) {
|
||||
return this.get_request(`PlayerGameProjectionStatsByWeek/${this.configs.get('server.sports_data.season')}/${week_num}`, 'projections')
|
||||
}
|
||||
|
||||
url(path, base = 'scores') {
|
||||
if ( path.startsWith('/') ) path = path.slice(1)
|
||||
return `https://api.sportsdata.io/v3/nfl/scores/json/${path}?key=${this.configs.get('server.sports_data.api_key')}`
|
||||
return `https://api.sportsdata.io/v3/nfl/${base}/json/${path}?key=${this.configs.get('server.sports_data.api_key')}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user