add average pp stat
All checks were successful
deploy / deploy (push) Successful in 58s

This commit is contained in:
Lee 2023-10-22 05:34:08 +01:00
parent 58ddf3d79a
commit 154eec2aac
2 changed files with 34 additions and 1 deletions

@ -2,7 +2,11 @@ import { ScoresaberPlayer } from "@/schemas/scoresaber/player";
import { usePlayerScoresStore } from "@/store/playerScoresStore";
import { useSettingsStore } from "@/store/settingsStore";
import { formatNumber } from "@/utils/number";
import { calcPpBoundary, getHighestPpPlay } from "@/utils/scoresaber/scores";
import {
calcPpBoundary,
getAveragePp,
getHighestPpPlay,
} from "@/utils/scoresaber/scores";
import {
GlobeAsiaAustraliaIcon,
HomeIcon,
@ -179,6 +183,14 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
getHighestPpPlay(playerId)?.toFixed(2),
)}pp`}
/>
<Label
title="Avg PP"
className="bg-[#8992e8]"
hoverValue="Average amount of pp per play (best 20 scores)"
value={`${formatNumber(
getAveragePp(playerId)?.toFixed(2),
)}pp`}
/>
<Label
title="+ 1pp"
className="bg-[#8992e8]"

@ -168,3 +168,24 @@ export function getHighestPpPlay(playerId: string) {
return rankedScorePps[0];
}
/**
* Gets the average pp of the player
*
* @param playerId the player id
* @param limit the amount of top scores to average (default: 20)
*/
export function getAveragePp(playerId: string, limit: number = 20) {
const rankedScores = usePlayerScoresStore
.getState()
.players.find((p) => p.id === playerId)
?.scores?.filter((s) => s.score.pp !== undefined);
if (!rankedScores) return null;
const rankedScorePps = rankedScores
.map((s) => s.score.pp)
.sort((a, b) => b - a)
.slice(0, limit);
return getTotalPpFromSortedPps(rankedScorePps, 0) / limit;
}