From 672ef8ece1b517ca162cd26f91208898961df329 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 19 Sep 2023 15:46:02 -0400 Subject: [PATCH] Add team pitching table --- components.d.ts | 1 + src/components/PlayerCareerPitchingTable.vue | 14 +- src/components/TeamPitchingTable.vue | 163 +++++++++++++++++++ src/services/gameService.ts | 2 +- src/services/pitchingStatsService.ts | 13 ++ src/services/utilities.ts | 18 ++ src/views/TeamView.vue | 10 +- 7 files changed, 209 insertions(+), 12 deletions(-) create mode 100644 src/components/TeamPitchingTable.vue diff --git a/components.d.ts b/components.d.ts index e466e0b..0ffc683 100644 --- a/components.d.ts +++ b/components.d.ts @@ -26,6 +26,7 @@ declare module '@vue/runtime-core' { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] StandingsTable: typeof import('./src/components/StandingsTable.vue')['default'] + TeamPitchingTable: typeof import('./src/components/TeamPitchingTable.vue')['default'] TeamScheduleTable: typeof import('./src/components/TeamScheduleTable.vue')['default'] } } diff --git a/src/components/PlayerCareerPitchingTable.vue b/src/components/PlayerCareerPitchingTable.vue index 2db7e7d..23c057e 100644 --- a/src/components/PlayerCareerPitchingTable.vue +++ b/src/components/PlayerCareerPitchingTable.vue @@ -108,7 +108,7 @@ diff --git a/src/services/gameService.ts b/src/services/gameService.ts index 6a710a2..a96151a 100644 --- a/src/services/gameService.ts +++ b/src/services/gameService.ts @@ -7,7 +7,7 @@ export async function fetchGamesBySeasonAndTeamId(seasonNumber: number, teamId: return [] } - const response = await fetch(`${SITE_URL}/api/v3/games?season=${seasonNumber}&team1_id=${teamId}&team2_id=${teamId}`) + const response = await fetch(`${SITE_URL}/api/v3/games?season=${seasonNumber}&team1_id=${teamId}&team2_id=${teamId}&season_type=regular`) const gamesResponse: { count: number diff --git a/src/services/pitchingStatsService.ts b/src/services/pitchingStatsService.ts index da7152a..f97f0bb 100644 --- a/src/services/pitchingStatsService.ts +++ b/src/services/pitchingStatsService.ts @@ -152,6 +152,19 @@ export async function fetchPitchingStatsBySeasonAndPlayerId(seasonNumber: number return normalizePitchingStat(pitchingStatsResponse.stats[0]) } +export async function fetchPitchingStatsBySeasonAndTeamId(seasonNumber: number, teamId: number, isRegularSeason: boolean): Promise { + const response = await fetch(`${SITE_URL}/api/v3/plays/pitching?season=${seasonNumber}&team_id=${teamId}&group_by=playerteam&s_type=${isRegularSeason ? 'regular' : 'post'}`) + + const pitchingStatsResponse: { + count: number + stats: PitchingStatRaw[] + } = await response.json() + + if (pitchingStatsResponse.count === 0) return [] + + return pitchingStatsResponse.stats.map(normalizePitchingStat) +} + async function fetchLegacyPitchingStatsBySeasonAndPlayerId(seasonNumber: number, playerId: number, isRegularSeason: boolean): Promise { const response = await fetch(`${SITE_URL}/api/v3/pitchingstats/totals?season=${seasonNumber}&player_id=${playerId}&s_type=${isRegularSeason ? 'regular' : 'post'}`) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 9d55054..b0bf9e3 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -44,3 +44,21 @@ export function woba(stat: { bb: number, hbp: number, hit: number, double: numbe export function outsToInnings(stat: { outs: number }): string { return (stat.outs / 3).toFixed(1) } + +export function winPercentage(stat: { win: number, loss: number }): string { + if (stat.win + stat.loss === 0) return '-' + + return (stat.win / (stat.win + stat.loss)).toFixed(3) +} + +export function hitsPer9(stat: { outs: number, hits: number }): string { + if (stat.outs === 0) return '-' + + return (stat.hits * 27 / stat.outs).toFixed(1) +} + +export function hrsPer9(stat: { outs: number, hr: number }): string { + if (stat.outs === 0) return '-' + + return (stat.hr * 27 / stat.outs).toFixed(1) +} diff --git a/src/views/TeamView.vue b/src/views/TeamView.vue index ef0011f..1607073 100644 --- a/src/views/TeamView.vue +++ b/src/views/TeamView.vue @@ -157,6 +157,12 @@ + + + + @@ -168,11 +174,13 @@ import { fetchStandings, type TeamStanding } from '@/services/standingsService' import { fetchTeam } from '@/services/teamsService' import { fetchTransactionsByTeamAndWeek, type Transaction } from '@/services/transactionsService' import TeamScheduleTable from '@/components/TeamScheduleTable.vue' +import TeamPitchingTable from '@/components/TeamPitchingTable.vue' export default { name: "TeamView", components: { - TeamScheduleTable + TeamScheduleTable, + TeamPitchingTable }, data() { return {