myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests | README | LICENSE

commit b0853f4821f4a8f8dce63f78c40f20d5c284cc87
parent 6b8ece9467307746b71cb6a1c0ac651df1522a10
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Wed,  8 Mar 2023 22:33:58 +0100

feat: add best/worst heat column

Diffstat:
Msrc/App.js | 29++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/App.js b/src/App.js @@ -33,23 +33,22 @@ async function getRatingSummary(heatIds) { let startListWithRatings = [] for (const i of startlist.data) { - i.ratings = [] - i.summary = [] + i.heats = [] for (const h of heatIds) { let ratings = await getRatingForHeatAndAthlete(h, i.athlete) - i.ratings[h] = ratings.data let summary = {data: []} summary = await supabase.from('rating_summary').select('rating_summary') .eq('heat_id', h) .eq('athlete_id', i.athlete) - if (summary.data.length > 0) { - i.summary[h] = summary.data[0].rating_summary - } else { - i.summary[h] = 0 - } + // add heat results of athlete to startlist entry + i.heats.push({ + heatId: h, + ratings: ratings.data, + summary: summary.data.length > 0 ? summary.data[0].rating_summary : 0 + }) } startListWithRatings.push(i) @@ -62,8 +61,8 @@ function rankByHeat(rankingComp) { return function(a, b) { // rank by chosen heat or ranking comparator for (const r of rankingComp) { - if (b.summary[r.value] - a.summary[r.value] !== 0) { - return b.summary[r.value] - a.summary[r.value] + if (b.heats.find(h => h.heatId === r.value)?.summary - a.heats.find(h => h.heatId === r.value)?.summary !== 0) { + return b.heats.find(h => h.heatId === r.value)?.summary - a.heats.find(h => h.heatId === r.value)?.summary } } } @@ -135,7 +134,7 @@ function App() { <th>Lastname</th> <th>Birthday</th> <th>School</th> - <th colSpan={heatSelection.length*2}>Ratings & Total</th> + <th colSpan={heatSelection.length * 2 + 2}>Ratings & Total</th> </tr> <tr> <th></th> @@ -146,6 +145,8 @@ function App() { {heatSelection.map(h => ( <th key={h.value} colSpan={2}>{h.label}</th> ))} + <th>👍 Best</th> + <th>👎 Worst</th> </tr> </thead> <tbody> @@ -158,10 +159,12 @@ function App() { <td>{i.school}</td> {heatSelection.map(h => ( <Fragment key={h.value}> - <td className='right'>{i.ratings[h.value]?.map(r => r.rating).join(" / ")}</td> - <td className='right'>{i.summary[h.value]}</td> + <td className='right'>{i.heats.find(heat => heat.heatId === h.value)?.ratings?.map(r => r.rating).join(" / ")}</td> + <td className='right'>{i.heats.find(heat => heat.heatId === h.value)?.summary}</td> </Fragment> ))} + <th>{Math.max(...i.heats.map(h => h.summary))}</th> + <th>{Math.min(...i.heats.map(h => h.summary))}</th> </tr> ))} </tbody>