add scores set
All checks were successful
deploy / deploy (push) Successful in 53s

This commit is contained in:
Lee 2023-10-27 18:33:07 +01:00
parent 5e3d8acbeb
commit 44bb22c2fe
5 changed files with 42 additions and 35 deletions

@ -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<Metadata> {
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<Metadata> {
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 (
<main>
@ -57,7 +65,7 @@ export default async function Analytics() {
Scoresaber metrics and statistics over the last 30 days.
</p>
<div className="mt-3 h-[400px] w-full">
<AnalyticsChart playerCountHistoryData={playerCountHistory} />
<AnalyticsChart historyData={historyData} />
</div>
</Card>
</Container>

@ -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",
},
],
};

@ -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) {
console.log(diff);
switch (diff.toLowerCase()) {
case "easy":
return "#3cb371";