Normalize pitching stats for fetchPitchingStatsBySeries and add fetchPitchingStatsForLastTwoWeeksByTeam
This commit is contained in:
parent
59d53e2964
commit
4532dd671e
@ -241,6 +241,22 @@ export async function fetchPitchingStatsForLastFourGamesBySeasonAndPlayerId(seas
|
|||||||
return pitchingStatsResponse.stats.map(normalizePitchingStat)
|
return pitchingStatsResponse.stats.map(normalizePitchingStat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchPitchingStatsForLastTwoWeeksByTeam(seasonNumber: number, weekNumber: number, teamId: number): Promise<PitchingStat[]> {
|
||||||
|
// no support for pre-modern games yet
|
||||||
|
if (seasonNumber < MODERN_STAT_ERA_START) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${SITE_URL}/api/v3/plays/pitching?season=${seasonNumber}&week_start=${weekNumber - 1}&week_end=${weekNumber}&team_id=${teamId}&group_by=playergame`)
|
||||||
|
|
||||||
|
const pitchingStatsResponse: {
|
||||||
|
count: number
|
||||||
|
stats: PitchingStatRaw[]
|
||||||
|
} = await response.json()
|
||||||
|
|
||||||
|
return pitchingStatsResponse.stats.map(normalizePitchingStat)
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchPitchingStatsBySeries(seasonNumber: number, weekNumber: number, homeTeamId: number, awayTeamId: number): Promise<PitchingStat[]> {
|
export async function fetchPitchingStatsBySeries(seasonNumber: number, weekNumber: number, homeTeamId: number, awayTeamId: number): Promise<PitchingStat[]> {
|
||||||
// no support for pre-modern games yet
|
// no support for pre-modern games yet
|
||||||
if (seasonNumber < MODERN_STAT_ERA_START) {
|
if (seasonNumber < MODERN_STAT_ERA_START) {
|
||||||
@ -251,10 +267,10 @@ export async function fetchPitchingStatsBySeries(seasonNumber: number, weekNumbe
|
|||||||
|
|
||||||
const pitchingStatsResponse: {
|
const pitchingStatsResponse: {
|
||||||
count: number
|
count: number
|
||||||
stats: PitchingStat[]
|
stats: PitchingStatRaw[]
|
||||||
} = await response.json()
|
} = await response.json()
|
||||||
|
|
||||||
return pitchingStatsResponse.stats
|
return pitchingStatsResponse.stats.map(normalizePitchingStat)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function aggregatePitchingStats(pitchingStats: PitchingStat[]): PitchingStat {
|
export function aggregatePitchingStats(pitchingStats: PitchingStat[]): PitchingStat {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user