From f8f51304e3daad9b8601e741444cf68eee5ce4e1 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 8 May 2024 21:04:24 +0100 Subject: [PATCH] feat: completely redo the raise breakdown THis logic was hopelessly broken, what was i smoking? (heh) --- .../sessions/SessionRaiseBreakdown.tsx | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/client/src/components/sessions/SessionRaiseBreakdown.tsx b/client/src/components/sessions/SessionRaiseBreakdown.tsx index ac252a127..d011ae54e 100644 --- a/client/src/components/sessions/SessionRaiseBreakdown.tsx +++ b/client/src/components/sessions/SessionRaiseBreakdown.tsx @@ -128,15 +128,15 @@ function SessionScoreStatBreakdown({ const enumMetrics = GetScoreMetrics(gptConfig, "ENUM"); + type Datapoint = { score: ScoreDocument; scoreInfo: SessionScoreInfo }; const newEnums = useMemo(() => { - const newEnums: Record< - string, - Record - > = {}; + const newEnums: Record>> = {}; for (const metric of enumMetrics) { newEnums[metric] = {}; + const highestMetric: Record = {}; + for (const scoreInfo of sessionData.scoreInfo) { const score = scoreMap.get(scoreInfo.scoreID); @@ -147,41 +147,36 @@ function SessionScoreStatBreakdown({ continue; } - if (scoreInfo.isNewScore || scoreInfo.deltas[metric] > 0) { - // @ts-expect-error yeah this is fine pls - const enumValue = score.scoreData[metric] as string; - // @ts-expect-error yeah this is fine pls - const enumIndex = score.scoreData.enumIndexes[metric] as integer; - - if (newEnums[metric][enumValue]) { - const alreadyInArray = newEnums[metric][enumValue].find( - (e) => - e.score.scoreID === score.scoreID || - e.score.chartID === score.chartID - ); - - if (alreadyInArray) { - if ( - // @ts-expect-error not justifying this - alreadyInArray.score.scoreData.enumIndexes[enumValue] < enumIndex - ) { - alreadyInArray.score = score; - alreadyInArray.scoreInfo = scoreInfo; - } - } else { - newEnums[metric][enumValue].push({ - score, - scoreInfo, - }); - } - } else { - newEnums[metric][enumValue] = [ - { - score, - scoreInfo, - }, - ]; + if (!scoreInfo.isNewScore && scoreInfo.deltas[metric] <= 0) { + // not a raise + continue; + } + + if (highestMetric[score.chartID]) { + const prevScore = highestMetric[score.chartID].score; + + // trumps previous score + if ( + // @ts-expect-error yeah this is fine pls + prevScore.scoreData.enumIndexes[metric] < + // @ts-expect-error yeah this is fine pls + score.scoreData.enumIndexes[metric] + ) { + highestMetric[score.chartID] = { score, scoreInfo }; } + } else { + highestMetric[score.chartID] = { score, scoreInfo }; + } + } + + for (const s of Object.values(highestMetric)) { + // @ts-expect-error bad metric type + const enumValue = s.score.scoreData[metric]; + + if (newEnums[metric][enumValue]) { + newEnums[metric][enumValue].push(s); + } else { + newEnums[metric][enumValue] = [s]; } } }