From d0f8568e172a14b98f5b3cff5191bf88fa62f6bc Mon Sep 17 00:00:00 2001 From: EmmyHeart Date: Wed, 13 Dec 2023 23:28:00 +0000 Subject: [PATCH] Fixed Rival Music API not returning everything due to iteration issues --- titles/chuni/base.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/titles/chuni/base.py b/titles/chuni/base.py index 43cad83..674fb9c 100644 --- a/titles/chuni/base.py +++ b/titles/chuni/base.py @@ -419,13 +419,13 @@ class ChuniBase: all_entries = self.data.score.get_rival_music(rival_id) # Process the entries based on max_count and nextIndex - for music in all_entries[next_index:]: + for music in all_entries: music_id = music["musicId"] level = music["level"] score = music["scoreMax"] rank = music["scoreRank"] - # Create a music entry for the current music_id + # Create a music entry for the current music_id if it's unique music_entry = next((entry for entry in user_rival_music_list if entry["musicId"] == music_id), None) if music_entry is None: music_entry = { @@ -435,15 +435,20 @@ class ChuniBase: } user_rival_music_list.append(music_entry) - # Create a level entry for the current level - level_entry = { - "level": level, - "scoreMax": score, - "scoreRank": rank - } - music_entry["userRivalMusicDetailList"].append(level_entry) + # Create a level entry for the current level if it's unique or has a higher score + level_entry = next((entry for entry in music_entry["userRivalMusicDetailList"] if entry["level"] == level), None) + if level_entry is None: + level_entry = { + "level": level, + "scoreMax": score, + "scoreRank": rank + } + music_entry["userRivalMusicDetailList"].append(level_entry) + elif score > level_entry["scoreMax"]: + level_entry["scoreMax"] = score + level_entry["scoreRank"] = rank - # Calculate the length for each "musicId" by counting the levels + # Calculate the length for each "musicId" by counting the unique levels for music_entry in user_rival_music_list: music_entry["length"] = len(music_entry["userRivalMusicDetailList"]) @@ -451,11 +456,11 @@ class ChuniBase: result = { "userId": data["userId"], "rivalId": data["rivalId"], - "nextIndex": str(next_index + len(all_entries) if len(all_entries) <= len(user_rival_music_list) else -1), - "userRivalMusicList": user_rival_music_list[:max_count] + "nextIndex": str(next_index + len(user_rival_music_list[next_index: next_index + max_count]) if max_count <= len(user_rival_music_list[next_index: next_index + max_count]) else -1), + "userRivalMusicList": user_rival_music_list[next_index: next_index + max_count] } - return result + def handle_get_user_favorite_item_api_request(self, data: Dict) -> Dict: user_fav_item_list = []