allow for negative pp change
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
Lee 2024-09-28 07:59:49 +01:00
parent 8b935145f6
commit 4b11a63f46
2 changed files with 17 additions and 11 deletions

@ -24,9 +24,9 @@ export default interface ScoreSaberPlayer extends Player {
pp: number;
/**
* The amount of pp gained compared to yesterday.
* The change in pp compared to yesterday.
*/
ppGain: number;
ppChange: number;
/**
* The role the player has.
@ -127,9 +127,12 @@ export async function getScoreSaberPlayerFromToken(
const yesterdayDate = formatDateMinimal(
getMidnightAlignedDate(getDaysAgoDate(1)),
);
const ppGain =
(statisticHistory[yesterdayDate]?.pp || 0) -
(statisticHistory[todayDate]?.pp || 0);
const todayStats = statisticHistory[todayDate];
const yesterdayStats = statisticHistory[yesterdayDate];
// Calculate the pp change
const ppChange =
todayStats.pp && todayStats.pp ? todayStats.pp - (todayStats.pp + 10) : 0;
return {
id: token.id,
@ -141,7 +144,7 @@ export async function getScoreSaberPlayerFromToken(
joinedDate: new Date(token.firstSeen),
bio: bio,
pp: token.pp,
ppGain: ppGain < 0 ? 0 : ppGain,
ppChange: ppChange,
role: role,
badges: badges,
statisticHistory: statisticHistory,

@ -33,11 +33,14 @@ const playerData = [
return (
<div className="text-pp flex gap-1 items-center">
<p>{formatPp(player.pp)}pp</p>
{player.ppGain > 0 && (
<Tooltip display={<p>The amount of PP you have gained today</p>}>
<span className="text-green-400 text-sm">+{player.ppGain}pp</span>
</Tooltip>
)}
<Tooltip display={<p>The change in your pp compared to yesterday</p>}>
<p
className={`text-sm ${player.ppChange > 0 ? "text-green-400" : "text-red-400"}`}
>
{player.ppChange > 0 ? "+" : ""}
{formatPp(player.ppChange)}pp
</p>
</Tooltip>
</div>
);
},