Clean up page and unused methods

This commit is contained in:
Peter 2024-10-31 07:28:14 -05:00
parent 130283b7f1
commit 334f5acdb3

View File

@ -3,7 +3,6 @@
<div class="row">
<div class="col-sm-12">
<h1 id="season-heading">Season {{ seasonNumber }} Team Stats</h1>
<h2 id="week-num">Week {{ weekNumber }}</h2>
<h2 id="stat-heading">{{ statType }} Stats</h2>
</div>
</div>
@ -29,8 +28,7 @@
import LeaderboardTeamBattingTable from '@/components/LeaderboardTeamBattingTable.vue'
import LeaderboardTeamFieldingTable from '@/components/LeaderboardTeamFieldingTable.vue'
import LeaderboardTeamPitchingTable from '@/components/LeaderboardTeamPitchingTable.vue'
import { type LeagueInfo, fetchCurrentLeagueInfo } from '@/services/currentService'
import { CURRENT_SEASON, GAMES_PER_WEEK, MODERN_STAT_ERA_START, WEEKS_PER_SEASON } from '@/services/utilities'
import { CURRENT_SEASON, MODERN_STAT_ERA_START } from '@/services/utilities'
export default {
name: 'TeamLeaderboardView',
@ -44,9 +42,6 @@ export default {
currentSeasonNumber: CURRENT_SEASON,
seasonNumber: CURRENT_SEASON,
statType: 'Batting' as 'Batting' | 'Pitching' | 'Fielding',
pitchingType: 'All' as 'All' | 'Starters' | 'Relievers',
weekNumber: undefined! as number
}
},
computed: {
@ -54,54 +49,6 @@ export default {
if (!this.currentSeasonNumber) return []
return Array.from({ length: this.currentSeasonNumber - MODERN_STAT_ERA_START + 1 }, (_, i) => i + MODERN_STAT_ERA_START)
},
weekNumberForCalcs(): number {
if (this.seasonNumber < this.currentSeasonNumber) return WEEKS_PER_SEASON
// since stats are for regular season, do not use post season weeks to up PA/IP mins
return Math.max(0, Math.min(this.weekNumber, WEEKS_PER_SEASON))
},
statMinimum(): string {
if (this.statType == 'Batting') return `PA: ${this.plateAppearanceMinimum}`
if (this.statType == 'Pitching') return `IP: ${this.inningsPitchedMinimum}`
return `${Math.floor(this.weekNumberForCalcs * 2)}/${Math.floor(this.weekNumberForCalcs)}/${Math.floor(this.weekNumberForCalcs * 0.5)}/${Math.floor(this.weekNumberForCalcs * 0.25)}`
},
plateAppearanceMinimum(): number {
const MIN_PLATE_APPEARANCES_PER_GAME = 3
return this.weekNumberForCalcs * GAMES_PER_WEEK * MIN_PLATE_APPEARANCES_PER_GAME
},
inningsPitchedMinimum(): number {
if (this.pitchingType === 'Relievers') return this.weekNumberForCalcs
const MIN_IP_PER_GAME = 1
return this.weekNumberForCalcs * GAMES_PER_WEEK * MIN_IP_PER_GAME
},
},
created() {
this.fetchData()
},
watch: {
seasonNumber(newValue, oldValue) {
if (newValue !== oldValue)
this.fetchData()
},
statType(newValue, oldValue) {
if (newValue !== oldValue)
this.fetchData()
}
},
methods: {
async fetchData(): Promise<void> {
const leagueInfo: LeagueInfo = await fetchCurrentLeagueInfo()
this.weekNumber = leagueInfo.week
}
}
}
</script>
<style>
/* align checkbox better */
input[type=checkbox] {
vertical-align: -2px;
margin: 0;
padding: 0;
}
</style>