This commit is contained in:
parent
5e3d8acbeb
commit
44bb22c2fe
@ -1,9 +1,10 @@
|
|||||||
import AnalyticsChart from "@/components/AnalyticsChart";
|
import AnalyticsChart from "@/components/AnalyticsChart";
|
||||||
import Card from "@/components/Card";
|
import Card from "@/components/Card";
|
||||||
import Container from "@/components/Container";
|
import Container from "@/components/Container";
|
||||||
import { ScoresaberPlayerCountHistory } from "@/schemas/fascinated/scoresaberPlayerCountHistory";
|
import { ScoresaberMetricsHistory } from "@/schemas/fascinated/scoresaberMetricsHistory";
|
||||||
import { ssrSettings } from "@/ssrSettings";
|
import { ssrSettings } from "@/ssrSettings";
|
||||||
import { formatNumber } from "@/utils/number";
|
import { formatNumber } from "@/utils/number";
|
||||||
|
import { isProduction } from "@/utils/utils";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
|
||||||
async function getData() {
|
async function getData() {
|
||||||
@ -11,21 +12,29 @@ async function getData() {
|
|||||||
"https://bs-tracker.fascinated.cc/analytics?time=30d",
|
"https://bs-tracker.fascinated.cc/analytics?time=30d",
|
||||||
{
|
{
|
||||||
next: {
|
next: {
|
||||||
revalidate: 600, // 10 minutes
|
revalidate: isProduction() ? 600 : 0, // 10 minutes (0 seconds in dev)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
return json as ScoresaberPlayerCountHistory;
|
return json as ScoresaberMetricsHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateMetadata(): Promise<Metadata> {
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
const data = await getData();
|
const historyData = await getData();
|
||||||
|
|
||||||
const description =
|
const description =
|
||||||
"View Scoresaber metrics and statistics over the last 30 days.";
|
"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 {
|
return {
|
||||||
title: `Analytics`,
|
title: `Analytics`,
|
||||||
description: description,
|
description: description,
|
||||||
@ -35,15 +44,14 @@ export async function generateMetadata(): Promise<Metadata> {
|
|||||||
description:
|
description:
|
||||||
description +
|
description +
|
||||||
`
|
`
|
||||||
Players currently online: ${formatNumber(
|
Players currently online: ${formatNumber(lastActivePlayers)}
|
||||||
data.history[data.history.length - 1].value,
|
Scores set: ${formatNumber(lastScoreCount)}`,
|
||||||
)}`,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function Analytics() {
|
export default async function Analytics() {
|
||||||
const playerCountHistory = await getData();
|
const historyData = await getData();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
@ -57,7 +65,7 @@ export default async function Analytics() {
|
|||||||
Scoresaber metrics and statistics over the last 30 days.
|
Scoresaber metrics and statistics over the last 30 days.
|
||||||
</p>
|
</p>
|
||||||
<div className="mt-3 h-[400px] w-full">
|
<div className="mt-3 h-[400px] w-full">
|
||||||
<AnalyticsChart playerCountHistoryData={playerCountHistory} />
|
<AnalyticsChart historyData={historyData} />
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { ScoresaberPlayerCountHistory } from "@/schemas/fascinated/scoresaberPlayerCountHistory";
|
import { ScoresaberMetricsHistory } from "@/schemas/fascinated/scoresaberMetricsHistory";
|
||||||
import { formatTimeAgo } from "@/utils/timeUtils";
|
import { formatTimeAgo } from "@/utils/timeUtils";
|
||||||
import {
|
import {
|
||||||
CategoryScale,
|
CategoryScale,
|
||||||
@ -26,7 +26,7 @@ ChartJS.register(
|
|||||||
|
|
||||||
type PlayerChartProps = {
|
type PlayerChartProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
playerCountHistoryData: ScoresaberPlayerCountHistory;
|
historyData: ScoresaberMetricsHistory;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const options: any = {
|
export const options: any = {
|
||||||
@ -65,32 +65,20 @@ export const options: any = {
|
|||||||
title: {
|
title: {
|
||||||
display: false,
|
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({
|
export default function AnalyticsChart({
|
||||||
className,
|
className,
|
||||||
playerCountHistoryData,
|
historyData,
|
||||||
}: PlayerChartProps) {
|
}: PlayerChartProps) {
|
||||||
const playerCountHistory = playerCountHistoryData.history;
|
const playerCountHistory = historyData.activePlayersHistory;
|
||||||
|
const scoreCountHistory = historyData.scoreCountHistory;
|
||||||
|
|
||||||
let labels = [];
|
let labels = [];
|
||||||
for (let i = 0; i < playerCountHistory.length; i++) {
|
for (let i = 0; i < playerCountHistory.length; i++) {
|
||||||
if (i == playerCountHistory.length - 1) {
|
if (i == playerCountHistory.length - 1) {
|
||||||
labels.push("now");
|
labels.push("today");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
labels.push(formatTimeAgo(playerCountHistory[i].time));
|
labels.push(formatTimeAgo(playerCountHistory[i].time));
|
||||||
@ -107,6 +95,14 @@ export default function AnalyticsChart({
|
|||||||
fill: false,
|
fill: false,
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
lineTension: 0.5,
|
||||||
|
data: scoreCountHistory.map((count) => count.value || "0"),
|
||||||
|
label: "Scores Set",
|
||||||
|
borderColor: "#8e5ea2",
|
||||||
|
fill: false,
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
11
src/schemas/fascinated/scoresaberMetricsHistory.ts
Normal file
11
src/schemas/fascinated/scoresaberMetricsHistory.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export type ScoresaberMetricsHistory = {
|
||||||
|
serverTimeTaken: number;
|
||||||
|
activePlayersHistory: {
|
||||||
|
time: string;
|
||||||
|
value: number | null;
|
||||||
|
}[];
|
||||||
|
scoreCountHistory: {
|
||||||
|
time: string;
|
||||||
|
value: number | null;
|
||||||
|
}[];
|
||||||
|
};
|
@ -1,7 +0,0 @@
|
|||||||
export type ScoresaberPlayerCountHistory = {
|
|
||||||
serverTimeTaken: number;
|
|
||||||
history: {
|
|
||||||
time: string;
|
|
||||||
value: number | null;
|
|
||||||
}[];
|
|
||||||
};
|
|
@ -1,5 +1,4 @@
|
|||||||
export function songDifficultyToColor(diff: string) {
|
export function songDifficultyToColor(diff: string) {
|
||||||
console.log(diff);
|
|
||||||
switch (diff.toLowerCase()) {
|
switch (diff.toLowerCase()) {
|
||||||
case "easy":
|
case "easy":
|
||||||
return "#3cb371";
|
return "#3cb371";
|
||||||
|
Loading…
Reference in New Issue
Block a user