forked from PolarisPyra/daphnis
added top and hot plays
This commit is contained in:
parent
caa987121c
commit
0ef5305fda
@ -13,12 +13,19 @@ import { getSystemVoices } from "@/components/(customization)/systemvoicecustomi
|
||||
import { SystemVoiceCustomization } from "@/components/(customization)/systemvoicecustomization/page";
|
||||
import { MapIconCustomization } from "@/components/(customization)/mapiconcustomization/page";
|
||||
import { getMapIcons } from "@/components/(customization)/mapiconcustomization/actions";
|
||||
import { ChunithmRecentPlays } from "@/components/RecentChunithmScores/page";
|
||||
import { getUserRatingBaseList } from "@/components/RecentChunithmScores/action";
|
||||
import { getUserRatingBaseList } from "@/components/userRatingBase/action";
|
||||
import { ChunithmHotPlays } from "@/components/userRatingBaseHotList/page";
|
||||
import { getUserRatingBaseHotList } from "@/components/userRatingBaseHotList/action";
|
||||
import { ChunithmTopPlays } from "@/components/userRatingBase/page";
|
||||
|
||||
const getChuniRecent = async () => {
|
||||
const recentRating = await getUserRatingBaseList();
|
||||
return { recentRating };
|
||||
const getChuniTopPlays = async () => {
|
||||
const topPlays = await getUserRatingBaseList();
|
||||
return { topPlays };
|
||||
};
|
||||
|
||||
const getChuniHotPlays = async () => {
|
||||
const hotRating = await getUserRatingBaseHotList();
|
||||
return { hotRating };
|
||||
};
|
||||
|
||||
const getAvatarHeadAccessories = async () => {
|
||||
@ -77,7 +84,8 @@ const Page = async () => {
|
||||
const AllSystemVoices = await getAllSystemVoices();
|
||||
const AllMapIcons = await getAllMapIcons();
|
||||
|
||||
const RecentChuniPlays = await getChuniRecent();
|
||||
const TopChuniPlays = await getChuniTopPlays();
|
||||
const HotChuniPlays = await getChuniHotPlays();
|
||||
|
||||
return (
|
||||
<div className="p-10">
|
||||
@ -86,7 +94,7 @@ const Page = async () => {
|
||||
<TabsTrigger value="scores">Scores</TabsTrigger>
|
||||
<TabsTrigger value="customize">Customize</TabsTrigger>
|
||||
<TabsTrigger value="TopPlays">Top Plays</TabsTrigger>
|
||||
<TabsTrigger value="RecentPlays">Recent Plays</TabsTrigger>
|
||||
<TabsTrigger value="HotPlays">Hot Plays</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="scores">
|
||||
<ChunithmScorePlaylog />
|
||||
@ -122,7 +130,10 @@ const Page = async () => {
|
||||
<div></div>
|
||||
</TabsContent>
|
||||
<TabsContent value="TopPlays">
|
||||
<ChunithmRecentPlays chuniProfileRecentPlays={RecentChuniPlays} />
|
||||
<ChunithmTopPlays chuniProfileTopPlays={TopChuniPlays} />
|
||||
</TabsContent>
|
||||
<TabsContent value="HotPlays">
|
||||
<ChunithmHotPlays chuniProfileHotPlays={HotChuniPlays} />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
@ -20,19 +20,18 @@ type userRatingBaseList = {
|
||||
score: number | null;
|
||||
};
|
||||
|
||||
type ChunithmProfileRecentPlays = {
|
||||
chuniProfileRecentPlays: {
|
||||
recentRating: userRatingBaseList[];
|
||||
type chunithmTopPlays = {
|
||||
chuniProfileTopPlays: {
|
||||
topPlays: userRatingBaseList[];
|
||||
};
|
||||
};
|
||||
export const ChunithmRecentPlays: FC<ChunithmProfileRecentPlays> = ({
|
||||
chuniProfileRecentPlays,
|
||||
export const ChunithmTopPlays: FC<chunithmTopPlays> = ({
|
||||
chuniProfileTopPlays,
|
||||
}) => {
|
||||
return (
|
||||
<div>
|
||||
{chuniProfileRecentPlays.recentRating.map(
|
||||
(playersRecentRatingList, index) => {
|
||||
const jacketPath = playersRecentRatingList.jacketPath?.replace(
|
||||
{chuniProfileTopPlays.topPlays.map((chuniProfileTopPlays, index) => {
|
||||
const jacketPath = chuniProfileTopPlays.jacketPath?.replace(
|
||||
".dds",
|
||||
".png",
|
||||
);
|
||||
@ -49,29 +48,28 @@ export const ChunithmRecentPlays: FC<ChunithmProfileRecentPlays> = ({
|
||||
<div>
|
||||
<ul className="pl-2">
|
||||
<li>
|
||||
<strong>Title: </strong> {playersRecentRatingList.title}
|
||||
<strong>Title: </strong> {chuniProfileTopPlays.title}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Level: </strong> {playersRecentRatingList.level}
|
||||
<strong>Level: </strong> {chuniProfileTopPlays.level}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Difficulty: </strong>
|
||||
{getDifficultyText(Number(playersRecentRatingList.chartId))}
|
||||
{getDifficultyText(Number(chuniProfileTopPlays.chartId))}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Score: </strong>{" "}
|
||||
{playersRecentRatingList.score?.toLocaleString()}
|
||||
{chuniProfileTopPlays.score?.toLocaleString()}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Rating: </strong>{" "}
|
||||
{(playersRecentRatingList.rating / 100).toFixed(2)}
|
||||
{(chuniProfileTopPlays.rating / 100).toFixed(2)}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
)}
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
121
components/userRatingBaseHotList/action.ts
Normal file
121
components/userRatingBaseHotList/action.ts
Normal file
@ -0,0 +1,121 @@
|
||||
"use server";
|
||||
import { getAuth } from "@/auth/queries/getauth";
|
||||
import { supportedVersionNumber } from "@/lib/helpers";
|
||||
import { artemis } from "@/lib/prisma";
|
||||
|
||||
export async function getUserRatingBaseHotList() {
|
||||
const { user } = await getAuth();
|
||||
|
||||
if (!user || !user.accessCode) {
|
||||
throw new Error("User is not authenticated or accessCode is missing");
|
||||
}
|
||||
|
||||
try {
|
||||
const userRatingBaseList = await artemis.chuni_profile_rating.findMany({
|
||||
where: {
|
||||
user: user.UserId,
|
||||
type: "userRatingBaseHotList",
|
||||
version: supportedVersionNumber,
|
||||
},
|
||||
select: {
|
||||
musicId: true,
|
||||
score: true,
|
||||
difficultId: true,
|
||||
version: true,
|
||||
index: true,
|
||||
},
|
||||
orderBy: {
|
||||
index: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
const staticMusicInfo = await artemis.chuni_static_music.findMany({
|
||||
where: {
|
||||
songId: {
|
||||
in: userRatingBaseList.map((entry) => entry.musicId!),
|
||||
},
|
||||
version: supportedVersionNumber,
|
||||
},
|
||||
select: {
|
||||
songId: true,
|
||||
title: true,
|
||||
artist: true,
|
||||
chartId: true,
|
||||
level: true,
|
||||
genre: true,
|
||||
jacketPath: true,
|
||||
},
|
||||
});
|
||||
|
||||
// chartId is the difficutly i.e
|
||||
// easy, hard, expert, master, ultima, worlds end
|
||||
|
||||
// msuicId is the id of the specific song in the rating table
|
||||
// we are mapping that to songId in chuni static music
|
||||
// so we can get name and jacket path etc
|
||||
// then we are mapping the difficultId to the chartId to get the proper difficutly from above
|
||||
// this is very confusing and my brain hurts
|
||||
// if someone could make this cleaner id highly appreciate it
|
||||
|
||||
// Create a map
|
||||
const songIdtoChartId = new Map<string, (typeof staticMusicInfo)[0]>(
|
||||
staticMusicInfo.map((music) => [
|
||||
`${music.songId}-${music.chartId}`,
|
||||
music,
|
||||
]),
|
||||
);
|
||||
|
||||
const musicIdToDifficltId = userRatingBaseList.map((rating) => {
|
||||
const staticMusic = songIdtoChartId.get(
|
||||
`${rating.musicId}-${rating.difficultId}`,
|
||||
);
|
||||
|
||||
const level = staticMusic?.level ?? 0;
|
||||
const score = rating.score ?? 0;
|
||||
|
||||
const perSongRating = calculateRating(level, score);
|
||||
|
||||
return {
|
||||
...rating,
|
||||
chartId: staticMusic?.chartId || "Unknown chartId",
|
||||
title: staticMusic?.title || "Unknown Title",
|
||||
artist: staticMusic?.artist || "Unknown Artist",
|
||||
genre: staticMusic?.genre || "Unknown Genre",
|
||||
level: staticMusic?.level || "Unknown Level",
|
||||
jacketPath: staticMusic?.jacketPath || "",
|
||||
rating: perSongRating,
|
||||
};
|
||||
});
|
||||
|
||||
return musicIdToDifficltId;
|
||||
} catch (error) {
|
||||
console.error("Error fetching songs with titles:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate the rating
|
||||
function calculateRating(level: number, score: number): number {
|
||||
if (score >= 1009000) {
|
||||
return level * 100 + 215;
|
||||
} else if (score >= 1007500) {
|
||||
return level * 100 + 200 + (score - 1007500) / 100;
|
||||
} else if (score >= 1005000) {
|
||||
return level * 100 + 150 + (score - 1005000) / 50;
|
||||
} else if (score >= 1000000) {
|
||||
return level * 100 + 100 + (score - 1000000) / 100;
|
||||
} else if (score >= 975000) {
|
||||
return level * 100 + (score - 975000) / 250;
|
||||
} else if (score >= 925000) {
|
||||
return level * 100 - 300 + ((score - 925000) * 3) / 500;
|
||||
} else if (score >= 900000) {
|
||||
return level * 100 - 500 + ((score - 900000) * 4) / 500;
|
||||
} else if (score >= 800000) {
|
||||
return (
|
||||
(level * 100 - 500) / 2 +
|
||||
((score - 800000) * ((level - 500) / 2)) / 100000
|
||||
);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
71
components/userRatingBaseHotList/page.tsx
Normal file
71
components/userRatingBaseHotList/page.tsx
Normal file
@ -0,0 +1,71 @@
|
||||
import React, { FC } from "react";
|
||||
import { getDifficultyText } from "@/lib/helpers";
|
||||
|
||||
type userRatingBaseList = {
|
||||
title: string;
|
||||
artist: string;
|
||||
genre: string;
|
||||
chartId: string | number;
|
||||
level: string | number;
|
||||
jacketPath: string;
|
||||
rating: number;
|
||||
version: number;
|
||||
index: number;
|
||||
musicId: number | null;
|
||||
difficultId: number | null;
|
||||
score: number | null;
|
||||
};
|
||||
|
||||
type ChunithmProfileHotPlays = {
|
||||
chuniProfileHotPlays: {
|
||||
hotRating: userRatingBaseList[];
|
||||
};
|
||||
};
|
||||
export const ChunithmHotPlays: FC<ChunithmProfileHotPlays> = ({
|
||||
chuniProfileHotPlays,
|
||||
}) => {
|
||||
return (
|
||||
<div>
|
||||
{chuniProfileHotPlays.hotRating.map((playerHotRatingList, index) => {
|
||||
const jacketPath = playerHotRatingList.jacketPath?.replace(
|
||||
".dds",
|
||||
".png",
|
||||
);
|
||||
return (
|
||||
<div key={index} className="center flex p-2">
|
||||
<div className="m-4 font-bold">{index + 1}.</div>
|
||||
{jacketPath && (
|
||||
<img
|
||||
src={`/JacketArt/${jacketPath}`}
|
||||
alt="Jacket"
|
||||
style={{ width: "120px", height: "120px" }}
|
||||
/>
|
||||
)}
|
||||
<div>
|
||||
<ul className="pl-2">
|
||||
<li>
|
||||
<strong>Title: </strong> {playerHotRatingList.title}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Level: </strong> {playerHotRatingList.level}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Difficulty: </strong>
|
||||
{getDifficultyText(Number(playerHotRatingList.chartId))}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Score: </strong>{" "}
|
||||
{playerHotRatingList.score?.toLocaleString()}
|
||||
</li>
|
||||
<li>
|
||||
<strong>Rating: </strong>{" "}
|
||||
{(playerHotRatingList.rating / 100).toFixed(2)}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
Loading…
Reference in New Issue
Block a user