cleanup hand acc
All checks were successful
Deploy Website / docker (ubuntu-latest) (push) Successful in 2m44s

This commit is contained in:
Lee 2024-10-23 07:31:43 +01:00
parent c3cf48e731
commit ff9ff5b96b
3 changed files with 87 additions and 44 deletions

@ -1,19 +1,44 @@
import React from "react"; import React from "react";
import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils";
/** type ChangeProps = {
* Renders the change for a stat. /**
* * The amount the value changed
* @param change the change */
* @param isPp whether the stat is pp change: number | undefined;
* @param formatValue the function to format the value
*/ /**
export function renderChange(change: number | undefined, isPp: boolean, formatValue: (value: number) => string) { * The function to format the value
* @param value
*/
formatValue?: (value: number) => string;
/**
* Whether the number is a pp number
*/
isPp?: boolean;
/**
* Should we use colors?
*/
showColors?: boolean;
};
export function Change({ change, formatValue, isPp, showColors }: ChangeProps) {
if (change === 0 || (change && change > 0 && change < 0.01) || change === undefined) { if (change === 0 || (change && change > 0 && change < 0.01) || change === undefined) {
return null; return null;
} }
// Default formats
if (!formatValue) {
formatValue = formatNumberWithCommas;
if (isPp) {
formatValue = formatPp;
}
}
return ( return (
<p className={`text-sm ${change > 0 ? "text-green-400" : "text-red-400"}`}> <p className={`text-sm ${showColors && (change > 0 ? "text-green-400" : "text-red-400")}`}>
{change > 0 ? "+" : ""} {change > 0 ? "+" : ""}
{`${formatValue(change)}${isPp ? "pp" : ""}`} {`${formatValue(change)}${isPp ? "pp" : ""}`}
</p> </p>

@ -0,0 +1,39 @@
import Tooltip from "@/components/tooltip";
import { Change } from "@/common/change";
import ScoreSaberScore from "@ssr/common/score/impl/scoresaber-score";
import { capitalizeFirstLetter } from "@/common/string-utils";
type HandAccuracyProps = {
/**
* The score to get the hand accuracy from
*/
score: ScoreSaberScore;
/**
* The hand to get the hand accuracy from
*/
hand: "left" | "right";
};
export function HandAccuracy({ score, hand }: HandAccuracyProps) {
if (!score.additionalData) {
return undefined;
}
const { handAccuracy } = score.additionalData;
const scoreImprovement = score.additionalData.scoreImprovement;
const previousHandAccuracy = scoreImprovement ? handAccuracy[hand] - scoreImprovement.handAccuracy[hand] : undefined;
const formattedHand = capitalizeFirstLetter(hand);
return (
<div className="flex flex-col items-center justify-center">
<Tooltip display={`${formattedHand} Hand Accuracy`}>
<p>{handAccuracy[hand].toFixed(2)}</p>
</Tooltip>
{scoreImprovement && previousHandAccuracy && (
<Tooltip display={`Previous ${formattedHand} Hand Accuracy: ${previousHandAccuracy.toFixed(2)}`}>
<Change change={scoreImprovement.handAccuracy[hand]} formatValue={num => num.toFixed(2)} />
</Tooltip>
)}
</div>
);
}

@ -7,8 +7,9 @@ import ScoreSaberLeaderboard from "@ssr/common/leaderboard/impl/scoresaber-leade
import ScoreMissesBadge from "@/components/score/badges/score-misses"; import ScoreMissesBadge from "@/components/score/badges/score-misses";
import { Modifier } from "@ssr/common/score/modifier"; import { Modifier } from "@ssr/common/score/modifier";
import { ScoreModifiers } from "@/components/score/score-modifiers"; import { ScoreModifiers } from "@/components/score/score-modifiers";
import { renderChange } from "@/common/change"; import { Change } from "@/common/change";
import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
import { HandAccuracy } from "@/components/score/hand-accuracy";
const badges: ScoreBadge[] = [ const badges: ScoreBadge[] = [
{ {
@ -17,6 +18,8 @@ const badges: ScoreBadge[] = [
return "bg-pp"; return "bg-pp";
}, },
create: (score: ScoreSaberScore, leaderboard: ScoreSaberLeaderboard) => { create: (score: ScoreSaberScore, leaderboard: ScoreSaberLeaderboard) => {
const scoreImprovement = score.additionalData?.scoreImprovement;
const previousAccuracy = scoreImprovement ? score.accuracy - scoreImprovement?.accuracy : undefined;
const fcAccuracy = score.additionalData?.fcAccuracy; const fcAccuracy = score.additionalData?.fcAccuracy;
const pp = score.pp; const pp = score.pp;
const weight = score.weight; const weight = score.weight;
@ -39,7 +42,10 @@ const badges: ScoreBadge[] = [
</div> </div>
} }
> >
<p>{formatPp(pp)}pp</p> <div className="flex flex-col items-center justify-center cursor-default">
<p>{formatPp(pp)}pp</p>
{previousAccuracy && <Change change={previousAccuracy} isPp />}
</div>
</Tooltip> </Tooltip>
</> </>
); );
@ -93,10 +99,9 @@ const badges: ScoreBadge[] = [
<p> <p>
{acc.toFixed(2)}% {modCount > 0 && <ScoreModifiers type="simple" limit={1} score={score} />} {acc.toFixed(2)}% {modCount > 0 && <ScoreModifiers type="simple" limit={1} score={score} />}
</p> </p>
{scoreImprovement && {scoreImprovement && (
renderChange(scoreImprovement.accuracy, false, num => { <Change change={scoreImprovement.accuracy} formatValue={num => `${num.toFixed(2)}%`} />
return `${num.toFixed(2)}%`; )}
})}
</div> </div>
</Tooltip> </Tooltip>
</> </>
@ -111,7 +116,7 @@ const badges: ScoreBadge[] = [
return ( return (
<div className="flex flex-col items-center justify-center"> <div className="flex flex-col items-center justify-center">
<p>{formatNumberWithCommas(Number(score.score.toFixed(0)))}</p> <p>{formatNumberWithCommas(Number(score.score.toFixed(0)))}</p>
{scoreImprovement && renderChange(scoreImprovement.score, false, formatNumberWithCommas)} {scoreImprovement && <Change change={scoreImprovement.score} />}
</div> </div>
); );
}, },
@ -120,40 +125,14 @@ const badges: ScoreBadge[] = [
name: "Left Hand Accuracy", name: "Left Hand Accuracy",
color: () => "bg-hands-left", color: () => "bg-hands-left",
create: (score: ScoreSaberScore) => { create: (score: ScoreSaberScore) => {
if (!score.additionalData) { return <HandAccuracy score={score} hand="left" />;
return undefined;
}
const { handAccuracy } = score.additionalData;
const scoreImprovement = score.additionalData.scoreImprovement;
return (
<Tooltip display={"Left Hand Accuracy"}>
<div className="flex flex-col items-center justify-center">
<p>{handAccuracy.left.toFixed(2)}</p>
{scoreImprovement && renderChange(scoreImprovement.handAccuracy.left, false, num => num.toFixed(2))}
</div>
</Tooltip>
);
}, },
}, },
{ {
name: "Right Hand Accuracy", name: "Right Hand Accuracy",
color: () => "bg-hands-right", color: () => "bg-hands-right",
create: (score: ScoreSaberScore) => { create: (score: ScoreSaberScore) => {
if (!score.additionalData) { return <HandAccuracy score={score} hand="right" />;
return undefined;
}
const { handAccuracy } = score.additionalData;
const scoreImprovement = score.additionalData.scoreImprovement;
return (
<Tooltip display={"Right Hand Accuracy"}>
<div className="flex flex-col items-center justify-center">
<p>{handAccuracy.right.toFixed(2)}</p>
{scoreImprovement && renderChange(scoreImprovement.handAccuracy.right, false, num => num.toFixed(2))}
</div>
</Tooltip>
);
}, },
}, },
{ {