mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-02-15 04:07:29 +08:00
Merge branch 'refs/heads/develop' into prism_plus_support
# Conflicts: # core/data/alembic/versions/16f34bf7b968_mai2_kaleidx_scope_support.py # core/data/alembic/versions/5cf98cfe52ad_mai2_prism_support.py # core/data/alembic/versions/5d7b38996e67_mai2_prism_support.py # core/data/alembic/versions/bdf710616ba4_mai2_add_prism_playlog_support.py # titles/mai2/index.py # titles/mai2/prism.py # titles/mai2/read.py # titles/mai2/schema/static.py
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from typing import Optional
|
||||
from core.utils import floor_to_nearest_005
|
||||
|
||||
class Mai2Constants:
|
||||
GRADE = {
|
||||
"D": 0,
|
||||
@@ -86,7 +89,57 @@ class Mai2Constants:
|
||||
"maimai DX PRiSM",
|
||||
"maimai DX PRiSM PLUS"
|
||||
)
|
||||
KALEIDXSCOPE_KEY_CONDITION={
|
||||
1: [11009, 11008, 11100, 11097, 11098, 11099, 11163, 11162, 11161, 11228, 11229, 11231, 11463, 11464, 11465, 11538, 11539, 11541, 11620, 11622, 11623, 11737, 11738, 11164, 11230, 11466, 11540, 11621, 11739],
|
||||
#青の扉: Played 29 songs
|
||||
2: [11102, 11234, 11300, 11529, 11542, 11612],
|
||||
#白の扉: set Frame as "Latent Kingdom" (459504), play 3 or 4 songs by the composer 大国奏音 in 1 pc
|
||||
3: [],
|
||||
#紫の扉: need to enter redeem code 51090942171709440000
|
||||
4: [11023, 11106, 11221, 11222, 11300, 11374, 11458, 11523, 11619, 11663, 11746],
|
||||
#青の扉: Played 11 songs
|
||||
}
|
||||
MAI_VERSION_LUT = {
|
||||
"100": VER_MAIMAI,
|
||||
"110": VER_MAIMAI_PLUS,
|
||||
"120": VER_MAIMAI_GREEN,
|
||||
"130": VER_MAIMAI_GREEN_PLUS,
|
||||
"140": VER_MAIMAI_ORANGE,
|
||||
"150": VER_MAIMAI_ORANGE_PLUS,
|
||||
"160": VER_MAIMAI_PINK,
|
||||
"170": VER_MAIMAI_PINK_PLUS,
|
||||
"180": VER_MAIMAI_MURASAKI,
|
||||
"185": VER_MAIMAI_MURASAKI_PLUS,
|
||||
"190": VER_MAIMAI_MILK,
|
||||
"195": VER_MAIMAI_MILK_PLUS,
|
||||
"197": VER_MAIMAI_FINALE,
|
||||
}
|
||||
|
||||
MAI2_VERSION_LUT = {
|
||||
"100": VER_MAIMAI_DX,
|
||||
"105": VER_MAIMAI_DX_PLUS,
|
||||
"110": VER_MAIMAI_DX_SPLASH,
|
||||
"115": VER_MAIMAI_DX_SPLASH_PLUS,
|
||||
"120": VER_MAIMAI_DX_UNIVERSE,
|
||||
"125": VER_MAIMAI_DX_UNIVERSE_PLUS,
|
||||
"130": VER_MAIMAI_DX_FESTIVAL,
|
||||
"135": VER_MAIMAI_DX_FESTIVAL_PLUS,
|
||||
"140": VER_MAIMAI_DX_BUDDIES,
|
||||
"145": VER_MAIMAI_DX_BUDDIES_PLUS,
|
||||
"150": VER_MAIMAI_DX_PRISM
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def game_ver_to_string(cls, ver: int):
|
||||
""" Takes an internal game version (ex 13 for maimai DX) and returns a the full name of the version """
|
||||
return cls.VERSION_STRING[ver]
|
||||
|
||||
@classmethod
|
||||
def int_ver_to_game_ver(cls, ver: int, is_dx = True) -> Optional[int]:
|
||||
""" Takes an int ver (ex 100 for 1.00) and returns an internal game version """
|
||||
if is_dx:
|
||||
return cls.MAI2_VERSION_LUT.get(str(floor_to_nearest_005(ver)), None)
|
||||
else:
|
||||
if ver >= 197:
|
||||
return cls.VER_MAIMAI_FINALE
|
||||
return cls.MAI_VERSION_LUT.get(str(floor_to_nearest_005(ver)), None)
|
||||
|
||||
@@ -32,7 +32,6 @@ from .festivalplus import Mai2FestivalPlus
|
||||
from .buddies import Mai2Buddies
|
||||
from .buddiesplus import Mai2BuddiesPlus
|
||||
from .prism import Mai2Prism
|
||||
from .prismplus import Mai2PrismPlus
|
||||
|
||||
|
||||
class Mai2Servlet(BaseServlet):
|
||||
@@ -311,7 +310,7 @@ class Mai2Servlet(BaseServlet):
|
||||
elif version >= 140 and version < 145: # BUDDiES
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_BUDDIES
|
||||
elif version >= 145 and version < 150: # BUDDiES PLUS
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_BUDDIES_PLUS,
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_BUDDIES_PLUS
|
||||
elif version >= 150 and version < 155:
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_PRISM
|
||||
elif version >= 155:
|
||||
@@ -337,7 +336,7 @@ class Mai2Servlet(BaseServlet):
|
||||
elif version >= 140 and version < 145: # BUDDiES
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_BUDDIES
|
||||
elif version >= 145 and version < 150: # BUDDiES PLUS
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_BUDDIES_PLUS,
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_BUDDIES_PLUS
|
||||
elif version >= 150 and version < 155:
|
||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_PRISM
|
||||
elif version >= 155:
|
||||
|
||||
@@ -43,27 +43,52 @@ class Mai2Prism(Mai2BuddiesPlus):
|
||||
{"gateId": 2, "phaseId": 6},
|
||||
{"gateId": 3, "phaseId": 6},
|
||||
{"gateId": 4, "phaseId": 6},
|
||||
{"gateId": 5, "phaseId": 6},
|
||||
{"gateId": 6, "phaseId": 6}
|
||||
]
|
||||
}
|
||||
|
||||
async def handle_get_user_kaleidx_scope_api_request(self, data: Dict) -> Dict:
|
||||
# kaleidxscope keyget condition judgement
|
||||
# player may get key before GateFound
|
||||
for gate in range(1,7):
|
||||
condition_list = await self.data.static.get_kaleidxscope_condition(gate)
|
||||
if not condition_list:
|
||||
continue
|
||||
condition_satisfy = 0
|
||||
for condition in condition_list:
|
||||
score_list = await self.data.score.get_best_scores(user_id=data["userId"], song_id=condition[3])
|
||||
if score_list:
|
||||
condition_satisfy = condition_satisfy + 1
|
||||
if len(condition_list) == condition_satisfy:
|
||||
new_kaleidxscope = {'gateId': gate, "isKeyFound": True}
|
||||
await self.data.score.put_user_kaleidxscope(data["userId"], new_kaleidxscope)
|
||||
for gate in range(1,5):
|
||||
if gate == 1 or gate == 4:
|
||||
condition_satisfy = 0
|
||||
for condition in Mai2Constants.KALEIDXSCOPE_KEY_CONDITION[gate]:
|
||||
score_list = await self.data.score.get_best_scores(user_id=data["userId"], song_id=condition)
|
||||
if score_list:
|
||||
condition_satisfy = condition_satisfy + 1
|
||||
if len(Mai2Constants.KALEIDXSCOPE_KEY_CONDITION[gate]) == condition_satisfy:
|
||||
new_kaleidxscope = {'gateId': gate, "isKeyFound": True}
|
||||
await self.data.score.put_user_kaleidxscope(data["userId"], new_kaleidxscope)
|
||||
|
||||
elif gate == 2:
|
||||
user_profile = await self.data.profile.get_profile_detail(user_id=data["userId"], version=self.version)
|
||||
user_frame = user_profile["frameId"]
|
||||
if user_frame == 459504:
|
||||
playlogs = await self.data.score.get_playlogs(user_id=data["userId"], idx=0, limit=0)
|
||||
|
||||
playlog_dict = {}
|
||||
for playlog in playlogs:
|
||||
playlog_id = playlog["playlogId"]
|
||||
if playlog_id not in playlog_dict:
|
||||
playlog_dict[playlog_id] = []
|
||||
playlog_dict[playlog_id].append(playlog["musicId"])
|
||||
valid_playlogs = []
|
||||
allowed_music = set(Mai2Constants.KALEIDXSCOPE_KEY_CONDITION[2])
|
||||
for playlog_id, music_ids in playlog_dict.items():
|
||||
|
||||
if len(music_ids) != len(set(music_ids)):
|
||||
continue
|
||||
all_valid = True
|
||||
for mid in music_ids:
|
||||
if mid not in allowed_music:
|
||||
all_valid = False
|
||||
break
|
||||
if all_valid:
|
||||
valid_playlogs.append(playlog_id)
|
||||
|
||||
if valid_playlogs:
|
||||
new_kaleidxscope = {'gateId': 2, "isKeyFound": True}
|
||||
await self.data.score.put_user_kaleidxscope(data["userId"], new_kaleidxscope)
|
||||
|
||||
kaleidxscope = await self.data.score.get_user_kaleidxscope_list(data["userId"])
|
||||
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
from decimal import Decimal
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Dict, List, Optional
|
||||
from Crypto.Cipher import AES
|
||||
import zlib
|
||||
import codecs
|
||||
|
||||
from core.config import CoreConfig
|
||||
from core.data import Data
|
||||
from read import BaseReader
|
||||
from titles.mai2.const import Mai2Constants
|
||||
from titles.mai2.database import Mai2Data
|
||||
|
||||
|
||||
class Mai2Reader(BaseReader):
|
||||
def __init__(
|
||||
self,
|
||||
@@ -46,14 +42,11 @@ class Mai2Reader(BaseReader):
|
||||
|
||||
for dir in data_dirs:
|
||||
self.logger.info(f"Read from {dir}")
|
||||
await self.get_events(f"{dir}/event")
|
||||
this_opt_id = await self.read_opt_info(dir)
|
||||
await self.get_events(f"{dir}/event", this_opt_id)
|
||||
await self.disable_events(f"{dir}/information", f"{dir}/scoreRanking")
|
||||
#await self.read_music(f"{dir}/music")
|
||||
await self.read_tickets(f"{dir}/ticket")
|
||||
|
||||
if self.version >= Mai2Constants.VER_MAIMAI_DX_PRISM:
|
||||
for dir in data_dirs:
|
||||
await self.read_kaleidxscope_condition(f"{dir}/kaleidxScopeKeyCondition")
|
||||
await self.read_music(f"{dir}/music", this_opt_id)
|
||||
await self.read_tickets(f"{dir}/ticket", this_opt_id)
|
||||
|
||||
else:
|
||||
if not os.path.exists(f"{self.bin_dir}/tables"):
|
||||
@@ -183,7 +176,7 @@ class Mai2Reader(BaseReader):
|
||||
self.logger.warning("Failed load table content, skipping")
|
||||
return
|
||||
|
||||
async def get_events(self, base_dir: str) -> None:
|
||||
async def get_events(self, base_dir: str, opt_id: int = None) -> None:
|
||||
self.logger.info(f"Reading events from {base_dir}...")
|
||||
|
||||
for root, dirs, files in os.walk(base_dir):
|
||||
@@ -197,7 +190,7 @@ class Mai2Reader(BaseReader):
|
||||
event_type = int(troot.find("infoType").text)
|
||||
|
||||
await self.data.static.put_game_event(
|
||||
self.version, event_type, id, name
|
||||
self.version, event_type, id, name, opt_id
|
||||
)
|
||||
self.logger.info(f"Added event {id}...")
|
||||
|
||||
@@ -259,7 +252,7 @@ class Mai2Reader(BaseReader):
|
||||
await self.data.static.toggle_game_event(self.version, event_id, toggle=False)
|
||||
self.logger.info(f"Disabled event {event_id}...")
|
||||
|
||||
async def read_music(self, base_dir: str) -> None:
|
||||
async def read_music(self, base_dir: str, opt_id: int = None) -> None:
|
||||
self.logger.info(f"Reading music from {base_dir}...")
|
||||
|
||||
for root, dirs, files in os.walk(base_dir):
|
||||
@@ -300,13 +293,14 @@ class Mai2Reader(BaseReader):
|
||||
added_ver,
|
||||
diff_num,
|
||||
note_designer,
|
||||
opt_id
|
||||
)
|
||||
|
||||
self.logger.info(
|
||||
f"Added music id {song_id} chart {chart_id}"
|
||||
)
|
||||
|
||||
async def read_tickets(self, base_dir: str) -> None:
|
||||
async def read_tickets(self, base_dir: str, opt_id: int = None) -> None:
|
||||
self.logger.info(f"Reading tickets from {base_dir}...")
|
||||
|
||||
for root, dirs, files in os.walk(base_dir):
|
||||
@@ -321,7 +315,7 @@ class Mai2Reader(BaseReader):
|
||||
price = int(troot.find("creditNum").text)
|
||||
|
||||
await self.data.static.put_game_ticket(
|
||||
self.version, id, ticket_type, price, name
|
||||
self.version, id, ticket_type, price, name, opt_id
|
||||
)
|
||||
self.logger.info(f"Added ticket {id}...")
|
||||
|
||||
@@ -346,30 +340,50 @@ class Mai2Reader(BaseReader):
|
||||
return
|
||||
# TODO
|
||||
|
||||
async def read_opt_info(self, directory: str) -> Optional[int]:
|
||||
datacfg_file = os.path.join(directory, "DataConfig.xml")
|
||||
if not os.path.exists(datacfg_file):
|
||||
self.logger.warning(f"{datacfg_file} does not contain DataConfig.xml, opt info will not be read")
|
||||
return None
|
||||
|
||||
with open(datacfg_file, encoding="utf-8") as f:
|
||||
troot = ET.fromstring(f.read())
|
||||
|
||||
if troot.find("version") is None:
|
||||
self.logger.warning(f"{directory}/DataConfig.xml contains no Version section, opt info will not be read")
|
||||
return None
|
||||
|
||||
ver_maj = troot.find("version/major")
|
||||
ver_min = troot.find("version/minor")
|
||||
ver_rel = troot.find("version/release")
|
||||
cm_maj = troot.find("cardMakerVersion/major")
|
||||
cm_min = troot.find("cardMakerVersion/minor")
|
||||
cm_rel = troot.find("cardMakerVersion/release")
|
||||
|
||||
if ver_maj is None: # Probably not worth checking that the other sections exist
|
||||
self.logger.warning(f"{datacfg_file} contains no major item in the Version section, opt info will not be read")
|
||||
return None
|
||||
|
||||
async def read_kaleidxscope_condition(self, base_dir: str) -> None :
|
||||
self.logger.info(f"Reading KaleidxScope Key Conditions from {base_dir}...")
|
||||
if ver_min is None: # Probably not worth checking that the other sections exist
|
||||
self.logger.warning(f"{datacfg_file} contains no minor item in the Version section, opt info will not be read")
|
||||
return None
|
||||
|
||||
for root, dirs, files in os.walk(base_dir):
|
||||
for dir in dirs:
|
||||
if os.path.exists(f"{root}/{dir}/KaleidxScopeKeyCondition.xml"):
|
||||
with open(f"{root}/{dir}/KaleidxScopeKeyCondition.xml", encoding="utf-8") as f:
|
||||
troot = ET.fromstring(f.read())
|
||||
if ver_rel is None: # Probably not worth checking that the other sections exist
|
||||
self.logger.warning(f"{datacfg_file} contains no release item in the Version section, opt info will not be read")
|
||||
return None
|
||||
|
||||
opt_folder = os.path.basename(os.path.normpath(directory))
|
||||
opt_id = await self.data.static.get_opt_by_version_folder(self.version, opt_folder)
|
||||
|
||||
if not opt_id:
|
||||
opt_id = await self.data.static.put_opt(self.version, opt_folder, int(ver_rel.text), int(cm_rel.text) if cm_rel is not None else None)
|
||||
if not opt_id:
|
||||
self.logger.error(f"Failed to put opt folder info for {opt_folder}")
|
||||
return None
|
||||
else:
|
||||
opt_id = opt_id['id']
|
||||
|
||||
condition_id = int(troot.find("name").find("id").text)
|
||||
condition_name = troot.find("name").find("str").text
|
||||
|
||||
music_list = troot.find("musicIds").find("list")
|
||||
for music in music_list.findall("StringID"):
|
||||
music_id = int(music.find("id").text)
|
||||
music_name = music.find("str").text
|
||||
|
||||
await self.data.static.put_kaleidxscope_condition(
|
||||
condition_id,
|
||||
condition_name,
|
||||
music_id,
|
||||
music_name
|
||||
)
|
||||
self.logger.info(
|
||||
f"Add music {music_id} for condition {condition_id}"
|
||||
)
|
||||
self.logger.info(
|
||||
f"Opt folder {opt_folder} (Database ID {opt_id}) contains v{ver_maj.text}.{ver_min.text}.{ver_rel.text} (cm v{cm_maj.text if cm_maj is not None else 'None'}.{cm_min.text if cm_min is not None else 'None'}.{cm_rel.text if cm_rel is not None else 'None'})"
|
||||
)
|
||||
return opt_id
|
||||
|
||||
@@ -728,10 +728,11 @@ class Mai2ItemData(BaseData):
|
||||
# Do an anti-join with the mai2_item_item table to exclude any
|
||||
# items the users have already owned.
|
||||
if exclude_owned:
|
||||
sql = sql.join(
|
||||
sql = sql.outerjoin(
|
||||
item,
|
||||
(present.c.itemKind == item.c.itemKind)
|
||||
& (present.c.itemId == item.c.itemId)
|
||||
& (item.c.user == user_id)
|
||||
)
|
||||
condition &= (item.c.itemKind.is_(None) & item.c.itemId.is_(None))
|
||||
|
||||
|
||||
@@ -2,13 +2,28 @@ from core.data.schema.base import BaseData, metadata
|
||||
|
||||
from typing import Optional, Dict, List
|
||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, Float
|
||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, BIGINT, Float, INTEGER, BOOLEAN, VARCHAR
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.sql import func, select
|
||||
from sqlalchemy.engine import Row
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
from sqlalchemy.sql.functions import coalesce
|
||||
from datetime import datetime
|
||||
|
||||
opts = Table(
|
||||
"mai2_static_opt",
|
||||
metadata,
|
||||
Column("id", BIGINT, primary_key=True, nullable=False),
|
||||
Column("version", INTEGER, nullable=False),
|
||||
Column("name", VARCHAR(4), nullable=False), # Axxx
|
||||
Column("sequence", INTEGER, nullable=False), # release in DataConfig.xml
|
||||
Column("cmReleaseVer", INTEGER, nullable=False),
|
||||
Column("whenRead", TIMESTAMP, nullable=False, server_default=func.now()),
|
||||
Column("isEnable", BOOLEAN, nullable=False, server_default="1"),
|
||||
UniqueConstraint("version", "name", name="mai2_static_opt_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
event = Table(
|
||||
"mai2_static_event",
|
||||
metadata,
|
||||
@@ -19,6 +34,7 @@ event = Table(
|
||||
Column("name", String(255)),
|
||||
Column("startDate", TIMESTAMP, server_default=func.now()),
|
||||
Column("enabled", Boolean, server_default="1"),
|
||||
Column("opt", ForeignKey("mai2_static_opt.id", ondelete="SET NULL", onupdate="cascade")),
|
||||
UniqueConstraint("version", "eventId", "type", name="mai2_static_event_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
@@ -37,6 +53,7 @@ music = Table(
|
||||
Column("addedVersion", String(255)),
|
||||
Column("difficulty", Float),
|
||||
Column("noteDesigner", String(255)),
|
||||
Column("opt", ForeignKey("mai2_static_opt.id", ondelete="SET NULL", onupdate="cascade")),
|
||||
UniqueConstraint("songId", "chartId", "version", name="mai2_static_music_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
@@ -51,6 +68,7 @@ ticket = Table(
|
||||
Column("name", String(255)),
|
||||
Column("price", Integer, server_default="1"),
|
||||
Column("enabled", Boolean, server_default="1"),
|
||||
Column("opt", ForeignKey("mai2_static_opt.id", ondelete="SET NULL", onupdate="cascade")),
|
||||
UniqueConstraint("version", "ticketId", name="mai2_static_ticket_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
@@ -67,34 +85,25 @@ cards = Table(
|
||||
Column("noticeStartDate", TIMESTAMP, server_default="2018-01-01 00:00:00.0"),
|
||||
Column("noticeEndDate", TIMESTAMP, server_default="2038-01-01 00:00:00.0"),
|
||||
Column("enabled", Boolean, server_default="1"),
|
||||
Column("opt", ForeignKey("cm_static_opts.id", ondelete="SET NULL", onupdate="cascade")),
|
||||
UniqueConstraint("version", "cardId", "cardName", name="mai2_static_cards_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
kaleidxscope_condition = Table(
|
||||
"mai2_static_kaleidxscope_condition",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("conditionId", Integer),
|
||||
Column("conditionName", String(255)),
|
||||
Column("songId", Integer),
|
||||
Column("songName", String(255)),
|
||||
UniqueConstraint("conditionId", "conditionName", "songId", "songName", name="mai2_static_kaleidxscope_uk"),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
class Mai2StaticData(BaseData):
|
||||
async def put_game_event(
|
||||
self, version: int, type: int, event_id: int, name: str
|
||||
self, version: int, type: int, event_id: int, name: str, opt_id: int = None
|
||||
) -> Optional[int]:
|
||||
sql = insert(event).values(
|
||||
version=version,
|
||||
type=type,
|
||||
eventId=event_id,
|
||||
name=name,
|
||||
opt=coalesce(event.c.opt, opt_id)
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(eventId=event_id)
|
||||
conflict = sql.on_duplicate_key_update(eventId=event_id, opt=coalesce(event.c.opt, opt_id))
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
@@ -147,6 +156,7 @@ class Mai2StaticData(BaseData):
|
||||
added_version: str,
|
||||
difficulty: float,
|
||||
note_designer: str,
|
||||
opt_id: int = None
|
||||
) -> None:
|
||||
sql = insert(music).values(
|
||||
version=version,
|
||||
@@ -159,6 +169,7 @@ class Mai2StaticData(BaseData):
|
||||
addedVersion=added_version,
|
||||
difficulty=difficulty,
|
||||
noteDesigner=note_designer,
|
||||
opt=coalesce(music.c.opt, opt_id)
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
@@ -169,6 +180,7 @@ class Mai2StaticData(BaseData):
|
||||
addedVersion=added_version,
|
||||
difficulty=difficulty,
|
||||
noteDesigner=note_designer,
|
||||
opt=coalesce(music.c.opt, opt_id)
|
||||
)
|
||||
|
||||
result = await self.execute(conflict)
|
||||
@@ -184,6 +196,7 @@ class Mai2StaticData(BaseData):
|
||||
ticket_type: int,
|
||||
ticket_price: int,
|
||||
name: str,
|
||||
opt_id: int = None
|
||||
) -> Optional[int]:
|
||||
sql = insert(ticket).values(
|
||||
version=version,
|
||||
@@ -191,11 +204,10 @@ class Mai2StaticData(BaseData):
|
||||
kind=ticket_type,
|
||||
price=ticket_price,
|
||||
name=name,
|
||||
opt=coalesce(ticket.c.opt, opt_id)
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(price=ticket_price)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(price=ticket_price)
|
||||
conflict = sql.on_duplicate_key_update(price=ticket_price, opt=coalesce(ticket.c.opt, opt_id))
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
@@ -240,12 +252,12 @@ class Mai2StaticData(BaseData):
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
async def put_card(self, version: int, card_id: int, card_name: str, **card_data) -> int:
|
||||
async def put_card(self, version: int, card_id: int, card_name: str, opt_id: int = None, **card_data) -> int:
|
||||
sql = insert(cards).values(
|
||||
version=version, cardId=card_id, cardName=card_name, **card_data
|
||||
version=version, cardId=card_id, cardName=card_name, opt=coalesce(cards.c.opt, opt_id) **card_data
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(**card_data)
|
||||
conflict = sql.on_duplicate_key_update(opt=coalesce(cards.c.opt, opt_id), **card_data)
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
@@ -276,34 +288,84 @@ class Mai2StaticData(BaseData):
|
||||
if not result:
|
||||
self.logger.error(f"Failed to update event {table_id} - {is_enable} {start_date}")
|
||||
|
||||
# new in prism
|
||||
async def put_kaleidxscope_condition(
|
||||
self,
|
||||
condition_id: int,
|
||||
condition_name: str,
|
||||
music_id: int,
|
||||
music_name: str
|
||||
) -> Optional[int]:
|
||||
sql = insert(kaleidxscope_condition).values(
|
||||
conditionId = condition_id,
|
||||
conditionName = condition_name,
|
||||
songId = music_id,
|
||||
songName = music_name,
|
||||
)
|
||||
|
||||
|
||||
conflict = sql.on_duplicate_key_update(conditionName=condition_name, songName=music_name)
|
||||
async def put_opt(self, version: int, folder: str, sequence: int, cm_seq: int = None) -> Optional[int]:
|
||||
sql = insert(opts).values(version=version, name=folder, sequence=sequence, cmReleaseVer=cm_seq)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(sequence=sequence, whenRead=datetime.now())
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.warning(
|
||||
f"put_kaleidxscope_condition: Failed to insert kaleidxScope Key Condition! conditionID {condition_id} songId {music_id}"
|
||||
)
|
||||
self.logger.warning(f"Failed to insert opt! version {version} folder {folder} sequence {sequence}")
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_kaleidxscope_condition(self, condition_id: int) -> None:
|
||||
sql = kaleidxscope_condition.select(kaleidxscope_condition.c.conditionId == condition_id)
|
||||
result = await self.execute(sql)
|
||||
async def get_opt_by_version_folder(self, version: int, folder: str) -> Optional[Row]:
|
||||
result = await self.execute(opts.select(and_(
|
||||
opts.c.version == version,
|
||||
opts.c.name == folder,
|
||||
)))
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
return result.fetchone()
|
||||
|
||||
async def get_opt_by_version_sequence(self, version: int, sequence: str) -> Optional[Row]:
|
||||
result = await self.execute(opts.select(and_(
|
||||
opts.c.version == version,
|
||||
opts.c.sequence == sequence,
|
||||
)))
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
async def get_opts_by_version(self, version: int) -> Optional[List[Row]]:
|
||||
result = await self.execute(opts.select(opts.c.version == version))
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
async def get_opts_enabled_by_version(self, version: int) -> Optional[List[Row]]:
|
||||
result = await self.execute(opts.select(and_(
|
||||
opts.c.version == version,
|
||||
opts.c.isEnable == True,
|
||||
)))
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
async def get_latest_enabled_opt_by_version(self, version: int) -> Optional[Row]:
|
||||
result = await self.execute(
|
||||
opts.select(and_(
|
||||
opts.c.version == version,
|
||||
opts.c.isEnable == True,
|
||||
)).order_by(opts.c.sequence.desc())
|
||||
)
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
async def get_opts(self) -> Optional[List[Row]]:
|
||||
result = await self.execute(opts.select())
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
async def get_opts(self) -> Optional[List[Row]]:
|
||||
result = await self.execute(opts.select())
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
async def set_opt_enabled(self, opt_id: int, enabled: bool) -> bool:
|
||||
result = await self.execute(opts.update(opts.c.id == opt_id).values(isEnable=enabled))
|
||||
|
||||
if result is None:
|
||||
self.logger.error(f"Failed to set opt enabled status to {enabled} for opt {opt_id}")
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user