From 8db37bfca070dc0c69959c0f31c6f2edd89af3e2 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 14 Nov 2024 17:16:33 -0600 Subject: [PATCH 1/6] Initial team fielding table sorting --- src/components/TeamFieldingTable.vue | 69 ++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/src/components/TeamFieldingTable.vue b/src/components/TeamFieldingTable.vue index b54d663..8768007 100644 --- a/src/components/TeamFieldingTable.vue +++ b/src/components/TeamFieldingTable.vue @@ -5,22 +5,23 @@ - - - - - - - - - - + + + + + + + + + + @@ -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: { @@ -97,7 +104,9 @@ export default { 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 +117,41 @@ export default { }, formatWeightedFieldingPercent(stat: FieldingStat): string { return stat.weightedFieldingPercent.toFixed(3) + }, + sortBy(stat: keyof ExtendedFieldingStat): void { + this.setKey(stat) + + 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' } } } + + From b3c8bc291301da7bf27847d5928216aeaf707331 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 14 Nov 2024 17:18:44 -0600 Subject: [PATCH 2/6] Special sort case for position name (number) --- src/components/TeamFieldingTable.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/TeamFieldingTable.vue b/src/components/TeamFieldingTable.vue index 8768007..8a66230 100644 --- a/src/components/TeamFieldingTable.vue +++ b/src/components/TeamFieldingTable.vue @@ -121,6 +121,11 @@ export default { 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 { From 1533fbd0ae8b8781bf787b62c7784f32a714a8f5 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 15 Nov 2024 11:30:09 -0600 Subject: [PATCH 3/6] Clean up comment --- src/components/TeamPitchingTable.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/TeamPitchingTable.vue b/src/components/TeamPitchingTable.vue index a7fdb5c..412a8d9 100644 --- a/src/components/TeamPitchingTable.vue +++ b/src/components/TeamPitchingTable.vue @@ -35,8 +35,6 @@ - From 113146573365355c050b7ffd06896781d3eb04b1 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 15 Nov 2024 16:26:09 -0600 Subject: [PATCH 4/6] Reset data on watcher for fielding table --- src/components/TeamFieldingTable.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/TeamFieldingTable.vue b/src/components/TeamFieldingTable.vue index 8a66230..94579e7 100644 --- a/src/components/TeamFieldingTable.vue +++ b/src/components/TeamFieldingTable.vue @@ -97,8 +97,12 @@ export default { }, watch: { teamId(newValue, oldValue) { - if (newValue !== oldValue) + if (newValue !== oldValue) { + this.fieldingStats = [] + this.sortKey = 'xCheckCount' + this.sortOrder = -1 this.fetchData() + } } }, methods: { From 6eef04e8c259de1478a309a0d69a2c5727c49c72 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 15 Nov 2024 16:35:23 -0600 Subject: [PATCH 5/6] Add sorting to TeamBattingTable and fix duplicate key issue --- src/components/TeamBattingTable.vue | 111 ++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 32 deletions(-) diff --git a/src/components/TeamBattingTable.vue b/src/components/TeamBattingTable.vue index 2e6331c..85406fc 100644 --- a/src/components/TeamBattingTable.vue +++ b/src/components/TeamBattingTable.vue @@ -3,40 +3,40 @@

Team Batting {{ isRegularSeason ? '' : ' - Postseason' }}

-
SeasonPosXChXHEPBSBaCScCS%wF%PlayerPosXChXHEPBSBaCScCS%wF%
- + {{ stat.player.name }} BB/9 SO/9 SO/BB
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - +
PlayerPAABRH2B3BHRRBISBCSBBSOBAOBPSLGOPSwOBAK%BPHRBPFOBP1BBPLOGIDPHBPSACIBBPlayerPAABRH2B3BHRRBISBCSBBSOBAOBPSLGOPSwOBAK%BPHRBPFOBP1BBPLOGIDPHBPSACIBB
@@ -111,6 +111,11 @@ + + From 971ae3f12e9036c0836de82705aff0ee4ec08829 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 15 Nov 2024 16:43:02 -0600 Subject: [PATCH 6/6] Add sorting to pitching table --- src/components/TeamPitchingTable.vue | 122 ++++++++++++++++++++------- 1 file changed, 90 insertions(+), 32 deletions(-) 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -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 { } } + +
PlayerWLW-L%ERAGGSSVHDBSVIPHRERHRBBSOHBPBKWPIRIRSIRS%WHIPH/9HR/9BB/9SO/9SO/BBPlayerWLW-L%ERAGGSSVHDBSVIPHRERHRBBSOHBPBKWPIRIRSIRS%WHIPH/9HR/9BB/9SO/9SO/BB