maybe now?!?
All checks were successful
Deploy / deploy (push) Successful in 2m47s

This commit is contained in:
Lee 2024-09-28 06:31:25 +01:00
parent 32e8468126
commit 0410f6b324
4 changed files with 25 additions and 6 deletions

View File

@ -3,7 +3,11 @@ import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-p
import { PlayerHistory } from "@/common/player/player-history";
import { config } from "../../../../../config";
import ky from "ky";
import { getDaysAgoDate, getMidnightAlignedDate } from "@/common/time-utils";
import {
formatDate,
getDaysAgoDate,
getMidnightAlignedDate,
} from "@/common/time-utils";
/**
* A ScoreSaber player.
@ -84,7 +88,7 @@ export async function getScoreSaberPlayerFromToken(
}
if (history) {
// Use the latest data for today
history[getMidnightAlignedDate(new Date()).toString()] = {
history[formatDate(getMidnightAlignedDate(new Date()))] = {
rank: token.rank,
countryRank: token.countryRank,
pp: token.pp,

View File

@ -1,6 +1,6 @@
import mongoose, { Document, Schema } from "mongoose";
import { PlayerHistory } from "@/common/player/player-history";
import { getMidnightAlignedDate } from "@/common/time-utils";
import { formatDate, getMidnightAlignedDate } from "@/common/time-utils";
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
// Interface for Player Document
@ -70,7 +70,7 @@ PlayerSchema.methods.getLastTracked = function (): Date {
PlayerSchema.methods.getHistory = function (date: Date): PlayerHistory {
return (
this.statisticHistory.get(getMidnightAlignedDate(date).toUTCString()) || {}
this.statisticHistory.get(formatDate(getMidnightAlignedDate(date))) || {}
);
};
@ -91,8 +91,10 @@ PlayerSchema.methods.setStatisticHistory = function (
if (!this.statisticHistory) {
this.statisticHistory = new Map();
}
const alignedDate = getMidnightAlignedDate(date).toUTCString();
return this.statisticHistory.set(alignedDate, data);
return this.statisticHistory.set(
formatDate(getMidnightAlignedDate(date)),
data,
);
};
PlayerSchema.methods.sortStatisticHistory = function (): Map<

View File

@ -28,6 +28,17 @@ export function timeAgo(input: Date | number) {
}
}
/**
* Formats the date
*
* @param date the date
*/
export function formatDate(date: Date) {
return date.toLocaleString("en-US", {
timeZone: "Europe/London",
});
}
/**
* Gets the midnight aligned date
*

View File

@ -169,6 +169,7 @@ type Props = {
};
export default function PlayerRankChart({ player }: Props) {
console.log(player.statisticHistory);
if (
player.statisticHistory === undefined ||
Object.keys(player.statisticHistory).length === 0
@ -193,6 +194,7 @@ export default function PlayerRankChart({ player }: Props) {
// Create labels based on days ago
if (daysAgo === 0) {
labels.push("Today");
console.log(dateString);
} else if (daysAgo === 1) {
labels.push("Yesterday");
} else {