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 6b8ece9467307746b71cb6a1c0ac651df1522a10
parent b8e95381bf4b488d2694cd1040890e4e2ee92a20
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Wed,  8 Mar 2023 20:49:58 +0100

feat: rank by heats

Diffstat:
Msrc/App.js | 28+++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/App.js b/src/App.js @@ -58,10 +58,22 @@ async function getRatingSummary(heatIds) { return startListWithRatings } +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] + } + } + } +} + function App() { const [leaderboard, setLeaderboard] = useState([]); const [heatSelection, setHeatSelection] = useState([{value: 0, label: ''}]); const [heats, setHeats] = useState([]); + const [rankingComp, setRankingComp] = useState([{value: 0, label: ''}]); useEffect(() => { (async () => { @@ -83,7 +95,7 @@ function App() { table: 'ratings', }, async (payload) => { - let ratingSummary = await getRatingSummary(1) + let ratingSummary = await getRatingSummary(heatSelection.map(h => h.value)) setLeaderboard(ratingSummary) } ).subscribe() @@ -92,7 +104,7 @@ function App() { <div className="App"> <header> <div> - Heats: <br /> + Heats: <Select closeMenuOnSelect={false} isMulti @@ -102,6 +114,16 @@ function App() { }})} onChange={h => setHeatSelection(h)} /> + Rank by (in this order): + <Select + closeMenuOnSelect={false} + isMulti + options={heats.map(h => {return { + value: h.id, + label: h.name + }})} + onChange={h => setRankingComp(h)} + /> </div> <h1>🏅 Leaderboard</h1> </header> @@ -127,7 +149,7 @@ function App() { </tr> </thead> <tbody> - {leaderboard.sort((a,b) => b.summary - a.summary).map(i => ( + {leaderboard.sort(rankByHeat(rankingComp)).map(i => ( <tr key={i.id}> <td>{i.nr}</td> <td>{i.firstname}</td>