mai2: calc GetGameRanking result
parent
ed5e7dc561
commit
3843ac6eb1
|
@ -1,3 +1,4 @@
|
||||||
|
import pymysql
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
import logging
|
import logging
|
||||||
|
@ -76,7 +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:
|
||||||
return {"length": 0, "gameRankingList": []}
|
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:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
query = """
|
||||||
|
SELECT musicid AS id, COUNT(*) AS point
|
||||||
|
FROM mai2_playlog
|
||||||
|
GROUP BY musicid
|
||||||
|
ORDER BY point DESC
|
||||||
|
LIMIT 100
|
||||||
|
"""
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
results = cursor.fetchall()
|
||||||
|
ranking_list = [{"id": row[0], "point": row[1], "userName": ""} for row in results]
|
||||||
|
output = {
|
||||||
|
"type": 1,
|
||||||
|
"gameRankingList": ranking_list,
|
||||||
|
"gameRankingInstantList": None
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
return output
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
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…
Reference in New Issue