revert 033c1aa776b7874b6e534efd664f0b7010271e68
revert Update 卖
This commit is contained in:
parent
033c1aa776
commit
29f4a6a696
@ -77,33 +77,40 @@ class Mai2Base:
|
|||||||
}
|
}
|
||||||
|
|
||||||
async def handle_get_game_ranking_api_request(self, data: Dict) -> Dict:
|
async def handle_get_game_ranking_api_request(self, data: Dict) -> Dict:
|
||||||
|
conn = pymysql.connect(
|
||||||
|
host=self.core_config.database.host,
|
||||||
|
port=self.core_config.database.port,
|
||||||
|
user=self.core_config.database.username,
|
||||||
|
password=self.core_config.database.password,
|
||||||
|
database=self.core_config.database.name,
|
||||||
|
charset='utf8mb4'
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
playlogs = await self.data.score.get_playlogs(user_id=None)
|
cursor = conn.cursor()
|
||||||
ranking_list = []
|
|
||||||
|
|
||||||
if not playlogs:
|
query = """
|
||||||
self.logger.warning("No playlogs found.")
|
SELECT musicid AS id, COUNT(*) AS point
|
||||||
return {"length": 0, "gameRankingList": []}
|
FROM mai2_playlog
|
||||||
|
GROUP BY musicid
|
||||||
|
ORDER BY point DESC
|
||||||
|
LIMIT 100
|
||||||
|
"""
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
music_count = {}
|
results = cursor.fetchall()
|
||||||
for log in playlogs:
|
ranking_list = [{"id": row[0], "point": row[1], "userName": ""} for row in results]
|
||||||
music_id = log.musicId
|
output = {
|
||||||
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,
|
"type": 1,
|
||||||
"gameRankingList": ranking_list,
|
"gameRankingList": ranking_list,
|
||||||
"gameRankingInstantList": None
|
"gameRankingInstantList": None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
return output
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error while getting game ranking: {e}")
|
return {'length': 0, 'gameRankingList': []}
|
||||||
return {"length": 0, "gameRankingList": []}
|
|
||||||
|
|
||||||
async def handle_get_game_tournament_info_api_request(self, data: Dict) -> Dict:
|
async def handle_get_game_tournament_info_api_request(self, data: Dict) -> Dict:
|
||||||
# TODO: Tournament support
|
# TODO: Tournament support
|
||||||
|
Loading…
x
Reference in New Issue
Block a user