From f78eabd222250d115bea14badd73f7a09bdda2e6 Mon Sep 17 00:00:00 2001 From: Justin Kleiber Date: Wed, 29 May 2024 20:48:52 -0400 Subject: [PATCH] Fixes sauce rankings (#46) Also generalizes filter chips more --- src/components/EventDataRow.vue | 2 +- src/views/EventRankingsView.vue | 127 ++++++++++++++++++++++---------- 2 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/components/EventDataRow.vue b/src/components/EventDataRow.vue index 97deadb..dbd886d 100644 --- a/src/components/EventDataRow.vue +++ b/src/components/EventDataRow.vue @@ -53,7 +53,7 @@ export default { }, methods: { valueDisplay(stat) { - if (stat && stat.value) { + if (stat && stat.value != null) { return stat.value.toFixed(4); } return "N/A"; diff --git a/src/views/EventRankingsView.vue b/src/views/EventRankingsView.vue index 15f95d9..34355eb 100644 --- a/src/views/EventRankingsView.vue +++ b/src/views/EventRankingsView.vue @@ -37,24 +37,26 @@ import '@material/web/chips/filter-chip';

Statistics

- + + - - - +

Award Types

- - + +
@@ -106,6 +108,20 @@ export default { lowerYearIndex: 0, upperYearIndex: 0, sortedColumnIdx: 2, + enabledMap: { + 'stats': { + 'info': true, + 'bbq': true, + 'sauce': true, + 'briquette': true, + 'ribs': true, + }, + 'types': { + 'info': true, + 'robot': true, + 'team': true + } + }, visibilityMap: { 'stats': { 'info': true, @@ -197,14 +213,14 @@ export default { } else { for (let i = 0; i < data.length; i++) { - let dataValid = (data[i].robot_bbq - && data[i].team_bbq - && data[i].robot_sauce - && data[i].team_sauce - && data[i].robot_briquette - && data[i].team_briquette - && data[i].robot_ribs - && data[i].team_ribs); + let dataValid = (data[i].robot_bbq !== null + && data[i].team_bbq !== null + && data[i].robot_sauce !== null + && data[i].team_sauce !== null + && data[i].robot_briquette !== null + && data[i].team_briquette !== null + && data[i].robot_ribs !== null + && data[i].team_ribs !== null); let eventInfo = { "name": data[i].Event.name, @@ -266,6 +282,20 @@ export default { }, setUpperYearFilter(yearIdx) { this.upperYearIndex = yearIdx; + + // If the upper year is now earlier than 2005, SAUCE is 0. Prevent the SAUCE filter from activating. + const prevSauceEnabled = this.enabledMap.stats['sauce']; + if (yearIdx < this.upperYearFilters.length && this.upperYearFilters[yearIdx] < 2005) { + this.enabledMap.stats['sauce'] = false; + } else { + this.enabledMap.stats['sauce'] = true; + } + + // If SAUCE has been disabled/enabled via the year flag, update the column visibility appropriately. + if (this.enabledMap.stats['sauce'] != prevSauceEnabled) { + this.updateColumnVisibility(); + } + this.rankEvents(); }, sortColumn(col_idx) { @@ -274,28 +304,45 @@ export default { this.rankEvents(); } }, - toggleStatFilter(stat) { - if (Object.keys(this.visibilityMap.stats).includes(stat)) { - this.visibilityMap.stats[stat] = !this.visibilityMap.stats[stat]; - this.updateColumnVisibility(); - } + chipEnabled(chip) { + return (Object.keys(this.enabledMap.stats).includes(chip) + && this.enabledMap.stats[chip] === true) + || (Object.keys(this.enabledMap.types).includes(chip) + && this.enabledMap.types[chip] === true); + }, + chipVisible(chip) { + return (Object.keys(this.visibilityMap.stats).includes(chip) + && this.visibilityMap.stats[chip] == true) + || (Object.keys(this.visibilityMap.types).includes(chip) + && this.visibilityMap.types[chip] == true) + }, + chipToggleable(chip) { + return this.chipEnabled(chip); }, - toggleTypeFilter(stat_type) { - if (Object.keys(this.visibilityMap.types).includes(stat_type)) { - this.visibilityMap.types[stat_type] = !this.visibilityMap.types[stat_type]; + toggleChip(chip) { + if (!this.chipToggleable(chip)) { + return; + } + + if (Object.keys(this.visibilityMap.stats).includes(chip)) { + this.visibilityMap.stats[chip] = !this.visibilityMap.stats[chip]; + this.updateColumnVisibility(); + } else if (Object.keys(this.visibilityMap.types).includes(chip)) { + this.visibilityMap.types[chip] = !this.visibilityMap.types[chip]; this.updateColumnVisibility(); } }, - getStatChipStatus(stat) { - if (Object.keys(this.visibilityMap.stats).includes(stat)) { - return this.visibilityMap.stats[stat]; + getChipStatus(chip) { + if (!this.chipToggleable(chip)) { + return false; } - return false; - }, - getTypeChipStatus(stat_type) { - if (Object.keys(this.visibilityMap.types).includes(stat_type)) { - return this.visibilityMap.types[stat_type]; + + if (Object.keys(this.visibilityMap.stats).includes(chip)) { + return this.visibilityMap.stats[chip]; + } else if (Object.keys(this.visibilityMap.types).includes(chip)) { + return this.visibilityMap.types[chip]; } + return false; }, updateColumnVisibility() { @@ -303,8 +350,14 @@ export default { let colType = this.tableColumns[i].type; let colStat = this.tableColumns[i].stat; - if (Object.keys(this.visibilityMap.types).includes(colType) && Object.keys(this.visibilityMap.stats).includes(colStat)) { - let visibility = (this.visibilityMap.types[colType]) && (this.visibilityMap.stats[colStat]); + if (Object.keys(this.visibilityMap.types).includes(colType) + && Object.keys(this.visibilityMap.stats).includes(colStat) + && Object.keys(this.enabledMap.types).includes(colType) + && Object.keys(this.enabledMap.stats).includes(colStat)) { + let visibility = (this.visibilityMap.types[colType]) + && (this.visibilityMap.stats[colStat]) + && (this.enabledMap.types[colType]) + && (this.enabledMap.stats[colStat]); this.tableColumns[i].visible = visibility; } }