mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-02-13 19:27:27 +08:00
ongeki: proper handling of music ranking list
This commit is contained in:
@@ -4,11 +4,13 @@ from sqlalchemy import Column, Table, UniqueConstraint
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
from sqlalchemy.engine import Row
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.sql import select
|
||||
from sqlalchemy.sql import select, func
|
||||
from sqlalchemy.types import TIMESTAMP, Boolean, Float, Integer, String
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
score_best: Table = Table(
|
||||
"ongeki_score_best",
|
||||
metadata,
|
||||
@@ -209,6 +211,18 @@ class OngekiScoreData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_rankings(self, date: datetime) -> Optional[List[Row]]:
|
||||
sql = (
|
||||
select([func.count(playlog.c.id), playlog.c.musicId])
|
||||
.where(playlog.c.playDate == date.date())
|
||||
.group_by(playlog.c.musicId)
|
||||
.order_by(func.count(playlog.c.id).desc())
|
||||
.limit(10)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
if result:
|
||||
return result.fetchall()
|
||||
|
||||
async def put_playlog(self, aime_id: int, playlog_data: Dict) -> Optional[int]:
|
||||
playlog_data["user"] = aime_id
|
||||
|
||||
|
||||
@@ -98,18 +98,6 @@ cards = Table(
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
music_ranking = Table(
|
||||
"ongeki_static_music_ranking_list",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("musicId", Integer, nullable=False),
|
||||
Column("point", Integer, nullable=False),
|
||||
Column("userName", String(255)),
|
||||
UniqueConstraint("version", "musicId", name="ongeki_static_music_ranking_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
rewards = Table(
|
||||
"ongeki_static_rewards",
|
||||
metadata,
|
||||
@@ -425,13 +413,6 @@ class OngekiStaticData(BaseData):
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
async def get_ranking_list(self, version: int) -> Optional[List[Dict]]:
|
||||
sql = select(music_ranking.c.musicId.label('id'), music_ranking.c.point, music_ranking.c.userName).where(music_ranking.c.version == version)
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
async def put_reward(self, version: int, rewardId: int, rewardname: str, itemKind: int, itemId: int) -> Optional[int]:
|
||||
sql = insert(rewards).values(
|
||||
version=version,
|
||||
|
||||
Reference in New Issue
Block a user