@@ -111,6 +111,11 @@
+
+
diff --git a/src/components/TeamFieldingTable.vue b/src/components/TeamFieldingTable.vue
index b54d663..94579e7 100644
--- a/src/components/TeamFieldingTable.vue
+++ b/src/components/TeamFieldingTable.vue
@@ -5,22 +5,23 @@
- | Season |
- Pos |
- XCh |
- XH |
- E |
- PB |
- SBa |
- CSc |
- CS% |
- wF% |
+ Player |
+ Pos |
+ XCh |
+ XH |
+ E |
+ PB |
+ SBa |
+ CSc |
+ CS% |
+ wF% |
|
-
+
{{ stat.player.name }}
|
@@ -57,6 +58,10 @@
import { aggregateFieldingStats, fetchFieldingStatsBySeasonAndTeamId, totaledFieldingStats, type FieldingStat } from '@/services/fieldingStatsService'
import { POS_MAP } from '@/services/utilities'
+interface ExtendedFieldingStat extends FieldingStat {
+ playerName: string
+}
+
export default {
name: 'TeamFieldingTable',
props: {
@@ -66,7 +71,9 @@ export default {
},
data() {
return {
- fieldingStats: [] as FieldingStat[]
+ fieldingStats: [] as ExtendedFieldingStat[],
+ sortKey: 'xCheckCount' as keyof ExtendedFieldingStat,
+ sortOrder: -1
}
},
computed: {
@@ -90,14 +97,20 @@ export default {
},
watch: {
teamId(newValue, oldValue) {
- if (newValue !== oldValue)
+ if (newValue !== oldValue) {
+ this.fieldingStats = []
+ this.sortKey = 'xCheckCount'
+ this.sortOrder = -1
this.fetchData()
+ }
}
},
methods: {
async fetchData(): Promise {
const unsortedFieldingStats: FieldingStat[] = await fetchFieldingStatsBySeasonAndTeamId(this.seasonNumber, this.teamId, this.isRegularSeason)
- this.fieldingStats = unsortedFieldingStats.sort((s1, s2) => s2.xCheckCount - s1.xCheckCount)
+ this.fieldingStats = unsortedFieldingStats
+ .map(s => ({ ...s, playerName: s.player.name }))
+ .sort((s1, s2) => s2.xCheckCount - s1.xCheckCount)
},
formatCaughtStealingPercent(stat: FieldingStat): string {
if (stat.stolenBaseCheckCount === 0 || Number.isNaN(stat.caughtStealingPercent)) {
@@ -108,7 +121,46 @@ export default {
},
formatWeightedFieldingPercent(stat: FieldingStat): string {
return stat.weightedFieldingPercent.toFixed(3)
+ },
+ sortBy(stat: keyof ExtendedFieldingStat): void {
+ this.setKey(stat)
+
+ if (stat === 'pos') {
+ this.fieldingStats.sort((s1, s2) => this.sortOrder * (POS_MAP[s1.pos] - POS_MAP[s2.pos]))
+ return
+ }
+
+ this.fieldingStats.sort((s1, s2) => s2[stat] < s1[stat] ? this.sortOrder : -1 * this.sortOrder)
+ },
+ setKey(stat: keyof ExtendedFieldingStat): 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 ExtendedFieldingStat): string {
+ if (this.sortKey !== stat) return 'faux-arrow'
+
+ return this.sortOrder > 0 ? 'up' : 'down'
}
}
}
+
+
diff --git a/src/components/TeamPitchingTable.vue b/src/components/TeamPitchingTable.vue
index a7fdb5c..30bcc31 100644
--- a/src/components/TeamPitchingTable.vue
+++ b/src/components/TeamPitchingTable.vue
@@ -6,37 +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 |
@@ -120,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: {
@@ -129,7 +135,9 @@ export default {
},
data() {
return {
- pitchingStats: [] as PitchingStat[]
+ pitchingStats: [] as ExtendedPitchingStat[],
+ sortKey: 'ip' as keyof ExtendedPitchingStat,
+ sortOrder: -1
}
},
computed: {
@@ -146,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)
@@ -175,3 +216,18 @@ export default {
}
}
+
+
|