Fixed Rival Music API not returning everything due to iteration issues

This commit is contained in:
EmmyHeart 2023-12-13 23:28:00 +00:00
parent fd0fefa48b
commit d0f8568e17

View File

@ -419,13 +419,13 @@ class ChuniBase:
all_entries = self.data.score.get_rival_music(rival_id) all_entries = self.data.score.get_rival_music(rival_id)
# Process the entries based on max_count and nextIndex # 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"] music_id = music["musicId"]
level = music["level"] level = music["level"]
score = music["scoreMax"] score = music["scoreMax"]
rank = music["scoreRank"] 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) music_entry = next((entry for entry in user_rival_music_list if entry["musicId"] == music_id), None)
if music_entry is None: if music_entry is None:
music_entry = { music_entry = {
@ -435,15 +435,20 @@ class ChuniBase:
} }
user_rival_music_list.append(music_entry) user_rival_music_list.append(music_entry)
# Create a level entry for the current level # Create a level entry for the current level if it's unique or has a higher score
level_entry = { level_entry = next((entry for entry in music_entry["userRivalMusicDetailList"] if entry["level"] == level), None)
"level": level, if level_entry is None:
"scoreMax": score, level_entry = {
"scoreRank": rank "level": level,
} "scoreMax": score,
music_entry["userRivalMusicDetailList"].append(level_entry) "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: for music_entry in user_rival_music_list:
music_entry["length"] = len(music_entry["userRivalMusicDetailList"]) music_entry["length"] = len(music_entry["userRivalMusicDetailList"])
@ -451,12 +456,12 @@ class ChuniBase:
result = { result = {
"userId": data["userId"], "userId": data["userId"],
"rivalId": data["rivalId"], "rivalId": data["rivalId"],
"nextIndex": str(next_index + len(all_entries) if len(all_entries) <= len(user_rival_music_list) else -1), "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[:max_count] "userRivalMusicList": user_rival_music_list[next_index: next_index + max_count]
} }
return result return result
def handle_get_user_favorite_item_api_request(self, data: Dict) -> Dict: def handle_get_user_favorite_item_api_request(self, data: Dict) -> Dict:
user_fav_item_list = [] user_fav_item_list = []