Skip to content

Commit

Permalink
feat: completely redo the raise breakdown
Browse files Browse the repository at this point in the history
THis logic was hopelessly broken,
what was i smoking? (heh)
  • Loading branch information
zkrising committed May 8, 2024
1 parent 238cf05 commit f8f5130
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions client/src/components/sessions/SessionRaiseBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { score: ScoreDocument; scoreInfo: SessionScoreInfo }[]>
> = {};
const newEnums: Record<string, Record<string, Array<Datapoint>>> = {};

for (const metric of enumMetrics) {
newEnums[metric] = {};

const highestMetric: Record<string, Datapoint> = {};

for (const scoreInfo of sessionData.scoreInfo) {
const score = scoreMap.get(scoreInfo.scoreID);

Expand All @@ -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];
}
}
}
Expand Down

0 comments on commit f8f5130

Please sign in to comment.