From c78a62de14c7e65abb06845cf07fef5b51e6ebc9 Mon Sep 17 00:00:00 2001 From: EmmyHeart Date: Mon, 16 Oct 2023 13:09:11 +0000 Subject: [PATCH] Fixed Rival Music retrieval --- titles/chuni/schema/score.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/titles/chuni/schema/score.py b/titles/chuni/schema/score.py index ab26f5f..c31f560 100644 --- a/titles/chuni/schema/score.py +++ b/titles/chuni/schema/score.py @@ -201,9 +201,33 @@ class ChuniScoreData(BaseData): return None return result.lastrowid - def get_rival_music(self, rival_id: int, index: int, max_count: int) -> Optional[List[Dict]]: - sql = select(playlog).where(playlog.c.user == rival_id).limit(max_count).offset(index) + def get_rival_music(self, rival_id: int) -> Optional[List[Dict]]: + sql = select(playlog).where(playlog.c.user == rival_id) result = self.execute(sql) if result is None: return None - return result.fetchall() \ No newline at end of file + return result.fetchall() + def get_rival_music_highest_scores(self, rival_id: int) -> Optional[List[Dict]]: + # Define the subquery to retrieve the highest scoreMax for each level and musicId + subquery = ( + select([ + self.playlog.c.musicId, + self.playlog.c.level, + func.max(self.playlog.c.score) + ]) + .where(self.playlog.c.user == rival_id) + .group_by(self.playlog.c.musicId, self.playlog.c.level) + ) + + # Join the subquery with the playlog table to get the full records + query = select([ + self.playlog, + subquery.scalar() + ]).where(self.playlog.c.user == rival_id) + + result = self.execute(query) + + if result is None: + return None + + return result.fetchall()