diff --git a/src/app/analytics/page.tsx b/src/app/analytics/page.tsx index 688a474..ebcd4ff 100644 --- a/src/app/analytics/page.tsx +++ b/src/app/analytics/page.tsx @@ -1,9 +1,10 @@ import AnalyticsChart from "@/components/AnalyticsChart"; import Card from "@/components/Card"; import Container from "@/components/Container"; -import { ScoresaberPlayerCountHistory } from "@/schemas/fascinated/scoresaberPlayerCountHistory"; +import { ScoresaberMetricsHistory } from "@/schemas/fascinated/scoresaberMetricsHistory"; import { ssrSettings } from "@/ssrSettings"; import { formatNumber } from "@/utils/number"; +import { isProduction } from "@/utils/utils"; import { Metadata } from "next"; async function getData() { @@ -11,21 +12,29 @@ async function getData() { "https://bs-tracker.fascinated.cc/analytics?time=30d", { next: { - revalidate: 600, // 10 minutes + revalidate: isProduction() ? 600 : 0, // 10 minutes (0 seconds in dev) }, }, ); const json = await response.json(); - return json as ScoresaberPlayerCountHistory; + return json as ScoresaberMetricsHistory; } export async function generateMetadata(): Promise { - const data = await getData(); + const historyData = await getData(); const description = "View Scoresaber metrics and statistics over the last 30 days."; + const lastActivePlayers = + historyData.activePlayersHistory[ + historyData.activePlayersHistory.length - 1 + ].value; + const lastScoreCount = + historyData.scoreCountHistory[historyData.scoreCountHistory.length - 1] + .value; + return { title: `Analytics`, description: description, @@ -35,15 +44,14 @@ export async function generateMetadata(): Promise { description: description + ` - Players currently online: ${formatNumber( - data.history[data.history.length - 1].value, - )}`, + Players currently online: ${formatNumber(lastActivePlayers)} + Scores set: ${formatNumber(lastScoreCount)}`, }, }; } export default async function Analytics() { - const playerCountHistory = await getData(); + const historyData = await getData(); return (
@@ -57,7 +65,7 @@ export default async function Analytics() { Scoresaber metrics and statistics over the last 30 days.

- +
diff --git a/src/components/AnalyticsChart.tsx b/src/components/AnalyticsChart.tsx index d6943ec..967f100 100644 --- a/src/components/AnalyticsChart.tsx +++ b/src/components/AnalyticsChart.tsx @@ -1,6 +1,6 @@ "use client"; -import { ScoresaberPlayerCountHistory } from "@/schemas/fascinated/scoresaberPlayerCountHistory"; +import { ScoresaberMetricsHistory } from "@/schemas/fascinated/scoresaberMetricsHistory"; import { formatTimeAgo } from "@/utils/timeUtils"; import { CategoryScale, @@ -26,7 +26,7 @@ ChartJS.register( type PlayerChartProps = { className?: string; - playerCountHistoryData: ScoresaberPlayerCountHistory; + historyData: ScoresaberMetricsHistory; }; export const options: any = { @@ -65,32 +65,20 @@ export const options: any = { title: { display: false, }, - tooltip: { - callbacks: { - label(context: any) { - switch ( - context.dataset.label - // case "Rank": { - // return `Rank #${formatNumber(context.parsed.y.toFixed(0))}`; - // } - ) { - } - }, - }, - }, }, }; export default function AnalyticsChart({ className, - playerCountHistoryData, + historyData, }: PlayerChartProps) { - const playerCountHistory = playerCountHistoryData.history; + const playerCountHistory = historyData.activePlayersHistory; + const scoreCountHistory = historyData.scoreCountHistory; let labels = []; for (let i = 0; i < playerCountHistory.length; i++) { if (i == playerCountHistory.length - 1) { - labels.push("now"); + labels.push("today"); continue; } labels.push(formatTimeAgo(playerCountHistory[i].time)); @@ -107,6 +95,14 @@ export default function AnalyticsChart({ fill: false, color: "#fff", }, + { + lineTension: 0.5, + data: scoreCountHistory.map((count) => count.value || "0"), + label: "Scores Set", + borderColor: "#8e5ea2", + fill: false, + color: "#fff", + }, ], }; diff --git a/src/schemas/fascinated/scoresaberMetricsHistory.ts b/src/schemas/fascinated/scoresaberMetricsHistory.ts new file mode 100644 index 0000000..bca6656 --- /dev/null +++ b/src/schemas/fascinated/scoresaberMetricsHistory.ts @@ -0,0 +1,11 @@ +export type ScoresaberMetricsHistory = { + serverTimeTaken: number; + activePlayersHistory: { + time: string; + value: number | null; + }[]; + scoreCountHistory: { + time: string; + value: number | null; + }[]; +}; diff --git a/src/schemas/fascinated/scoresaberPlayerCountHistory.ts b/src/schemas/fascinated/scoresaberPlayerCountHistory.ts deleted file mode 100644 index 0cded69..0000000 --- a/src/schemas/fascinated/scoresaberPlayerCountHistory.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type ScoresaberPlayerCountHistory = { - serverTimeTaken: number; - history: { - time: string; - value: number | null; - }[]; -}; diff --git a/src/utils/songUtils.ts b/src/utils/songUtils.ts index 9aba8bc..74b7927 100644 --- a/src/utils/songUtils.ts +++ b/src/utils/songUtils.ts @@ -1,5 +1,4 @@ export function songDifficultyToColor(diff: string) { - console.log(diff); switch (diff.toLowerCase()) { case "easy": return "#3cb371";