fix
This commit is contained in:
parent
06a13bedc8
commit
81640c3c4e
@ -5,7 +5,7 @@ import ScoreSaberPlayerToken from "../../types/token/scoresaber/score-saber-play
|
|||||||
import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../utils/time-utils";
|
import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../utils/time-utils";
|
||||||
import { getPageFromRank } from "../../utils/utils";
|
import { getPageFromRank } from "../../utils/utils";
|
||||||
import { Config } from "../../config";
|
import { Config } from "../../config";
|
||||||
import { getValueFromHistory } from "website/src/common/player-utils";
|
import { getValueFromHistory } from "../../utils/player-utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ScoreSaber player.
|
* A ScoreSaber player.
|
||||||
|
@ -17,6 +17,31 @@ export function getPlayerHistoryToday(player: ScoreSaberPlayer) {
|
|||||||
return player.statisticHistory[formatDateMinimal(today)] || {};
|
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,
|
* Sorts the player history based on date,
|
||||||
* so the most recent date is first
|
* 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 React from "react";
|
||||||
import GenericChart, { DatasetConfig } from "@/components/chart/generic-chart";
|
import GenericChart, { DatasetConfig } from "@/components/chart/generic-chart";
|
||||||
import { getValueFromHistory } from "@/common/player-utils";
|
|
||||||
import ScoreSaberPlayer from "@ssr/common/player/impl/scoresaber-player";
|
import ScoreSaberPlayer from "@ssr/common/player/impl/scoresaber-player";
|
||||||
import { parseDate } from "@ssr/common/utils/time-utils";
|
import { parseDate } from "@ssr/common/utils/time-utils";
|
||||||
|
import { getValueFromHistory } from "@ssr/common/utils/player-utils";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user