fix total score change
This commit is contained in:
parent
be25896c5e
commit
f89207f306
@ -125,6 +125,10 @@ export async function getScoreSaberPlayerFromToken(
|
||||
accuracy: {
|
||||
averageRankedAccuracy: token.scoreStats.averageRankedAccuracy,
|
||||
},
|
||||
scores: {
|
||||
totalScores: token.scoreStats.totalPlayCount,
|
||||
totalRankedScores: token.scoreStats.rankedPlayCount,
|
||||
},
|
||||
};
|
||||
|
||||
isBeingTracked = true;
|
||||
@ -177,10 +181,11 @@ export async function getScoreSaberPlayerFromToken(
|
||||
* Gets the change in the given stat
|
||||
*
|
||||
* @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
|
||||
* @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];
|
||||
let otherDate: Date | undefined;
|
||||
|
||||
@ -218,14 +223,14 @@ export async function getScoreSaberPlayerFromToken(
|
||||
}
|
||||
|
||||
// Ensure todayStats exists and contains the statType
|
||||
if (!todayStats || !(statType in todayStats)) {
|
||||
if (!todayStats || !getValueFromHistory(todayStats, statType)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const otherStats = statisticHistory[formatDateMinimal(otherDate)]; // This is now validated
|
||||
|
||||
// Ensure otherStats exists and contains the statType
|
||||
if (!otherStats || !(statType in otherStats)) {
|
||||
if (!otherStats || !getValueFromHistory(otherStats, statType)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -235,19 +240,17 @@ export async function getScoreSaberPlayerFromToken(
|
||||
if (statToday === undefined || statOther === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Return the difference, accounting for negative changes in ranks
|
||||
return (statToday - statOther) * (statType === "pp" ? 1 : -1);
|
||||
return (statToday - statOther) * (!positive ? 1 : -1);
|
||||
};
|
||||
|
||||
const getStatisticChanges = (daysAgo: number): PlayerHistory => {
|
||||
return {
|
||||
rank: getStatisticChange("rank", daysAgo),
|
||||
countryRank: getStatisticChange("countryRank", daysAgo),
|
||||
pp: getStatisticChange("pp", daysAgo),
|
||||
rank: getStatisticChange("rank", true, daysAgo),
|
||||
countryRank: getStatisticChange("countryRank", true, daysAgo),
|
||||
pp: getStatisticChange("pp", false, daysAgo),
|
||||
scores: {
|
||||
totalScores: getStatisticChange("scores.totalScores", daysAgo),
|
||||
totalRankedScores: getStatisticChange("scores.totalRankedScores", daysAgo),
|
||||
totalScores: getStatisticChange("scores.totalScores", false, daysAgo),
|
||||
totalRankedScores: getStatisticChange("scores.totalRankedScores", false, daysAgo),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -58,11 +58,39 @@ const datasetConfig: DatasetConfig[] = [
|
||||
},
|
||||
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",
|
||||
field: "scores.rankedScores",
|
||||
color: "#ffae4d",
|
||||
axisId: "y3",
|
||||
axisId: "y5",
|
||||
axisConfig: {
|
||||
reverse: false,
|
||||
display: false,
|
||||
@ -76,7 +104,7 @@ const datasetConfig: DatasetConfig[] = [
|
||||
title: "Unranked Scores",
|
||||
field: "scores.unrankedScores",
|
||||
color: "#616161",
|
||||
axisId: "y3",
|
||||
axisId: "y5",
|
||||
axisConfig: {
|
||||
reverse: false,
|
||||
display: false,
|
||||
|
Reference in New Issue
Block a user