fix total score change
All checks were successful
Deploy Backend / docker (ubuntu-latest) (push) Successful in 48s
Deploy Website / docker (ubuntu-latest) (push) Successful in 2m7s

This commit is contained in:
Lee 2024-10-22 12:34:17 +01:00
parent be25896c5e
commit f89207f306
2 changed files with 44 additions and 13 deletions

@ -125,6 +125,10 @@ export async function getScoreSaberPlayerFromToken(
accuracy: { accuracy: {
averageRankedAccuracy: token.scoreStats.averageRankedAccuracy, averageRankedAccuracy: token.scoreStats.averageRankedAccuracy,
}, },
scores: {
totalScores: token.scoreStats.totalPlayCount,
totalRankedScores: token.scoreStats.rankedPlayCount,
},
}; };
isBeingTracked = true; isBeingTracked = true;
@ -177,10 +181,11 @@ export async function getScoreSaberPlayerFromToken(
* Gets the change in the given stat * Gets the change in the given stat
* *
* @param statType the stat to check * @param statType the stat to check
* @param positive whether to multiply the change by 1 or -1
* @param daysAgo the amount of days ago to get the stat for * @param daysAgo the amount of days ago to get the stat for
* @return the change * @return the change
*/ */
const getStatisticChange = (statType: string, daysAgo: number = 1): number | undefined => { const getStatisticChange = (statType: string, positive: boolean, daysAgo: number = 1): number | undefined => {
const todayStats = statisticHistory[todayDate]; const todayStats = statisticHistory[todayDate];
let otherDate: Date | undefined; let otherDate: Date | undefined;
@ -218,14 +223,14 @@ export async function getScoreSaberPlayerFromToken(
} }
// Ensure todayStats exists and contains the statType // Ensure todayStats exists and contains the statType
if (!todayStats || !(statType in todayStats)) { if (!todayStats || !getValueFromHistory(todayStats, statType)) {
return undefined; return undefined;
} }
const otherStats = statisticHistory[formatDateMinimal(otherDate)]; // This is now validated const otherStats = statisticHistory[formatDateMinimal(otherDate)]; // This is now validated
// Ensure otherStats exists and contains the statType // Ensure otherStats exists and contains the statType
if (!otherStats || !(statType in otherStats)) { if (!otherStats || !getValueFromHistory(otherStats, statType)) {
return undefined; return undefined;
} }
@ -235,19 +240,17 @@ export async function getScoreSaberPlayerFromToken(
if (statToday === undefined || statOther === undefined) { if (statToday === undefined || statOther === undefined) {
return undefined; return undefined;
} }
return (statToday - statOther) * (!positive ? 1 : -1);
// Return the difference, accounting for negative changes in ranks
return (statToday - statOther) * (statType === "pp" ? 1 : -1);
}; };
const getStatisticChanges = (daysAgo: number): PlayerHistory => { const getStatisticChanges = (daysAgo: number): PlayerHistory => {
return { return {
rank: getStatisticChange("rank", daysAgo), rank: getStatisticChange("rank", true, daysAgo),
countryRank: getStatisticChange("countryRank", daysAgo), countryRank: getStatisticChange("countryRank", true, daysAgo),
pp: getStatisticChange("pp", daysAgo), pp: getStatisticChange("pp", false, daysAgo),
scores: { scores: {
totalScores: getStatisticChange("scores.totalScores", daysAgo), totalScores: getStatisticChange("scores.totalScores", false, daysAgo),
totalRankedScores: getStatisticChange("scores.totalRankedScores", daysAgo), totalRankedScores: getStatisticChange("scores.totalRankedScores", false, daysAgo),
}, },
}; };
}; };

@ -58,11 +58,39 @@ const datasetConfig: DatasetConfig[] = [
}, },
labelFormatter: (value: number) => `PP: ${formatNumberWithCommas(value)}pp`, labelFormatter: (value: number) => `PP: ${formatNumberWithCommas(value)}pp`,
}, },
{
title: "Total Scores",
field: "scores.totalScores",
color: "#616161",
axisId: "y3",
showLegend: false,
axisConfig: {
reverse: false,
display: false,
displayName: "Total Scores",
position: "left",
},
labelFormatter: (value: number) => `Total Scores: ${formatNumberWithCommas(value)}`,
},
{
title: "Total Ranked Scores",
field: "scores.totalRankedScores",
color: "#6773ff",
axisId: "y4",
showLegend: false,
axisConfig: {
reverse: false,
display: false,
displayName: "Total Ranked Scores",
position: "left",
},
labelFormatter: (value: number) => `Total Ranked Scores: ${formatNumberWithCommas(value)}`,
},
{ {
title: "Ranked Scores", title: "Ranked Scores",
field: "scores.rankedScores", field: "scores.rankedScores",
color: "#ffae4d", color: "#ffae4d",
axisId: "y3", axisId: "y5",
axisConfig: { axisConfig: {
reverse: false, reverse: false,
display: false, display: false,
@ -76,7 +104,7 @@ const datasetConfig: DatasetConfig[] = [
title: "Unranked Scores", title: "Unranked Scores",
field: "scores.unrankedScores", field: "scores.unrankedScores",
color: "#616161", color: "#616161",
axisId: "y3", axisId: "y5",
axisConfig: { axisConfig: {
reverse: false, reverse: false,
display: false, display: false,