Add last 2 appearances for pitchers

This commit is contained in:
Peter 2023-08-16 09:03:05 -04:00
parent 2220ec88dd
commit fbaeebc7c7
4 changed files with 75 additions and 10 deletions

5
components.d.ts vendored
View File

@ -9,19 +9,14 @@ export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
FrontPage: typeof import('./src/components/FrontPage.vue')['default']
IconCommunity: typeof import('./src/components/icons/IconCommunity.vue')['default']
IconDocumentation: typeof import('./src/components/icons/IconDocumentation.vue')['default']
IconEcosystem: typeof import('./src/components/icons/IconEcosystem.vue')['default']
IconSupport: typeof import('./src/components/icons/IconSupport.vue')['default']
IconTooling: typeof import('./src/components/icons/IconTooling.vue')['default']
NavBar: typeof import('./src/components/NavBar.vue')['default']
NButton: typeof import('naive-ui')['NButton']
NMenu: typeof import('naive-ui')['NMenu']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
StandingsTable: typeof import('./src/components/StandingsTable.vue')['default']
TheWelcome: typeof import('./src/components/TheWelcome.vue')['default']
WelcomeItem: typeof import('./src/components/WelcomeItem.vue')['default']
}
}

View File

@ -29,10 +29,24 @@ export interface Manager {
}
export interface Division {
division_abbrev: 'W' | 'E'
division_name: 'West' | 'East'
division_abbrev: string
division_name: string
id: number
league_abbrev: 'NL' | 'AL'
league_name: 'National League' | 'American League'
league_abbrev: string
league_name: string
season: number
}
export interface Game {
id: number,
season: number,
week: number,
game_num: number,
season_type: string,
away_team: Team
home_team: Team
away_score: number,
home_score: number,
away_manager: Manager
home_manager: Manager
}

View File

@ -0,0 +1,35 @@
import type { Game } from './apiResponseTypes'
import type { Player } from './playersService'
import { SITE_URL } from './utilities'
export interface Decision {
id: number,
game: Game,
season: number,
week: number,
game_num: number,
pitcher: Player,
win: number,
loss: number,
hold: number,
is_save: number,
b_save: number,
irunners: number,
irunners_scored: number,
rest_ip: number,
rest_required: number,
is_start: false
}
export async function fetchLast2DecisionsByPlayerId(seasonNumber: number, playerId: number): Promise<Decision[]> {
const response = await fetch(`${SITE_URL}/api/v3/decisions?season=${seasonNumber}&player_id=${playerId}&limit=2`)
const decisionsResponse: {
count: number
decisions: Decision[]
} = await response.json()
return decisionsResponse.decisions
}

View File

@ -39,11 +39,15 @@
<thead class="thead-dark">
<tr>
<th>Inj</th>
<th v-if="lastAppearance">Last App</th>
<th v-if="secondLastAppearance">2nd Last App</th>
</tr>
</thead>
<tbody id="batter-summary-helper">
<tr>
<td>{{ injuryRating }}</td>
<td v-if="lastAppearance">{{ lastAppearance }}</td>
<td v-if="secondLastAppearance">{{ secondLastAppearance }}</td>
</tr>
</tbody>
</table>
@ -55,13 +59,15 @@
</template>
<script lang="ts">
import { fetchLast2DecisionsByPlayerId, type Decision } from '@/services/decisionsService'
import { type Player, fetchPlayerByName } from '@/services/playersService'
export default {
name: "TeamView",
data() {
return {
player: undefined as Player | undefined
player: undefined as Player | undefined,
last2Decisions: [] as Decision[]
}
},
props: {
@ -101,6 +107,17 @@ export default {
},
injuryRating(): string | undefined {
return this.player?.injury_rating
},
lastAppearance(): string | undefined {
if (!this.last2Decisions?.length) return undefined
if (this.last2Decisions.length <= 0) return undefined
return this.formatDecisionToAppearance(this.last2Decisions[0])
},
secondLastAppearance(): string | undefined {
if (!this.last2Decisions?.length) return undefined
if (this.last2Decisions.length <= 1) return '-'
return this.formatDecisionToAppearance(this.last2Decisions[1])
}
},
created() {
@ -117,6 +134,10 @@ export default {
methods: {
async fetchData(): Promise<void> {
this.player = await fetchPlayerByName(this.seasonNumber, this.playerName)
this.last2Decisions = await fetchLast2DecisionsByPlayerId(this.seasonNumber, this.player?.id)
},
formatDecisionToAppearance(decision: Decision): string {
return `${decision.rest_ip.toFixed(1)}IP w${decision.week}g${decision.game_num}`
}
}
}