From bd5a1a2990be13d7591775677a751a18e0020ddf Mon Sep 17 00:00:00 2001 From: Polaris Date: Wed, 14 Aug 2024 22:27:17 -0400 Subject: [PATCH] finished top 30 --- app/(authenticated)/chunithm/page.tsx | 12 ++--- app/page.tsx | 2 +- components/RecentChunithmScores/action.ts | 63 ++++++++++++++-------- components/RecentChunithmScores/page.tsx | 65 +++++++++++++++++++---- 4 files changed, 99 insertions(+), 43 deletions(-) diff --git a/app/(authenticated)/chunithm/page.tsx b/app/(authenticated)/chunithm/page.tsx index f6333a2..21b15b6 100644 --- a/app/(authenticated)/chunithm/page.tsx +++ b/app/(authenticated)/chunithm/page.tsx @@ -14,16 +14,13 @@ import { SystemVoiceCustomization } from "@/components/(customization)/systemvoi import { MapIconCustomization } from "@/components/(customization)/mapiconcustomization/page"; import { getMapIcons } from "@/components/(customization)/mapiconcustomization/actions"; import { ChunithmRecentPlays } from "@/components/RecentChunithmScores/page"; -import { getUserRecentPlays } from "@/components/RecentChunithmScores/action"; - +import { getUserRatingBaseList } from "@/components/RecentChunithmScores/action"; const getChuniRecent = async () => { - const recentRating = await getUserRecentPlays(); + const recentRating = await getUserRatingBaseList(); return { recentRating }; }; - - const getAvatarHeadAccessories = async () => { const avatarParts = await getAllAvatarParts(2); // head return { avatarParts }; @@ -79,8 +76,8 @@ const Page = async () => { const AllStaticNameplates = await getAllNameplates(); const AllSystemVoices = await getAllSystemVoices(); const AllMapIcons = await getAllMapIcons(); - const RecentChuniPlays = await getChuniRecent(); + const RecentChuniPlays = await getChuniRecent(); return (
@@ -89,7 +86,6 @@ const Page = async () => { Scores Customize Top / Recent Plays - @@ -125,7 +121,7 @@ const Page = async () => {
- +
diff --git a/app/page.tsx b/app/page.tsx index 336517a..70420e5 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -2,7 +2,7 @@ import { SignInForm } from "@/auth/components/signin/signin"; const PublicHomePage = () => { return ( -
+
); diff --git a/components/RecentChunithmScores/action.ts b/components/RecentChunithmScores/action.ts index e79916e..e61674e 100644 --- a/components/RecentChunithmScores/action.ts +++ b/components/RecentChunithmScores/action.ts @@ -1,35 +1,52 @@ "use server"; - import { getAuth } from "@/auth/queries/getauth"; import { supportedVersionNumber } from "@/lib/helpers"; import { artemis } from "@/lib/prisma"; -export async function getUserRecentPlays() { +export async function getUserRatingBaseList() { const { user } = await getAuth(); if (!user || !user.accessCode) { throw new Error("User is not authenticated or accessCode is missing"); } - const userRatingBaseHotList = await artemis.chuni_profile_rating.findMany({ - where: { - user: user.UserId, - // userRatingBaseList recent 30 // userRatingBaseHotList recent 15 - type: "userRatingBaseList", - version: supportedVersionNumber, // TODO: eventually change this so the user can set their own version - }, - select: { - score:true, - difficultId: true, - musicId: true, - type:true, - version: true, - romVersionCode: true, - id: true, - index:true, - user: true, + 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 + `; - }, - }); - return userRatingBaseHotList; -} \ No newline at end of file + // Return results + return results; + } 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 a240bf7..57c0b07 100644 --- a/components/RecentChunithmScores/page.tsx +++ b/components/RecentChunithmScores/page.tsx @@ -1,23 +1,66 @@ -import { chuni_profile_rating, chuni_profile_recent_rating } from '@/prisma/schemas/artemis/generated/artemis'; -import React, { FC } from 'react'; +import React, { FC } from "react"; +import { + chuni_profile_rating, + chuni_static_music, +} from "@/prisma/schemas/artemis/generated/artemis"; -type chunithm_recent = chuni_profile_rating +type ChunithmRecent = chuni_profile_rating & + chuni_static_music & { rating: number; jacketPath: string | undefined }; type ChunithmProfileRecentPlays = { chuniProfileRecentPlays: { - recentRating: chunithm_recent[]; + recentRating: ChunithmRecent[]; }; }; -export const ChunithmRecentPlays: FC = ({ chuniProfileRecentPlays }) => { +export const ChunithmRecentPlays: FC = ({ + chuniProfileRecentPlays, +}) => { return (
- {chuniProfileRecentPlays.recentRating.map((playersRecentRatingList, index) => ( -
- {playersRecentRatingList.score} - -
- ))} + {chuniProfileRecentPlays.recentRating.map( + (playersRecentRatingList, index) => { + const jacketPath = playersRecentRatingList.jacketPath?.replace( + ".dds", + ".png", + ); + + return ( +
+
{index + 1}.
+ {jacketPath && ( + Jacket + )} +
+
    +
  • + Title: {playersRecentRatingList.title} +
  • +
  • + Score:{" "} + {playersRecentRatingList.score?.toLocaleString()} +
  • +
  • + Rating:{" "} + {(playersRecentRatingList.rating / 100).toFixed(2)} +
  • +
+
+
+ ); + }, + )}
); };