From 6d1c911c9f210c501fdcb185b4235a9f31a98bc0 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 12 Oct 2024 22:07:32 +0100 Subject: [PATCH] fix rank graph --- projects/common/src/service/impl/beatsaver.ts | 1 - .../player/chart/generic-player-chart.tsx | 44 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/projects/common/src/service/impl/beatsaver.ts b/projects/common/src/service/impl/beatsaver.ts index 41548c8..f93f371 100644 --- a/projects/common/src/service/impl/beatsaver.ts +++ b/projects/common/src/service/impl/beatsaver.ts @@ -13,7 +13,6 @@ class BeatSaverService extends Service { * Gets the map that match the query. * * @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 */ async lookupMap(query: string): Promise { diff --git a/projects/website/src/components/player/chart/generic-player-chart.tsx b/projects/website/src/components/player/chart/generic-player-chart.tsx index a0f4dcb..3ac22ce 100644 --- a/projects/website/src/components/player/chart/generic-player-chart.tsx +++ b/projects/website/src/components/player/chart/generic-player-chart.tsx @@ -40,9 +40,8 @@ export default function GenericPlayerChart({ player, datasetConfig }: Props) { ); } - const histories: Record = {}; - // Initialize histories for each dataset + const histories: Record = {}; datasetConfig.forEach(config => { histories[config.field] = []; }); @@ -52,30 +51,39 @@ export default function GenericPlayerChart({ player, datasetConfig }: Props) { ([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 - for (const [dateString, history] of statisticEntries) { - const currentDate = parseDate(dateString); + // Iterate from 50 days ago to today + for (let dayAgo = historyDays - 1; dayAgo >= 0; dayAgo--) { + const targetDate = new Date(); + targetDate.setDate(today.getDate() - dayAgo); - // Fill in missing days with null values - if (previousDate) { - const diffDays = Math.floor((currentDate.getTime() - previousDate.getTime()) / (1000 * 60 * 60 * 24)); - for (let i = 1; i < diffDays; i++) { + // Check if there is a statistic entry that matches this date + let matchedEntry = false; + + 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(null); + histories[config.field].push(getValueFromHistory(history, config.field) ?? null); }); + currentHistoryIndex++; + matchedEntry = true; } } - // Push the historical data to histories - datasetConfig.forEach(config => { - histories[config.field].push(getValueFromHistory(history, config.field) ?? null); - }); - - previousDate = currentDate; // Update the previousDate for the next iteration + // If no matching entry, fill the current day with null + if (!matchedEntry) { + datasetConfig.forEach(config => { + histories[config.field].push(null); + }); + } } - // Render the GenericChart with collected data + // Render the chart with collected data return ; }