diff --git a/app/(authenticated)/chunithm/page.tsx b/app/(authenticated)/chunithm/page.tsx
index 21b15b6..f1dfad6 100644
--- a/app/(authenticated)/chunithm/page.tsx
+++ b/app/(authenticated)/chunithm/page.tsx
@@ -85,7 +85,8 @@ const Page = async () => {
Scores
Customize
- Top / Recent Plays
+ Top Plays
+ Recent Plays
@@ -120,7 +121,7 @@ const Page = async () => {
-
+
diff --git a/components/RecentChunithmScores/action.ts b/components/RecentChunithmScores/action.ts
index e61674e..386badd 100644
--- a/components/RecentChunithmScores/action.ts
+++ b/components/RecentChunithmScores/action.ts
@@ -11,40 +11,88 @@ export async function getUserRatingBaseList() {
}
try {
- // fuck prisma sometimes man
- const results = await artemis.$queryRaw`
- SELECT
- cpr.score,
- csm.chartId,
- csm.title,
- csm.level,
- csm.genre,
- csm.jacketPath,
- csm.artist,
- 'Increase' AS rating_change,
- CASE
- WHEN cpr.score >= 1009000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 215
- WHEN cpr.score >= 1007500 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 200 + (cpr.score - 1007500) / 100
- WHEN cpr.score >= 1005000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 150 + (cpr.score - 1005000) / 50
- WHEN cpr.score >= 1000000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 100 + (cpr.score - 1000000) / 100
- WHEN cpr.score >= 975000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + (cpr.score - 975000) / 250
- WHEN cpr.score >= 925000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 - 300 + (cpr.score - 925000) * 3 / 500
- WHEN cpr.score >= 900000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 - 500 + (cpr.score - 900000) * 4 / 500
- WHEN cpr.score >= 800000 THEN ((CAST(csm.level AS DECIMAL(10,2)) * 100 - 500) / 2 + (cpr.score - 800000) * ((CAST(csm.level AS DECIMAL(10,2)) - 500) / 2) / 100000)
- ELSE 0
- END AS rating
- FROM
- chuni_profile_rating cpr
- JOIN
- chuni_static_music csm ON cpr.musicId = csm.songId AND cpr.difficultId = csm.chartId AND cpr.version = csm.version
- WHERE
- cpr.user = ${user.UserId} AND cpr.version = ${supportedVersionNumber} AND cpr.type = 'userRatingBaseList'
- ORDER BY
- cpr.index ASC
- `;
+ // Fetch data from Prisma
+ const userRatingBaseList = await artemis.chuni_profile_rating.findMany({
+ where: {
+ user: user.UserId,
+ type: "userRatingBaseList",
+ version: supportedVersionNumber,
+ },
+ select: {
+ musicId: true,
+ score: true,
+ difficultId: true,
+ romVersionCode: true,
+ version: true,
+ index: true,
+ },
+ });
- // Return results
- return results;
+ const baseListMusicIds = userRatingBaseList.map((entry) => entry.musicId!);
+
+ const staticMusicInfo = await artemis.chuni_static_music.findMany({
+ where: {
+ songId: {
+ in: baseListMusicIds,
+ },
+ },
+ select: {
+ songId: true,
+ title: true,
+ artist: true,
+ chartId: true,
+ level: true,
+ genre: true,
+ worldsEndTag: true,
+ jacketPath: true,
+ },
+ });
+
+ const staticMusic = new Map(
+ staticMusicInfo.map((info) => [info.songId, info]),
+ );
+
+ const songsWithTitles = userRatingBaseList.map((ratingListSong) => {
+ const staticInfo = staticMusic.get(ratingListSong.musicId);
+
+ const level = staticInfo?.level ?? 0;
+ const score = ratingListSong.score ?? 0;
+
+ // Calculate the rating
+ let rating = 0;
+ if (score >= 1009000) {
+ rating = level * 100 + 215;
+ } else if (score >= 1007500) {
+ rating = level * 100 + 200 + (score - 1007500) / 100;
+ } else if (score >= 1005000) {
+ rating = level * 100 + 150 + (score - 1005000) / 50;
+ } else if (score >= 1000000) {
+ rating = level * 100 + 100 + (score - 1000000) / 100;
+ } else if (score >= 975000) {
+ rating = level * 100 + (score - 975000) / 250;
+ } else if (score >= 925000) {
+ rating = level * 100 - 300 + ((score - 925000) * 3) / 500;
+ } else if (score >= 900000) {
+ rating = level * 100 - 500 + ((score - 900000) * 4) / 500;
+ } else if (score >= 800000) {
+ rating =
+ (level * 100 - 500) / 2 +
+ ((score - 800000) * ((level - 500) / 2)) / 100000;
+ }
+
+ return {
+ ...ratingListSong,
+ title: staticInfo?.title || "Unknown Title",
+ artist: staticInfo?.artist || "Unknown Artist",
+ genre: staticInfo?.genre || "Unknown Genre",
+ chartId: staticInfo?.chartId || "Unknown chartId",
+ level: staticInfo?.level || "Unknown Level",
+ jacketPath: staticInfo?.jacketPath || "",
+ rating,
+ };
+ });
+
+ return songsWithTitles;
} catch (error) {
console.error("Error fetching songs with titles:", error);
throw error;
diff --git a/components/RecentChunithmScores/page.tsx b/components/RecentChunithmScores/page.tsx
index c06da06..bdcd736 100644
--- a/components/RecentChunithmScores/page.tsx
+++ b/components/RecentChunithmScores/page.tsx
@@ -4,15 +4,27 @@ import {
chuni_static_music,
} from "@/prisma/schemas/artemis/generated/artemis";
-type ChunithmRecent = chuni_profile_rating &
- chuni_static_music & { rating: number; jacketPath: string | undefined };
+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;
+ romVersionCode: number | null;
+ score: number | null;
+};
type ChunithmProfileRecentPlays = {
chuniProfileRecentPlays: {
- recentRating: ChunithmRecent[];
+ recentRating: userRatingBaseList[];
};
};
-
export const ChunithmRecentPlays: FC = ({
chuniProfileRecentPlays,
}) => {