fixed playcount tabulation

This commit is contained in:
Polaris
2024-08-25 00:08:45 -04:00
parent 7fa261669c
commit 7226a2c9e0
2 changed files with 18 additions and 66 deletions

View File

@ -6,7 +6,6 @@ import type * as Prisma from "@prisma/client";
type ChuniScorePlaylog = Prisma.PrismaClient;
type ChuniStaticMusic = Prisma.PrismaClient;
export async function getSongsWithTitles(userId: number) {
try {
const songs: ChuniScorePlaylog[] =
@ -82,36 +81,16 @@ export async function getSongsWithTitles(userId: number) {
},
});
const chuniScoreBest: chuni_score_best[] =
await artemis.chuni_score_best.findMany({
where: {
musicId: {
in: chuniScorePlaylogMusicId,
},
},
select: {
id: true,
user: true,
musicId: true,
level: true,
playCount: true,
scoreMax: true,
resRequestCount: true,
resAcceptCount: true,
resSuccessCount: true,
missCount: true,
maxComboCount: true,
isFullCombo: true,
isAllJustice: true,
isSuccess: true,
fullChain: true,
maxChain: true,
scoreRank: true,
isLock: true,
ext1: true,
theoryCount: true,
},
});
const playCounts = await artemis.chuni_score_playlog.groupBy({
by: ["musicId", "level"],
where: {
musicId: { in: chuniScorePlaylogMusicId },
user: userId,
},
_count: {
_all: true,
},
});
const songsWithTitles = songs.map((song) => {
const staticInfo = staticMusicInfo.find(
@ -120,9 +99,10 @@ export async function getSongsWithTitles(userId: number) {
chuniStaticMusic.chartId === song.level,
);
const bestScore = chuniScoreBest.find(
(score) => score.musicId === song.musicId,
);
const playCount =
playCounts.find(
(play) => play.musicId === song.musicId && play.level === song.level,
)?._count._all || 0;
return {
...song,
@ -132,8 +112,7 @@ export async function getSongsWithTitles(userId: number) {
chartId: staticInfo?.chartId || "Unknown chartId",
level: staticInfo?.level || "Unknown Level",
chartlevel: song.level || "Unknown Level",
playCount: bestScore?.playCount || 0,
isSuccess: bestScore?.isSuccess || 0,
playCount,
jacketPath: staticInfo?.jacketPath || "",
};
});