forked from Hay1tsme/artemis
add back games, conform them to new title dispatch
This commit is contained in:
7
titles/ongeki/schema/__init__.py
Normal file
7
titles/ongeki/schema/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
from titles.ongeki.schema.profile import OngekiProfileData
|
||||
from titles.ongeki.schema.item import OngekiItemData
|
||||
from titles.ongeki.schema.static import OngekiStaticData
|
||||
from titles.ongeki.schema.score import OngekiScoreData
|
||||
from titles.ongeki.schema.log import OngekiLogData
|
||||
|
||||
__all__ = [OngekiProfileData, OngekiItemData, OngekiStaticData, OngekiScoreData, OngekiLogData]
|
526
titles/ongeki/schema/item.py
Normal file
526
titles/ongeki/schema/item.py
Normal file
@ -0,0 +1,526 @@
|
||||
from typing import Dict, Optional, List
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
|
||||
card = Table(
|
||||
"ongeki_user_card",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("cardId", Integer),
|
||||
Column("digitalStock", Integer),
|
||||
Column("analogStock", Integer),
|
||||
Column("level", Integer),
|
||||
Column("maxLevel", Integer),
|
||||
Column("exp", Integer),
|
||||
Column("printCount", Integer),
|
||||
Column("useCount", Integer),
|
||||
Column("isNew", Boolean),
|
||||
Column("kaikaDate", String(25)),
|
||||
Column("choKaikaDate", String(25)),
|
||||
Column("skillId", Integer),
|
||||
Column("isAcquired", Boolean),
|
||||
Column("created", String(25)),
|
||||
UniqueConstraint("user", "cardId", name="ongeki_user_card_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
deck = Table(
|
||||
"ongeki_user_deck",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("deckId", Integer),
|
||||
Column("cardId1", Integer),
|
||||
Column("cardId2", Integer),
|
||||
Column("cardId3", Integer),
|
||||
UniqueConstraint("user", "deckId", name="ongeki_user_deck_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
character = Table(
|
||||
"ongeki_user_character",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("characterId", Integer),
|
||||
Column("costumeId", Integer),
|
||||
Column("attachmentId", Integer),
|
||||
Column("playCount", Integer),
|
||||
Column("intimateLevel", Integer),
|
||||
Column("intimateCount", Integer),
|
||||
Column("intimateCountRewarded", Integer),
|
||||
Column("intimateCountDate", String(25)),
|
||||
Column("isNew", Boolean),
|
||||
UniqueConstraint("user", "characterId", name="ongeki_user_character_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
boss = Table (
|
||||
"ongeki_user_boss",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("musicId", Integer),
|
||||
Column("damage", Integer),
|
||||
Column("isClear", Boolean),
|
||||
Column("eventId", Integer),
|
||||
UniqueConstraint("user", "musicId", "eventId", name="ongeki_user_boss_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
story = Table (
|
||||
"ongeki_user_story",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("storyId", Integer),
|
||||
Column("jewelCount", Integer),
|
||||
Column("lastChapterId", Integer),
|
||||
Column("lastPlayMusicId", Integer),
|
||||
Column("lastPlayMusicCategory", Integer),
|
||||
Column("lastPlayMusicLevel", Integer),
|
||||
UniqueConstraint("user", "storyId", name="ongeki_user_story_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
chapter = Table(
|
||||
"ongeki_user_chapter",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("chapterId", Integer),
|
||||
Column("jewelCount", Integer),
|
||||
Column("isStoryWatched", Boolean),
|
||||
Column("isClear", Boolean),
|
||||
Column("lastPlayMusicId", Integer),
|
||||
Column("lastPlayMusicCategory", Integer),
|
||||
Column("lastPlayMusicLevel", Integer),
|
||||
Column("skipTiming1", Integer),
|
||||
Column("skipTiming2", Integer),
|
||||
UniqueConstraint("user", "chapterId", name="ongeki_user_chapter_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
item = Table(
|
||||
"ongeki_user_item",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("itemKind", Integer),
|
||||
Column("itemId", Integer),
|
||||
Column("stock", Integer),
|
||||
Column("isValid", Boolean),
|
||||
UniqueConstraint("user", "itemKind", "itemId", name="ongeki_user_item_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
music_item = Table(
|
||||
"ongeki_user_music_item",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("musicId", Integer),
|
||||
Column("status", Integer),
|
||||
UniqueConstraint("user", "musicId", name="ongeki_user_music_item_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
login_bonus = Table(
|
||||
"ongeki_user_login_bonus",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("bonusId", Integer),
|
||||
Column("bonusCount", Integer),
|
||||
Column("lastUpdateDate", String(25)),
|
||||
UniqueConstraint("user", "bonusId", name="ongeki_user_login_bonus_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
event_point = Table(
|
||||
"ongeki_user_event_point",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("eventId", Integer),
|
||||
Column("point", Integer),
|
||||
Column("isRankingRewarded", Boolean),
|
||||
UniqueConstraint("user", "eventId", name="ongeki_user_event_point_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
mission_point = Table(
|
||||
"ongeki_user_mission_point",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("eventId", Integer),
|
||||
Column("point", Integer),
|
||||
UniqueConstraint("user", "eventId", name="ongeki_user_mission_point_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
scenerio = Table(
|
||||
"ongeki_user_scenerio",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("scenarioId", Integer),
|
||||
Column("playCount", Integer),
|
||||
UniqueConstraint("user", "scenarioId", name="ongeki_user_scenerio_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
trade_item = Table(
|
||||
"ongeki_user_trade_item",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("chapterId", Integer),
|
||||
Column("tradeItemId", Integer),
|
||||
Column("tradeCount", Integer),
|
||||
UniqueConstraint("user", "chapterId", "tradeItemId", name="ongeki_user_trade_item_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
event_music = Table(
|
||||
"ongeki_user_event_music",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("eventId", Integer),
|
||||
Column("type", Integer),
|
||||
Column("musicId", Integer),
|
||||
Column("level", Integer),
|
||||
Column("techScoreMax", Integer),
|
||||
Column("platinumScoreMax", Integer),
|
||||
Column("techRecordDate", String(25)),
|
||||
Column("isTechNewRecord", Boolean),
|
||||
UniqueConstraint("user", "eventId", "type", "musicId", "level", name="ongeki_user_event_music"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
tech_event = Table(
|
||||
"ongeki_user_tech_event",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("eventId", Integer),
|
||||
Column("totalTechScore", Integer),
|
||||
Column("totalPlatinumScore", Integer),
|
||||
Column("techRecordDate", String(25)),
|
||||
Column("isRankingRewarded", Boolean),
|
||||
Column("isTotalTechNewRecord", Boolean),
|
||||
UniqueConstraint("user", "eventId", name="ongeki_user_tech_event_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
|
||||
class OngekiItemData(BaseData):
|
||||
def put_card(self, aime_id: int, card_data: Dict) -> Optional[int]:
|
||||
card_data["user"] = aime_id
|
||||
|
||||
sql = insert(card).values(**card_data)
|
||||
conflict = sql.on_duplicate_key_update(**card_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_card: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_cards(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(card).where(card.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_character(self, aime_id: int, character_data: Dict) -> Optional[int]:
|
||||
character_data["user"] = aime_id
|
||||
|
||||
sql = insert(character).values(**character_data)
|
||||
conflict = sql.on_duplicate_key_update(**character_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_character: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_characters(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(character).where(character.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_deck(self, aime_id: int, deck_data: Dict) -> Optional[int]:
|
||||
deck_data["user"] = aime_id
|
||||
|
||||
sql = insert(deck).values(**deck_data)
|
||||
conflict = sql.on_duplicate_key_update(**deck_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_deck: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_deck(self, aime_id: int, deck_id: int) -> Optional[Dict]:
|
||||
sql = select(deck).where(and_(deck.c.user == aime_id, deck.c.deckId == deck_id))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_decks(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(deck).where(deck.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_boss(self, aime_id: int, boss_data: Dict) -> Optional[int]:
|
||||
boss_data["user"] = aime_id
|
||||
|
||||
sql = insert(boss).values(**boss_data)
|
||||
conflict = sql.on_duplicate_key_update(**boss_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_boss: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_story(self, aime_id: int, story_data: Dict) -> Optional[int]:
|
||||
story_data["user"] = aime_id
|
||||
|
||||
sql = insert(story).values(**story_data)
|
||||
conflict = sql.on_duplicate_key_update(**story_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_story: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_stories(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(story).where(story.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_chapter(self, aime_id: int, chapter_data: Dict) -> Optional[int]:
|
||||
chapter_data["user"] = aime_id
|
||||
|
||||
sql = insert(chapter).values(**chapter_data)
|
||||
conflict = sql.on_duplicate_key_update(**chapter_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_chapter: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_chapters(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(chapter).where(chapter.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_item(self, aime_id: int, item_data: Dict) -> Optional[int]:
|
||||
item_data["user"] = aime_id
|
||||
|
||||
sql = insert(item).values(**item_data)
|
||||
conflict = sql.on_duplicate_key_update(**item_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_item: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_item(self, aime_id: int, item_id: int, item_kind: int) -> Optional[Dict]:
|
||||
sql = select(item).where(and_(item.c.user == aime_id, item.c.itemId == item_id))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_items(self, aime_id: int, item_kind: int = None) -> Optional[List[Dict]]:
|
||||
if item_kind is None:
|
||||
sql = select(item).where(item.c.user == aime_id)
|
||||
else:
|
||||
sql = select(item).where(and_(item.c.user == aime_id, item.c.itemKind == item_kind))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_music_item(self, aime_id: int, music_item_data: Dict) -> Optional[int]:
|
||||
music_item_data["user"] = aime_id
|
||||
|
||||
sql = insert(music_item).values(**music_item_data)
|
||||
conflict = sql.on_duplicate_key_update(**music_item_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_music_item: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_music_items(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(music_item).where(music_item.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_login_bonus(self, aime_id: int, login_bonus_data: Dict) -> Optional[int]:
|
||||
login_bonus_data["user"] = aime_id
|
||||
|
||||
sql = insert(login_bonus).values(**login_bonus_data)
|
||||
conflict = sql.on_duplicate_key_update(**login_bonus_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_login_bonus: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_login_bonuses(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(login_bonus).where(login_bonus.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_mission_point(self, aime_id: int, mission_point_data: Dict) -> Optional[int]:
|
||||
mission_point_data["user"] = aime_id
|
||||
|
||||
sql = insert(mission_point).values(**mission_point_data)
|
||||
conflict = sql.on_duplicate_key_update(**mission_point_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_mission_point: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_mission_points(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(mission_point).where(mission_point.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_event_point(self, aime_id: int, event_point_data: Dict) -> Optional[int]:
|
||||
event_point_data["user"] = aime_id
|
||||
|
||||
sql = insert(event_point).values(**event_point_data)
|
||||
conflict = sql.on_duplicate_key_update(**event_point_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_event_point: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_event_points(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(event_point).where(event_point.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_scenerio(self, aime_id: int, scenerio_data: Dict) -> Optional[int]:
|
||||
scenerio_data["user"] = aime_id
|
||||
|
||||
sql = insert(scenerio).values(**scenerio_data)
|
||||
conflict = sql.on_duplicate_key_update(**scenerio_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_scenerio: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_scenerios(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(scenerio).where(scenerio.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_trade_item(self, aime_id: int, trade_item_data: Dict) -> Optional[int]:
|
||||
trade_item_data["user"] = aime_id
|
||||
|
||||
sql = insert(trade_item).values(**trade_item_data)
|
||||
conflict = sql.on_duplicate_key_update(**trade_item_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_trade_item: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_trade_items(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(trade_item).where(trade_item.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_event_music(self, aime_id: int, event_music_data: Dict) -> Optional[int]:
|
||||
event_music_data["user"] = aime_id
|
||||
|
||||
sql = insert(event_music).values(**event_music_data)
|
||||
conflict = sql.on_duplicate_key_update(**event_music_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_event_music: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_event_music(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(event_music).where(event_music.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_tech_event(self, aime_id: int, tech_event_data: Dict) -> Optional[int]:
|
||||
tech_event_data["user"] = aime_id
|
||||
|
||||
sql = insert(tech_event).values(**tech_event_data)
|
||||
conflict = sql.on_duplicate_key_update(**tech_event_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_tech_event: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_tech_event(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(tech_event).where(tech_event.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_bosses(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(boss).where(boss.c.user == aime_id)
|
||||
result = self.execute(sql)
|
||||
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
55
titles/ongeki/schema/log.py
Normal file
55
titles/ongeki/schema/log.py
Normal file
@ -0,0 +1,55 @@
|
||||
from typing import Dict, Optional
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
|
||||
gp_log = Table(
|
||||
"ongeki_gp_log",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("usedCredit", Integer),
|
||||
Column("placeName", String(255)),
|
||||
Column("trxnDate", String(255)),
|
||||
Column("placeId", Integer), # Making this an FK would mess with people playing with default KC
|
||||
Column("kind", Integer),
|
||||
Column("pattern", Integer),
|
||||
Column("currentGP", Integer),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
session_log = Table(
|
||||
"ongeki_session_log",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("sortNumber", Integer),
|
||||
Column("placeId", Integer),
|
||||
Column("playDate", String(10)),
|
||||
Column("userPlayDate", String(25)),
|
||||
Column("isPaid", Boolean),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
class OngekiLogData(BaseData):
|
||||
def put_gp_log(self, aime_id: Optional[int], used_credit: int, place_name: str, tx_date: str, place_id: int,
|
||||
kind: int, pattern: int, current_gp: int) -> Optional[int]:
|
||||
sql = insert(gp_log).values(
|
||||
user=aime_id,
|
||||
usedCredit=used_credit,
|
||||
placeName=place_name,
|
||||
trxnDate=tx_date,
|
||||
placeId=place_id,
|
||||
kind=kind,
|
||||
pattern=pattern,
|
||||
currentGP=current_gp,
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_gp_log: Failed to insert GP log! aime_id: {aime_id} kind {kind} pattern {pattern} current_gp {current_gp}")
|
||||
return result.lastrowid
|
447
titles/ongeki/schema/profile.py
Normal file
447
titles/ongeki/schema/profile.py
Normal file
@ -0,0 +1,447 @@
|
||||
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.schema import ForeignKey
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.engine import Row
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
from core.config import CoreConfig
|
||||
|
||||
# Cammel case column names technically don't follow the other games but
|
||||
# it makes it way easier on me to not fuck with what the games has
|
||||
profile = Table(
|
||||
"ongeki_profile_data",
|
||||
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("userName", String(8)),
|
||||
Column("level", Integer),
|
||||
Column("reincarnationNum", Integer),
|
||||
Column("exp", Integer),
|
||||
Column("point", Integer),
|
||||
Column("totalPoint", Integer),
|
||||
Column("playCount", Integer),
|
||||
Column("jewelCount", Integer),
|
||||
Column("totalJewelCount", Integer),
|
||||
Column("medalCount", Integer),
|
||||
Column("playerRating", Integer),
|
||||
Column("highestRating", Integer),
|
||||
Column("battlePoint", Integer),
|
||||
Column("nameplateId", Integer),
|
||||
Column("trophyId", Integer),
|
||||
Column("cardId", Integer),
|
||||
Column("characterId", Integer),
|
||||
Column("characterVoiceNo", Integer),
|
||||
Column("tabSetting", Integer),
|
||||
Column("tabSortSetting", Integer),
|
||||
Column("cardCategorySetting", Integer),
|
||||
Column("cardSortSetting", Integer),
|
||||
Column("playedTutorialBit", Integer),
|
||||
Column("firstTutorialCancelNum", Integer),
|
||||
Column("sumTechHighScore", BigInteger),
|
||||
Column("sumTechBasicHighScore", BigInteger),
|
||||
Column("sumTechAdvancedHighScore", BigInteger),
|
||||
Column("sumTechExpertHighScore", BigInteger),
|
||||
Column("sumTechMasterHighScore", BigInteger),
|
||||
Column("sumTechLunaticHighScore", BigInteger),
|
||||
Column("sumBattleHighScore", BigInteger),
|
||||
Column("sumBattleBasicHighScore", BigInteger),
|
||||
Column("sumBattleAdvancedHighScore", BigInteger),
|
||||
Column("sumBattleExpertHighScore", BigInteger),
|
||||
Column("sumBattleMasterHighScore", BigInteger),
|
||||
Column("sumBattleLunaticHighScore", BigInteger),
|
||||
Column("eventWatchedDate", String(255)),
|
||||
Column("cmEventWatchedDate", String(255)),
|
||||
Column("firstGameId", String(8)),
|
||||
Column("firstRomVersion", String(8)),
|
||||
Column("firstDataVersion", String(8)),
|
||||
Column("firstPlayDate", String(255)),
|
||||
Column("lastGameId", String(8)),
|
||||
Column("lastRomVersion", String(8)),
|
||||
Column("lastDataVersion", String(8)),
|
||||
Column("compatibleCmVersion", String(8)),
|
||||
Column("lastPlayDate", String(255)),
|
||||
Column("lastPlaceId", Integer),
|
||||
Column("lastPlaceName", String(255)),
|
||||
Column("lastRegionId", Integer),
|
||||
Column("lastRegionName", String(255)),
|
||||
Column("lastAllNetId", Integer),
|
||||
Column("lastClientId", String(16)),
|
||||
Column("lastUsedDeckId", Integer),
|
||||
Column("lastPlayMusicLevel", Integer),
|
||||
Column("banStatus", Integer, server_default="0"),
|
||||
Column("rivalScoreCategorySetting", Integer, server_default="0"),
|
||||
Column("overDamageBattlePoint", Integer, server_default="0"),
|
||||
Column("bestBattlePoint", Integer, server_default="0"),
|
||||
Column("lastEmoneyBrand", Integer, server_default="0"),
|
||||
UniqueConstraint("user", "version", name="ongeki_profile_profile_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
# No point setting defaults since the game sends everything on profile creation anyway
|
||||
option = Table(
|
||||
"ongeki_profile_option",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("optionSet", Integer),
|
||||
Column("speed", Integer),
|
||||
Column("mirror", Integer),
|
||||
Column("judgeTiming", Integer),
|
||||
Column("judgeAdjustment", Integer),
|
||||
Column("abort", Integer),
|
||||
Column("tapSound", Integer),
|
||||
Column("volGuide", Integer),
|
||||
Column("volAll", Integer),
|
||||
Column("volTap", Integer),
|
||||
Column("volCrTap", Integer),
|
||||
Column("volHold", Integer),
|
||||
Column("volSide", Integer),
|
||||
Column("volFlick", Integer),
|
||||
Column("volBell", Integer),
|
||||
Column("volEnemy", Integer),
|
||||
Column("volSkill", Integer),
|
||||
Column("volDamage", Integer),
|
||||
Column("colorField", Integer),
|
||||
Column("colorLaneBright", Integer),
|
||||
Column("colorLane", Integer),
|
||||
Column("colorSide", Integer),
|
||||
Column("effectDamage", Integer),
|
||||
Column("effectPos", Integer),
|
||||
Column("judgeDisp", Integer),
|
||||
Column("judgePos", Integer),
|
||||
Column("judgeBreak", Integer),
|
||||
Column("judgeHit", Integer),
|
||||
Column("platinumBreakDisp", Integer),
|
||||
Column("judgeCriticalBreak", Integer),
|
||||
Column("matching", Integer),
|
||||
Column("dispPlayerLv", Integer),
|
||||
Column("dispRating", Integer),
|
||||
Column("dispBP", Integer),
|
||||
Column("headphone", Integer),
|
||||
Column("stealthField", Integer),
|
||||
Column("colorWallBright", Integer),
|
||||
UniqueConstraint("user", name="ongeki_profile_option_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
activity = Table(
|
||||
"ongeki_profile_activity",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("kind", Integer),
|
||||
Column("activityId", Integer),
|
||||
Column("sortNumber", Integer),
|
||||
Column("param1", Integer),
|
||||
Column("param2", Integer),
|
||||
Column("param3", Integer),
|
||||
Column("param4", Integer),
|
||||
UniqueConstraint("user", "kind", "activityId", name="ongeki_profile_activity_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
recent_rating = Table(
|
||||
"ongeki_profile_recent_rating",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("recentRating", JSON),
|
||||
UniqueConstraint("user", name="ongeki_profile_recent_rating_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
rating_log = Table(
|
||||
"ongeki_profile_rating_log",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("highestRating", Integer),
|
||||
Column("dataVersion", String(10)),
|
||||
UniqueConstraint("user", "dataVersion", name="ongeki_profile_rating_log_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
region = Table(
|
||||
"ongeki_profile_region",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("regionId", Integer),
|
||||
Column("playCount", Integer),
|
||||
Column("created", String(25)),
|
||||
UniqueConstraint("user", "regionId", name="ongeki_profile_region_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
training_room = Table (
|
||||
"ongeki_profile_training_room",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("roomId", Integer),
|
||||
Column("authKey", Integer),
|
||||
Column("cardId", Integer),
|
||||
Column("valueDate", String(25)),
|
||||
UniqueConstraint("user", "roomId", name="ongeki_profile_training_room_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
kop = Table (
|
||||
"ongeki_profile_kop",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("authKey", Integer),
|
||||
Column("kopId", Integer),
|
||||
Column("areaId", Integer),
|
||||
Column("totalTechScore", Integer),
|
||||
Column("totalPlatinumScore", Integer),
|
||||
Column("techRecordDate", String(25)),
|
||||
Column("isTotalTechNewRecord", Boolean),
|
||||
UniqueConstraint("user", "kopId", name="ongeki_profile_kop_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
rival = Table(
|
||||
"ongeki_profile_rival",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
Column("rivalUserId", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade")),
|
||||
UniqueConstraint("user", "rivalUserId", name="ongeki_profile_rival_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
class OngekiProfileData(BaseData):
|
||||
def __init__(self, cfg: CoreConfig, conn: Connection) -> None:
|
||||
super().__init__(cfg, conn)
|
||||
self.date_time_format_ext = "%Y-%m-%d %H:%M:%S.%f" # needs to be lopped off at [:-5]
|
||||
self.date_time_format_short = "%Y-%m-%d"
|
||||
|
||||
def get_profile_name(self, aime_id: int, version: int) -> Optional[str]:
|
||||
sql = select(profile.c.userName).where(and_(profile.c.user == aime_id, profile.c.version == version))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
|
||||
row = result.fetchone()
|
||||
if row is None: return None
|
||||
|
||||
return row["userName"]
|
||||
|
||||
def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]:
|
||||
sql = select([profile, option]).join(option, profile.c.user == option.c.user).filter(
|
||||
and_(profile.c.user == aime_id, profile.c.version == version)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_profile_data(self, aime_id: int, version: int) -> Optional[Row]:
|
||||
sql = select(profile).where(and_(
|
||||
profile.c.user == aime_id,
|
||||
profile.c.version == version,
|
||||
))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_profile_options(self, aime_id: int) -> Optional[Row]:
|
||||
sql = select(option).where(and_(
|
||||
option.c.user == aime_id,
|
||||
))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_profile_recent_rating(self, aime_id: int) -> Optional[List[Row]]:
|
||||
sql = select(recent_rating).where(recent_rating.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_profile_rating_log(self, aime_id: int) -> Optional[List[Row]]:
|
||||
sql = select(rating_log).where(recent_rating.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_profile_activity(self, aime_id: int, kind: int = None) -> Optional[List[Row]]:
|
||||
sql = select(activity).where(and_(
|
||||
activity.c.user == aime_id,
|
||||
(activity.c.kind == kind) if kind is not None else True
|
||||
))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_kop(self, aime_id: int) -> Optional[List[Row]]:
|
||||
sql = select(kop).where(kop.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_rivals(self, aime_id: int) -> Optional[List[Row]]:
|
||||
sql = select(rival.c.rivalUserId).where(rival.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_profile_data(self, aime_id: int, version: int, data: Dict) -> Optional[int]:
|
||||
data["user"] = aime_id
|
||||
data["version"] = version
|
||||
data.pop("accessCode")
|
||||
|
||||
sql = insert(profile).values(**data)
|
||||
conflict = sql.on_duplicate_key_update(**data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_profile_data: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_profile_options(self, aime_id: int, options_data: Dict) -> Optional[int]:
|
||||
options_data["user"] = aime_id
|
||||
|
||||
sql = insert(option).values(**options_data)
|
||||
conflict = sql.on_duplicate_key_update(**options_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_profile_options: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_profile_recent_rating(self, aime_id: int, recent_rating_data: List[Dict]) -> Optional[int]:
|
||||
sql = insert(recent_rating).values(
|
||||
user=aime_id,
|
||||
recentRating=recent_rating_data
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
recentRating=recent_rating_data
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_profile_recent_rating: failed to update recent rating! aime_id {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_profile_bp_list(self, aime_id: int, bp_base_list: List[Dict]) -> Optional[int]:
|
||||
pass
|
||||
|
||||
def put_profile_rating_log(self, aime_id: int, data_version: str, highest_rating: int) -> Optional[int]:
|
||||
sql = insert(rating_log).values(
|
||||
user=aime_id,
|
||||
dataVersion=data_version,
|
||||
highestRating=highest_rating
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
highestRating=highest_rating
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_profile_rating_log: failed to update rating log! aime_id {aime_id} data_version {data_version} highest_rating {highest_rating}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_profile_activity(self, aime_id: int, kind: int, activity_id: int, sort_num: int,
|
||||
p1: int, p2: int, p3: int, p4: int) -> Optional[int]:
|
||||
sql = insert(activity).values(
|
||||
user=aime_id,
|
||||
kind=kind,
|
||||
activityId=activity_id,
|
||||
sortNumber=sort_num,
|
||||
param1=p1,
|
||||
param2=p2,
|
||||
param3=p3,
|
||||
param4=p4
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
sortNumber=sort_num,
|
||||
param1=p1,
|
||||
param2=p2,
|
||||
param3=p3,
|
||||
param4=p4
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_profile_activity: failed to put activity! aime_id {aime_id} kind {kind} activity_id {activity_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_profile_region(self, aime_id: int, region: int, date: str) -> Optional[int]:
|
||||
sql = insert(activity).values(
|
||||
user=aime_id,
|
||||
region=region,
|
||||
playCount=1,
|
||||
created=date
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
playCount=activity.c.playCount + 1,
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_profile_region: failed to update! aime_id {aime_id} region {region}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_training_room(self, aime_id: int, room_detail: Dict) -> Optional[int]:
|
||||
room_detail["user"] = aime_id
|
||||
|
||||
sql = insert(training_room).values(**room_detail)
|
||||
conflict = sql.on_duplicate_key_update(**room_detail)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_best_score: Failed to add score! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_kop(self, aime_id: int, kop_data: Dict) -> Optional[int]:
|
||||
kop_data["user"] = aime_id
|
||||
|
||||
sql = insert(kop).values(**kop_data)
|
||||
conflict = sql.on_duplicate_key_update(**kop_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_kop: Failed to add score! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_rival(self, aime_id: int, rival_id: int) -> Optional[int]:
|
||||
sql = insert(rival).values(
|
||||
user = aime_id,
|
||||
rivalUserId = rival_id
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(rival = rival_id)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_rival: failed to update! aime_id: {aime_id}, rival_id: {rival_id}")
|
||||
return None
|
||||
return result.lastrowid
|
161
titles/ongeki/schema/score.py
Normal file
161
titles/ongeki/schema/score.py
Normal file
@ -0,0 +1,161 @@
|
||||
from typing import Dict, List, Optional
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, Float
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
|
||||
score_best = Table(
|
||||
"ongeki_score_best",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("musicId", Integer, nullable=False),
|
||||
Column("level", Integer, nullable=False),
|
||||
Column("playCount", Integer, nullable=False),
|
||||
Column("techScoreMax", Integer, nullable=False),
|
||||
Column("techScoreRank", Integer, nullable=False),
|
||||
Column("battleScoreMax", Integer, nullable=False),
|
||||
Column("battleScoreRank", Integer, nullable=False),
|
||||
Column("maxComboCount", Integer, nullable=False),
|
||||
Column("maxOverKill", Float, nullable=False),
|
||||
Column("maxTeamOverKill", Float, nullable=False),
|
||||
Column("isFullBell", Boolean, nullable=False),
|
||||
Column("isFullCombo", Boolean, nullable=False),
|
||||
Column("isAllBreake", Boolean, nullable=False),
|
||||
Column("isLock", Boolean, nullable=False),
|
||||
Column("clearStatus", Boolean, nullable=False),
|
||||
Column("isStoryWatched", Boolean, nullable=False),
|
||||
UniqueConstraint("user", "musicId", "level", name="ongeki_best_score_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
playlog = Table(
|
||||
"ongeki_score_playlog",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("sortNumber", Integer),
|
||||
Column("placeId", Integer),
|
||||
Column("placeName", String(255)),
|
||||
Column("playDate", TIMESTAMP),
|
||||
Column("userPlayDate", TIMESTAMP),
|
||||
Column("musicId", Integer),
|
||||
Column("level", Integer),
|
||||
Column("playKind", Integer),
|
||||
Column("eventId", Integer),
|
||||
Column("eventName", String(255)),
|
||||
Column("eventPoint", Integer),
|
||||
Column("playedUserId1", Integer),
|
||||
Column("playedUserId2", Integer),
|
||||
Column("playedUserId3", Integer),
|
||||
Column("playedUserName1", String(8)),
|
||||
Column("playedUserName2", String(8)),
|
||||
Column("playedUserName3", String(8)),
|
||||
Column("playedMusicLevel1", Integer),
|
||||
Column("playedMusicLevel2", Integer),
|
||||
Column("playedMusicLevel3", Integer),
|
||||
Column("cardId1", Integer),
|
||||
Column("cardId2", Integer),
|
||||
Column("cardId3", Integer),
|
||||
Column("cardLevel1", Integer),
|
||||
Column("cardLevel2", Integer),
|
||||
Column("cardLevel3", Integer),
|
||||
Column("cardAttack1", Integer),
|
||||
Column("cardAttack2", Integer),
|
||||
Column("cardAttack3", Integer),
|
||||
Column("bossCharaId", Integer),
|
||||
Column("bossLevel", Integer),
|
||||
Column("bossAttribute", Integer),
|
||||
Column("clearStatus", Integer),
|
||||
Column("techScore", Integer),
|
||||
Column("techScoreRank", Integer),
|
||||
Column("battleScore", Integer),
|
||||
Column("battleScoreRank", Integer),
|
||||
Column("maxCombo", Integer),
|
||||
Column("judgeMiss", Integer),
|
||||
Column("judgeHit", Integer),
|
||||
Column("judgeBreak", Integer),
|
||||
Column("judgeCriticalBreak", Integer),
|
||||
Column("rateTap", Integer),
|
||||
Column("rateHold", Integer),
|
||||
Column("rateFlick", Integer),
|
||||
Column("rateSideTap", Integer),
|
||||
Column("rateSideHold", Integer),
|
||||
Column("bellCount", Integer),
|
||||
Column("totalBellCount", Integer),
|
||||
Column("damageCount", Integer),
|
||||
Column("overDamage", Integer),
|
||||
Column("isTechNewRecord", Boolean),
|
||||
Column("isBattleNewRecord", Boolean),
|
||||
Column("isOverDamageNewRecord", Boolean),
|
||||
Column("isFullCombo", Boolean),
|
||||
Column("isFullBell", Boolean),
|
||||
Column("isAllBreak", Boolean),
|
||||
Column("playerRating", Integer),
|
||||
Column("battlePoint", Integer),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
tech_count = Table(
|
||||
"ongeki_score_tech_count",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column("levelId", Integer, nullable=False),
|
||||
Column("allBreakCount", Integer),
|
||||
Column("allBreakPlusCount", Integer),
|
||||
UniqueConstraint("user", "levelId", name="ongeki_tech_count_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
class OngekiScoreData(BaseData):
|
||||
def get_tech_count(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
return []
|
||||
|
||||
def put_tech_count(self, aime_id: int, tech_count_data: Dict) -> Optional[int]:
|
||||
tech_count_data["user"] = aime_id
|
||||
|
||||
sql = insert(tech_count).values(**tech_count_data)
|
||||
conflict = sql.on_duplicate_key_update(**tech_count_data)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_tech_count: Failed to update! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_best_scores(self, aime_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(score_best).where(score_best.c.user == aime_id)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_best_score(self, aime_id: int, song_id: int, chart_id: int = None) -> Optional[List[Dict]]:
|
||||
return []
|
||||
|
||||
def put_best_score(self, aime_id: int, music_detail: Dict) -> Optional[int]:
|
||||
music_detail["user"] = aime_id
|
||||
|
||||
sql = insert(score_best).values(**music_detail)
|
||||
conflict = sql.on_duplicate_key_update(**music_detail)
|
||||
result = self.execute(conflict)
|
||||
|
||||
if result is None:
|
||||
self.logger.warn(f"put_best_score: Failed to add score! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def put_playlog(self, aime_id: int, playlog_data: Dict) -> Optional[int]:
|
||||
playlog_data["user"] = aime_id
|
||||
|
||||
sql = insert(playlog).values(**playlog_data)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
self.logger.warn(f"put_playlog: Failed to add playlog! aime_id: {aime_id}")
|
||||
return None
|
||||
return result.lastrowid
|
119
titles/ongeki/schema/static.py
Normal file
119
titles/ongeki/schema/static.py
Normal file
@ -0,0 +1,119 @@
|
||||
from typing import Dict, List, Optional
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, Float
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.engine import Row
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from core.data.schema import BaseData, metadata
|
||||
|
||||
events = Table(
|
||||
"ongeki_static_events",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("version", Integer),
|
||||
Column("eventId", Integer),
|
||||
Column("type", Integer),
|
||||
Column("name", String(255)),
|
||||
Column("enabled", Boolean, server_default="1"),
|
||||
UniqueConstraint("version", "eventId", "type", name="ongeki_static_events_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
|
||||
music = Table(
|
||||
"ongeki_static_music",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("version", Integer),
|
||||
Column("songId", Integer),
|
||||
Column("chartId", Integer),
|
||||
Column("title", String(255)),
|
||||
Column("artist", String(255)),
|
||||
Column("genre", String(255)),
|
||||
Column("level", Float),
|
||||
UniqueConstraint("version", "songId", "chartId", name="ongeki_static_music_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
)
|
||||
|
||||
class OngekiStaticData(BaseData):
|
||||
def put_event(self, version: int, event_id: int, event_type: int, event_name: str) -> Optional[int]:
|
||||
sql = insert(events).values(
|
||||
version = version,
|
||||
eventId = event_id,
|
||||
type = event_type,
|
||||
name = event_name,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
name = event_name,
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"Failed to insert event! event_id {event_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_event(self, version: int, event_id: int) -> Optional[List[Dict]]:
|
||||
sql = select(events).where(and_(events.c.version == version, events.c.eventId == event_id))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_events(self, version: int) -> Optional[List[Dict]]:
|
||||
sql = select(events).where(events.c.version == version)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_enabled_events(self, version: int) -> Optional[List[Dict]]:
|
||||
sql = select(events).where(and_(events.c.version == version, events.c.enabled == True))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_chart(self, version: int, song_id: int, chart_id: int, title: str, artist: str, genre: str, level: float) -> Optional[int]:
|
||||
sql = insert(music).values(
|
||||
version = version,
|
||||
songId = song_id,
|
||||
chartId = chart_id,
|
||||
title = title,
|
||||
artist = artist,
|
||||
genre = genre,
|
||||
level = level,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
title = title,
|
||||
artist = artist,
|
||||
genre = genre,
|
||||
level = level,
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warn(f"Failed to insert chart! song_id: {song_id}, chart_id: {chart_id}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_chart(self, version: int, song_id: int, chart_id: int = None) -> Optional[List[Dict]]:
|
||||
pass
|
||||
|
||||
def get_music(self, version: int) -> Optional[List[Dict]]:
|
||||
pass
|
||||
|
||||
def get_music_chart(self, version: int, song_id: int, chart_id: int) -> Optional[List[Row]]:
|
||||
sql = select(music).where(and_(
|
||||
music.c.version == version,
|
||||
music.c.songId == song_id,
|
||||
music.c.chartId == chart_id
|
||||
))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
return result.fetchone()
|
Reference in New Issue
Block a user