fix
All checks were successful
Deploy Backend / docker (ubuntu-latest) (push) Successful in 44s
Deploy Website / docker (ubuntu-latest) (push) Successful in 2m43s

This commit is contained in:
Lee 2024-10-20 19:52:33 +01:00
parent 06a13bedc8
commit 81640c3c4e
4 changed files with 27 additions and 28 deletions

@ -5,7 +5,7 @@ import ScoreSaberPlayerToken from "../../types/token/scoresaber/score-saber-play
import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../utils/time-utils";
import { getPageFromRank } from "../../utils/utils";
import { Config } from "../../config";
import { getValueFromHistory } from "website/src/common/player-utils";
import { getValueFromHistory } from "../../utils/player-utils";
/**
* A ScoreSaber player.

@ -17,6 +17,31 @@ export function getPlayerHistoryToday(player: ScoreSaberPlayer) {
return player.statisticHistory[formatDateMinimal(today)] || {};
}
/**
* Gets a value from an {@link PlayerHistory}
* based on the field
*
* @param history the history to get the value from
* @param field the field to get
*/
export function getValueFromHistory(history: PlayerHistory, field: string): number | undefined {
const keys = field.split(".");
/* eslint-disable @typescript-eslint/no-explicit-any */
let value: any = history;
// Navigate through the keys safely
for (const key of keys) {
if (value && key in value) {
value = value[key];
} else {
return undefined; // Return null if the key doesn't exist
}
}
// Ensure we return a number or null
return typeof value === "number" ? value : undefined;
}
/**
* Sorts the player history based on date,
* so the most recent date is first

@ -1,26 +0,0 @@
import { PlayerHistory } from "@ssr/common/player/player-history";
/**
* Gets a value from an {@link PlayerHistory}
* based on the field
*
* @param history the history to get the value from
* @param field the field to get
*/
export function getValueFromHistory(history: PlayerHistory, field: string): number | undefined {
const keys = field.split(".");
/* eslint-disable @typescript-eslint/no-explicit-any */
let value: any = history;
// Navigate through the keys safely
for (const key of keys) {
if (value && key in value) {
value = value[key];
} else {
return undefined; // Return null if the key doesn't exist
}
}
// Ensure we return a number or null
return typeof value === "number" ? value : undefined;
}

@ -2,9 +2,9 @@
import React from "react";
import GenericChart, { DatasetConfig } from "@/components/chart/generic-chart";
import { getValueFromHistory } from "@/common/player-utils";
import ScoreSaberPlayer from "@ssr/common/player/impl/scoresaber-player";
import { parseDate } from "@ssr/common/utils/time-utils";
import { getValueFromHistory } from "@ssr/common/utils/player-utils";
type Props = {
/**