diff --git a/src/components/TeamPitchingTable.vue b/src/components/TeamPitchingTable.vue
index 412a8d9..30bcc31 100644
--- a/src/components/TeamPitchingTable.vue
+++ b/src/components/TeamPitchingTable.vue
@@ -6,35 +6,35 @@
- | Player |
- W |
- L |
- W-L% |
- ERA |
- G |
- GS |
- SV |
- HD |
- BSV |
- IP |
- H |
- R |
- ER |
- HR |
- BB |
- SO |
- HBP |
- BK |
- WP |
- IR |
- IRS |
- IRS% |
- WHIP |
- H/9 |
- HR/9 |
- BB/9 |
- SO/9 |
- SO/BB |
+ Player |
+ W |
+ L |
+ W-L% |
+ ERA |
+ G |
+ GS |
+ SV |
+ HD |
+ BSV |
+ IP |
+ H |
+ R |
+ ER |
+ HR |
+ BB |
+ SO |
+ HBP |
+ BK |
+ WP |
+ IR |
+ IRS |
+ IRS% |
+ WHIP |
+ H/9 |
+ HR/9 |
+ BB/9 |
+ SO/9 |
+ SO/BB |
@@ -118,6 +118,14 @@
import { aggregatePitchingStats, fetchPitchingStatsBySeasonAndTeamId, type PitchingStat } from '@/services/pitchingStatsService'
import { outsToInnings, winPercentage, hitsPer9, hrsPer9 } from '@/services/utilities'
+interface ExtendedPitchingStat extends PitchingStat {
+ playerName: string
+ winPct: string
+ irsPct: string
+ hPer9: string
+ hrPer9: string
+}
+
export default {
name: 'TeamPitchingTable',
props: {
@@ -127,7 +135,9 @@ export default {
},
data() {
return {
- pitchingStats: [] as PitchingStat[]
+ pitchingStats: [] as ExtendedPitchingStat[],
+ sortKey: 'ip' as keyof ExtendedPitchingStat,
+ sortOrder: -1
}
},
computed: {
@@ -144,14 +154,47 @@ export default {
},
watch: {
teamId(newValue, oldValue) {
- if (newValue !== oldValue)
+ if (newValue !== oldValue) {
+ this.pitchingStats = []
+ this.sortKey = 'ip'
+ this.sortOrder = -1
this.fetchData()
+ }
}
},
methods: {
async fetchData(): Promise {
const unsortedPitchingStats: PitchingStat[] = await fetchPitchingStatsBySeasonAndTeamId(this.seasonNumber, this.teamId, this.isRegularSeason)
- this.pitchingStats = unsortedPitchingStats.sort((s1, s2) => s2.outs - s1.outs)
+ this.pitchingStats = unsortedPitchingStats
+ .map(s => (
+ {
+ ...s,
+ playerName: s.player.name,
+ winPct: this.winPercentage(s),
+ irsPct: this.formatIRSPercentage(s),
+ hPer9: this.hitsPer9(s),
+ hrPer9: this.hrsPer9(s)
+ }))
+ .sort((s1, s2) => s2.ip - s1.ip)
+ },
+ sortBy(stat: keyof ExtendedPitchingStat): void {
+ this.setKey(stat)
+
+ this.pitchingStats.sort((s1, s2) => s2[stat] < s1[stat] ? this.sortOrder : -1 * this.sortOrder)
+ },
+ setKey(stat: keyof ExtendedPitchingStat): void {
+ if (this.sortKey === stat) {
+ // if key currently selected, flip sort order
+ this.sortOrder *= -1
+ } else {
+ this.sortKey = stat
+ this.sortOrder = stat === 'playerName' ? 1 : -1
+ }
+ },
+ getArrow(stat: keyof ExtendedPitchingStat): string {
+ if (this.sortKey !== stat) return 'faux-arrow'
+
+ return this.sortOrder > 0 ? 'up' : 'down'
},
outsToInnings(stat: PitchingStat): string {
return outsToInnings(stat)
@@ -173,3 +216,18 @@ export default {
}
}
+
+