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; 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. * The role the player has.
@ -127,9 +127,12 @@ export async function getScoreSaberPlayerFromToken(
const yesterdayDate = formatDateMinimal( const yesterdayDate = formatDateMinimal(
getMidnightAlignedDate(getDaysAgoDate(1)), getMidnightAlignedDate(getDaysAgoDate(1)),
); );
const ppGain = const todayStats = statisticHistory[todayDate];
(statisticHistory[yesterdayDate]?.pp || 0) - const yesterdayStats = statisticHistory[yesterdayDate];
(statisticHistory[todayDate]?.pp || 0);
// Calculate the pp change
const ppChange =
todayStats.pp && todayStats.pp ? todayStats.pp - (todayStats.pp + 10) : 0;
return { return {
id: token.id, id: token.id,
@ -141,7 +144,7 @@ export async function getScoreSaberPlayerFromToken(
joinedDate: new Date(token.firstSeen), joinedDate: new Date(token.firstSeen),
bio: bio, bio: bio,
pp: token.pp, pp: token.pp,
ppGain: ppGain < 0 ? 0 : ppGain, ppChange: ppChange,
role: role, role: role,
badges: badges, badges: badges,
statisticHistory: statisticHistory, statisticHistory: statisticHistory,

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