From 3b8691046577ce87ca9b3bd3bf666bd188810a55 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 1 Nov 2024 13:48:30 -0500 Subject: [PATCH] Add IRS% to Team Stats and individual leaderboards. Also updated tie breakers for individual leaderboards based on PAs/IP/XCh respectively --- .../LeaderboardTeamPitchingTable.vue | 8 ++++ src/components/PlayerPitchingSummaryTable.vue | 2 +- src/views/LeaderboardView.vue | 41 +++++++++++++++---- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/components/LeaderboardTeamPitchingTable.vue b/src/components/LeaderboardTeamPitchingTable.vue index 64ac54d..2da9034 100644 --- a/src/components/LeaderboardTeamPitchingTable.vue +++ b/src/components/LeaderboardTeamPitchingTable.vue @@ -27,6 +27,7 @@ WP IR IRS + IRS% WHIP H/9 HR/9 @@ -66,6 +67,7 @@ {{ stat.wp }} {{ stat.ir }} {{ stat.ir_sc }} + {{ formatIRSPercentage(stat) }} {{ stat.whip.toFixed(2) }} {{ hitsPer9(stat) }} {{ hrsPer9(stat) }} @@ -98,6 +100,7 @@ {{ totalPitchingStat.wp }} {{ totalPitchingStat.ir }} {{ totalPitchingStat.ir_sc }} + {{ formatIRSPercentage(totalPitchingStat) }} {{ totalPitchingStat.whip.toFixed(2) }} {{ hitsPer9(totalPitchingStat) }} {{ hrsPer9(totalPitchingStat) }} @@ -162,6 +165,11 @@ export default { }, hrsPer9(stat: PitchingStat): string { return hrsPer9(stat) + }, + formatIRSPercentage(stat: PitchingStat): string { + if (stat.ir === 0) return '-' + + return `${(stat.ir_sc_pct * 100).toFixed(1)}%` } } } diff --git a/src/components/PlayerPitchingSummaryTable.vue b/src/components/PlayerPitchingSummaryTable.vue index 75bd555..8b71169 100644 --- a/src/components/PlayerPitchingSummaryTable.vue +++ b/src/components/PlayerPitchingSummaryTable.vue @@ -67,7 +67,7 @@ import { outsToInnings } from '@/services/utilities' import type { PropType } from 'vue' export default { - name: "PlayerPitchingSummaryTable", + name: 'PlayerPitchingSummaryTable', props: { currentSeasonPitching: { type: Object as PropType, required: false }, currentPostSeasonPitching: { type: Object as PropType, required: false }, diff --git a/src/views/LeaderboardView.vue b/src/views/LeaderboardView.vue index c324d41..19f57b9 100644 --- a/src/views/LeaderboardView.vue +++ b/src/views/LeaderboardView.vue @@ -226,7 +226,8 @@ export default { { title: 'Wild Pitches', columnName: 'WP', statPropertyName: 'wp' }, { title: 'Inherited Runners', columnName: 'IR', statPropertyName: 'ir' }, - { title: 'Inherited Runners Scored', columnName: 'IRS', statPropertyName: 'ir_sc' } + { title: 'Inherited Runners Scored', columnName: 'IRS', statPropertyName: 'ir_sc' }, + { title: 'Inherited Runners Scored %', columnName: 'IRS%', statPropertyName: 'ir_sc_pct' } ] }, fieldingLeaderboardTableData(): LeaderboardTableData[] { @@ -284,11 +285,16 @@ export default { const statBase: BattingStat[] = paExemptStat.includes(stat) ? this.allPlayersBattingStats.concat([]) : this.qualifyingBattingStats.concat([]) const sortMultiplier = this.invertSort ? -1 : 1 - return statBase.sort((a, b) => sortMultiplier * ((b[stat] as number) - (a[stat] as number))).slice(0, 10) + return statBase + .sort((a, b) => + sortMultiplier * ((b[stat] as number) - (a[stat] as number)) !== 0 + ? sortMultiplier * ((b[stat] as number) - (a[stat] as number)) + : b.pa - a.pa) + .slice(0, 10) }, getTop10PitchingStatByCategory(stat: keyof PitchingStat): PitchingStat[] { // qualifying IP exempt stats - const ipExemptStats: (keyof PitchingStat)[] = ['win', 'loss', 'save', 'bsave', 'hold', 'so', 'bb', 'hbp', 'hits', 'hr', 'run', 'e_run', 'balk', 'wp', 'ir', 'ir_sc'] + const ipExemptStats: (keyof PitchingStat)[] = ['win', 'loss', 'save', 'bsave', 'hold', 'so', 'bb', 'hbp', 'hits', 'hr', 'run', 'e_run', 'balk', 'wp', 'ir', 'ir_sc', 'ir_sc_pct'] // concat an empty array so that the existing array is not sorted as a side effect const statBase: PitchingStat[] = ipExemptStats.includes(stat) ? this.allPlayersPitchingStats.concat([]) : this.qualifyingPitchingStats.concat([]) @@ -301,10 +307,26 @@ export default { : s.gs === 0 ) - const reverseSortStats = ['era', 'whip', 'bbPer9'] + const reverseSortStats = ['era', 'whip', 'bbPer9', 'ir_sc_pct'] const sortMultiplier = (reverseSortStats.includes(stat) ? -1 : 1) * (this.invertSort ? -1 : 1) - return filteredStatBase.sort((a, b) => sortMultiplier * ((b[stat] as number) - (a[stat] as number))).slice(0, 10) + // janky workaround for irs% without weird entries + if (stat === 'ir_sc_pct') { + return filteredStatBase + .filter(s => s.ir > 0) + .sort((a, b) => + sortMultiplier * ((b[stat] as number) - (a[stat] as number)) !== 0 + ? sortMultiplier * ((b[stat] as number) - (a[stat] as number)) + : b.ip - a.ip) + .slice(0, 10) + } + + return filteredStatBase + .sort((a, b) => + sortMultiplier * ((b[stat] as number) - (a[stat] as number)) !== 0 + ? sortMultiplier * ((b[stat] as number) - (a[stat] as number)) + : b.ip - a.ip) + .slice(0, 10) }, getTop10FieldingStatByCategory(stat: keyof FlatFieldingStat): FlatFieldingStat[] { // High: 2B/SS - 2 XCh/wk @@ -328,9 +350,14 @@ export default { const xCheckCountProperty = `xCheckCount${position[1]}` as keyof FlatFieldingStat const sortMultiplier = this.invertSort ? -1 : 1 - return this.allPlayersFieldingStats.concat([]) + return this.allPlayersFieldingStats + .concat([]) .filter(stat => (stat[xCheckCountProperty] as number) >= Math.floor(xCheckCountPerWeek * this.weekNumberForCalcs)) - .sort((a, b) => sortMultiplier * ((b[stat] as number) - (a[stat] as number))).slice(0, 10) + .sort((a, b) => + sortMultiplier * ((b[stat] as number) - (a[stat] as number)) !== 0 + ? sortMultiplier * ((b[stat] as number) - (a[stat] as number)) + : b.xCheckCount - a.xCheckCount) + .slice(0, 10) } // non-wF% stats currently won't have any qualifying minimum