CHUNITHM & O.N.G.E.K.I.: Handle userRatingBase*List
This commit is contained in:
parent
346f82a32a
commit
5c48edc86b
|
@ -0,0 +1,56 @@
|
|||
"""GekiChu rating tables
|
||||
|
||||
Revision ID: 6a7e8277763b
|
||||
Revises: d8950c7ce2fc
|
||||
Create Date: 2024-03-13 12:18:53.210018
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
from sqlalchemy import Column, Integer, String
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6a7e8277763b'
|
||||
down_revision = 'd8950c7ce2fc'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
GEKICHU_RATING_TABLE_NAMES = [
|
||||
"chuni_profile_rating",
|
||||
"ongeki_profile_rating",
|
||||
]
|
||||
|
||||
def upgrade():
|
||||
for table_name in GEKICHU_RATING_TABLE_NAMES:
|
||||
op.create_table(
|
||||
table_name,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", Integer, nullable=False),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("type", String(255), nullable=False),
|
||||
Column("index", Integer, nullable=False),
|
||||
Column("musicId", Integer),
|
||||
Column("difficultId", Integer),
|
||||
Column("romVersionCode", Integer),
|
||||
Column("score", Integer),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
op.create_foreign_key(
|
||||
None,
|
||||
table_name,
|
||||
"aime_user",
|
||||
["user"],
|
||||
["id"],
|
||||
ondelete="cascade",
|
||||
onupdate="cascade",
|
||||
)
|
||||
op.create_unique_constraint(
|
||||
f"{table_name}_uk",
|
||||
table_name,
|
||||
["user", "version", "type", "index"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
for table_name in GEKICHU_RATING_TABLE_NAMES:
|
||||
op.drop_table(table_name)
|
|
@ -924,6 +924,27 @@ class ChuniBase:
|
|||
if "userRecentPlayerList" in upsert: # TODO: Seen in Air, maybe implement sometime
|
||||
for rp in upsert["userRecentPlayerList"]:
|
||||
pass
|
||||
|
||||
if "userRatingBaseList" in upsert:
|
||||
await self.data.profile.put_profile_rating_best(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseHotList" in upsert:
|
||||
await self.data.profile.put_profile_rating_hot(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseHotList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseNextList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseNextList"]
|
||||
)
|
||||
|
||||
return {"returnCode": "1"}
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from typing import Dict, List, Optional
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, BigInteger
|
||||
from sqlalchemy.engine.base import Connection
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, Boolean, JSON, BigInteger
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.engine import Row
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.sql import select, delete
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
|
@ -393,6 +392,26 @@ team = Table(
|
|||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
rating = Table(
|
||||
"chuni_profile_rating",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("type", String(255), nullable=False),
|
||||
Column("index", Integer, nullable=False),
|
||||
Column("musicId", Integer),
|
||||
Column("difficultId", Integer),
|
||||
Column("romVersionCode", Integer),
|
||||
Column("score", Integer),
|
||||
UniqueConstraint("user", "version", "type", "index", name="chuni_profile_rating_best_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class ChuniProfileData(BaseData):
|
||||
async def update_name(self, user_id: int, new_name: str) -> bool:
|
||||
|
@ -714,3 +733,46 @@ class ChuniProfileData(BaseData):
|
|||
return {
|
||||
"total_play_count": total_play_count
|
||||
}
|
||||
|
||||
async def _put_profile_rating(self, rating_type: str, aime_id: int, version: int, rating_data: List[Dict]):
|
||||
inserted_values = [
|
||||
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
||||
for (i, x) in enumerate(rating_data)
|
||||
]
|
||||
sql = insert(rating).values(inserted_values)
|
||||
update_dict = {x.name: x for x in sql.inserted if x.name != "id"}
|
||||
sql = sql.on_duplicate_key_update(**update_dict)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(
|
||||
f"put_profile_rating_{rating_type}: Could not insert rating entries, aime_id: {aime_id}",
|
||||
)
|
||||
return
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
async def put_profile_rating_best(self, aime_id: int, version: int, rating_best_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"best",
|
||||
aime_id,
|
||||
version,
|
||||
rating_best_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_hot(self, aime_id: int, version: int, rating_hot_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"hot",
|
||||
aime_id,
|
||||
version,
|
||||
rating_hot_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next(self, aime_id: int, version: int, rating_next_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_data,
|
||||
)
|
||||
|
||||
|
|
|
@ -1067,6 +1067,48 @@ class OngekiBase:
|
|||
if "userKopList" in upsert:
|
||||
for x in upsert["userKopList"]:
|
||||
await self.data.profile.put_kop(user_id, x)
|
||||
|
||||
if "userRatingBaseBestList" in upsert:
|
||||
await self.data.profile.put_profile_rating_best(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseBestList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseBestNewList" in upsert:
|
||||
await self.data.profile.put_profile_rating_best_new(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseBestNewList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseHotList" in upsert:
|
||||
await self.data.profile.put_profile_rating_hot(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseHotList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseNextList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseNextList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseNextNewList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next_new(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseNextNewList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseHotNextList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next_hot(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseHotNextList"]
|
||||
)
|
||||
|
||||
return {"returnCode": 1, "apiName": "upsertUserAll"}
|
||||
|
||||
|
|
|
@ -246,6 +246,26 @@ rival = Table(
|
|||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
rating = Table(
|
||||
"ongeki_profile_rating",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("type", String(255), nullable=False),
|
||||
Column("index", Integer, nullable=False),
|
||||
Column("musicId", Integer),
|
||||
Column("difficultId", Integer),
|
||||
Column("romVersionCode", Integer),
|
||||
Column("score", Integer),
|
||||
UniqueConstraint("user", "version", "type", "index", name="ongeki_profile_rating_best_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class OngekiProfileData(BaseData):
|
||||
def __init__(self, cfg: CoreConfig, conn: Connection) -> None:
|
||||
|
@ -514,4 +534,70 @@ class OngekiProfileData(BaseData):
|
|||
if result is None:
|
||||
self.logger.error(f"delete_rival: failed to delete! aime_id: {aime_id}, rival_id: {rival_id}")
|
||||
else:
|
||||
return result.rowcount
|
||||
return result.rowcount
|
||||
|
||||
async def _put_profile_rating(self, rating_type: str, aime_id: int, version: int, rating_data: List[Dict]):
|
||||
inserted_values = [
|
||||
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
||||
for (i, x) in enumerate(rating_data)
|
||||
]
|
||||
sql = insert(rating).values(inserted_values)
|
||||
update_dict = {x.name: x for x in sql.inserted if x.name != "id"}
|
||||
sql = sql.on_duplicate_key_update(**update_dict)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(
|
||||
f"put_profile_rating_{rating_type}: Could not insert rating entries, aime_id: {aime_id}",
|
||||
)
|
||||
return
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
async def put_profile_rating_best(self, aime_id: int, version: int, rating_best_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"best",
|
||||
aime_id,
|
||||
version,
|
||||
rating_best_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_best_new(self, aime_id: int, version: int, rating_best_new_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"best_new",
|
||||
aime_id,
|
||||
version,
|
||||
rating_best_new_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_hot(self, aime_id: int, version: int, rating_hot_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"hot",
|
||||
aime_id,
|
||||
version,
|
||||
rating_hot_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next(self, aime_id: int, version: int, rating_next_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next_new(self, aime_id: int, version: int, rating_next_new_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next_new",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_new_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next_hot(self, aime_id: int, version: int, rating_next_hot_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next_hot",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_hot_data,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue