forked from Hay1tsme/artemis
Merge pull request '[mai2] Implement GetGameRankingAPI . Fix photo merge , Add UserScoreRankingAPI handler' (#181) from SoulGateKey/artemis:develop into develop
Reviewed-on: Hay1tsme/artemis#181
This commit is contained in:
@ -76,6 +76,32 @@ class Mai2Base:
|
||||
}
|
||||
|
||||
async def handle_get_game_ranking_api_request(self, data: Dict) -> Dict:
|
||||
try:
|
||||
playlogs = await self.data.score.get_playlogs(user_id=None)
|
||||
ranking_list = []
|
||||
|
||||
if not playlogs:
|
||||
self.logger.warning("No playlogs found.")
|
||||
return {"length": 0, "gameRankingList": []}
|
||||
|
||||
music_count = {}
|
||||
for log in playlogs:
|
||||
music_id = log.musicId
|
||||
music_count[music_id] = music_count.get(music_id, 0) + 1
|
||||
|
||||
sorted_music = sorted(music_count.items(), key=lambda item: item[1], reverse=True)
|
||||
|
||||
for music_id, count in sorted_music[:100]:
|
||||
ranking_list.append({"id": music_id, "point": count, "userName": ""})
|
||||
|
||||
return {
|
||||
"type": 1,
|
||||
"gameRankingList": ranking_list,
|
||||
"gameRankingInstantList": None
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error while getting game ranking: {e}")
|
||||
return {"length": 0, "gameRankingList": []}
|
||||
|
||||
async def handle_get_game_tournament_info_api_request(self, data: Dict) -> Dict:
|
||||
@ -937,3 +963,6 @@ class Mai2Base:
|
||||
userRecommendSelectionMusicIdList: list[int]
|
||||
"""
|
||||
return {"userId": data["userId"], "userRecommendSelectionMusicIdList": []}
|
||||
async def handle_get_user_score_ranking_api_request(self, data: Dict) ->Dict:
|
||||
|
||||
return {"userId": data["userId"], "userScoreRanking": []}
|
@ -383,14 +383,14 @@ class Mai2Frontend(FE_Base):
|
||||
return Response(status_code=404)
|
||||
|
||||
if path.exists(f"{out_folder}"):
|
||||
print("path exists")
|
||||
self.logger.info(f"Photo Path Exist.")
|
||||
max_idx = 0
|
||||
p = ImageFile.Parser()
|
||||
for _, _, files in walk("out_folder"):
|
||||
for _, _, files in walk(f"{out_folder}"):
|
||||
if not files:
|
||||
break
|
||||
|
||||
matcher = re.match("^(\d+)_(\d+)$", files[0])
|
||||
matcher = re.match(r"^(\d+)_(\d+)\.bin$", files[0])
|
||||
if not matcher:
|
||||
break
|
||||
|
||||
@ -405,11 +405,12 @@ class Mai2Frontend(FE_Base):
|
||||
return Response(status_code=500)
|
||||
|
||||
for i in range(max_idx + 1):
|
||||
with open(f"{out_folder}/{i}_{max_idx}", "rb") as f:
|
||||
with open(f"{out_folder}/{i}_{max_idx}.bin", "rb") as f:
|
||||
p.feed(f.read())
|
||||
try:
|
||||
im = p.close()
|
||||
im.save(f"{out_folder}.jpeg")
|
||||
self.logger.info(f"{out_folder}.jpeg generated.")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"{photo_id} failed PIL validation! - {e}")
|
||||
@ -417,7 +418,7 @@ class Mai2Frontend(FE_Base):
|
||||
shutil.rmtree(out_folder)
|
||||
|
||||
if path.exists(f"{out_folder}.jpeg"):
|
||||
print(f"{out_folder}.jpeg exists")
|
||||
self.logger.info(f"{out_folder}.jpeg exists")
|
||||
return FileResponse(f"{out_folder}.jpeg")
|
||||
|
||||
return Response(status_code=404)
|
||||
|
@ -396,7 +396,10 @@ class Mai2ScoreData(BaseData):
|
||||
return result.fetchall()
|
||||
|
||||
async def get_playlogs(self, user_id: int, idx: int = 0, limit: int = 0) -> Optional[List[Row]]:
|
||||
if user_id is not None:
|
||||
sql = playlog.select(playlog.c.user == user_id)
|
||||
else:
|
||||
sql = playlog.select()
|
||||
|
||||
if limit:
|
||||
sql = sql.limit(limit)
|
||||
|
Reference in New Issue
Block a user