fix rank graph
All checks were successful
Deploy Backend / deploy (push) Successful in 3m8s
Deploy Website / deploy (push) Successful in 3m54s

This commit is contained in:
Lee 2024-10-12 22:07:32 +01:00
parent e2d9a23974
commit 6d1c911c9f
2 changed files with 26 additions and 19 deletions

@ -13,7 +13,6 @@ class BeatSaverService extends Service {
* Gets the map that match the query. * Gets the map that match the query.
* *
* @param query the query to search for * @param query the query to search for
* @param useProxy whether to use the proxy or not
* @returns the map that match the query, or undefined if no map were found * @returns the map that match the query, or undefined if no map were found
*/ */
async lookupMap(query: string): Promise<BeatSaverMapToken | undefined> { async lookupMap(query: string): Promise<BeatSaverMapToken | undefined> {

@ -40,9 +40,8 @@ export default function GenericPlayerChart({ player, datasetConfig }: Props) {
</div> </div>
); );
} }
const histories: Record<string, (number | null)[]> = {};
// Initialize histories for each dataset const histories: Record<string, (number | null)[]> = {};
datasetConfig.forEach(config => { datasetConfig.forEach(config => {
histories[config.field] = []; histories[config.field] = [];
}); });
@ -52,30 +51,39 @@ export default function GenericPlayerChart({ player, datasetConfig }: Props) {
([a], [b]) => parseDate(a).getTime() - parseDate(b).getTime() ([a], [b]) => parseDate(a).getTime() - parseDate(b).getTime()
); );
let previousDate: Date | null = null; const today = new Date();
let currentHistoryIndex = 0;
// Iterate through each statistic entry // Iterate from 50 days ago to today
for (const [dateString, history] of statisticEntries) { for (let dayAgo = historyDays - 1; dayAgo >= 0; dayAgo--) {
const currentDate = parseDate(dateString); const targetDate = new Date();
targetDate.setDate(today.getDate() - dayAgo);
// Fill in missing days with null values // Check if there is a statistic entry that matches this date
if (previousDate) { let matchedEntry = false;
const diffDays = Math.floor((currentDate.getTime() - previousDate.getTime()) / (1000 * 60 * 60 * 24));
for (let i = 1; i < diffDays; i++) { if (currentHistoryIndex < statisticEntries.length) {
const [dateString, history] = statisticEntries[currentHistoryIndex];
const entryDate = parseDate(dateString);
// If the current statistic entry matches the target date, use it
if (entryDate.toDateString() === targetDate.toDateString()) {
datasetConfig.forEach(config => {
histories[config.field].push(getValueFromHistory(history, config.field) ?? null);
});
currentHistoryIndex++;
matchedEntry = true;
}
}
// If no matching entry, fill the current day with null
if (!matchedEntry) {
datasetConfig.forEach(config => { datasetConfig.forEach(config => {
histories[config.field].push(null); histories[config.field].push(null);
}); });
} }
} }
// Push the historical data to histories // Render the chart with collected data
datasetConfig.forEach(config => {
histories[config.field].push(getValueFromHistory(history, config.field) ?? null);
});
previousDate = currentDate; // Update the previousDate for the next iteration
}
// Render the GenericChart with collected data
return <GenericChart labels={labels} datasetConfig={datasetConfig} histories={histories} />; return <GenericChart labels={labels} datasetConfig={datasetConfig} histories={histories} />;
} }