From 57d050273e3986eaee6772f99bfa5739abdd4553 Mon Sep 17 00:00:00 2001 From: drmext <71258889+drmext@users.noreply.github.com> Date: Tue, 24 Mar 2026 22:50:16 +0000 Subject: [PATCH] Fix --- activate-venv.bat | 5 ++ modules/ddr/playdata_3.py | 7 +- modules/ddr/playerdata.py | 2 + modules/ddr/playerdata_2.py | 2 + utils/db/README.md | 4 +- utils/db/import_ddr_spice_automap.py | 96 ++++++++++++++++++---------- 6 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 activate-venv.bat diff --git a/activate-venv.bat b/activate-venv.bat new file mode 100644 index 0000000..e81c3ed --- /dev/null +++ b/activate-venv.bat @@ -0,0 +1,5 @@ +@echo off + +cd /d %~dp0 + +start .venv\Scripts\activate.bat diff --git a/modules/ddr/playdata_3.py b/modules/ddr/playdata_3.py index 519e239..36b442c 100644 --- a/modules/ddr/playdata_3.py +++ b/modules/ddr/playdata_3.py @@ -233,7 +233,7 @@ async def playdata_3_playerdata_load(request: Request): difficulty = int(record["difficulty"]) score = int(record["score"]) flare = int(record.get("flare_force", 0)) - if flare == 0: + if flare in (-1, 0): for k, v in flares: if score >= k: flare = v @@ -644,7 +644,10 @@ async def playdata_3_playerdata_save(request: Request): & (where("difficulty") == difficulty) & (where("score") == max(score, best.get("score", score))) ) - best_score_data["ghostid"] = ghostid.doc_id + if ghostid == None: + best_score_data["ghostid"] = -1 + else: + best_score_data["ghostid"] = ghostid.doc_id db.table("ddr_scores_best").upsert( best_score_data, diff --git a/modules/ddr/playerdata.py b/modules/ddr/playerdata.py index 3c74f1a..dbcbcdb 100644 --- a/modules/ddr/playerdata.py +++ b/modules/ddr/playerdata.py @@ -58,6 +58,8 @@ async def playerdata_usergamedata_advanced(request: Request): if "ddr_id" not in all_profiles_for_card: ddr_id = random.randint(10000000, 99999999) all_profiles_for_card["ddr_id"] = ddr_id + else: + ddr_id = all_profiles_for_card["ddr_id"] all_profiles_for_card["version"][str(game_version)] = { "game_version": game_version, diff --git a/modules/ddr/playerdata_2.py b/modules/ddr/playerdata_2.py index 100a5f7..1d6eac1 100644 --- a/modules/ddr/playerdata_2.py +++ b/modules/ddr/playerdata_2.py @@ -58,6 +58,8 @@ async def playerdata_2_usergamedata_advanced(request: Request): if "ddr_id" not in all_profiles_for_card: ddr_id = random.randint(10000000, 99999999) all_profiles_for_card["ddr_id"] = ddr_id + else: + ddr_id = all_profiles_for_card["ddr_id"] all_profiles_for_card["version"][str(game_version)] = { "game_version": game_version, diff --git a/utils/db/README.md b/utils/db/README.md index ceda409..0f86231 100644 --- a/utils/db/README.md +++ b/utils/db/README.md @@ -29,9 +29,9 @@ Instructions: ### [import_ddr_spice_automap.py](import_ddr_spice_automap.py) -Example: `python utils\db\import_ddr_spice_automap.py --automap_xml automap_0.xml --version 19 --monkey_db db.json --ddr_id 12345678` +Example: `python utils\db\import_ddr_spice_automap.py --automap_xml automap_0.xml --version 3 --monkey_db db.json --ddr_id 12345678` -- `--version` 19 for A20P or 20 for A3 +- `--version` 1 for A20P, 2 for A3, 3 for WORLD (automap source version, not destination) - `--ddr_id` destination profile in db.json diff --git a/utils/db/import_ddr_spice_automap.py b/utils/db/import_ddr_spice_automap.py index 2f45a88..b6e0413 100644 --- a/utils/db/import_ddr_spice_automap.py +++ b/utils/db/import_ddr_spice_automap.py @@ -24,43 +24,72 @@ def main(automap_xml, version, monkey_db, ddr_id): if profile == None: raise SystemExit(f"ERROR: DDR profile {ddr_id} not in {monkey_db}") - game_version = 19 - if profile["version"].get(str(game_version), None) == None: - raise SystemExit( - f"ERROR: DDR profile {ddr_id} version {game_version} not in {monkey_db}" - ) - - scores = [] with open(automap_xml, "rb") as fp: automap_0 = fp.read().split(b"\n\n") - if version == 19: - playerdata = "playerdata" - else: + if version == 3: + playerdata = "playdata_3" + game_version = 20 + elif version == 2: playerdata = "playerdata_2" + game_version = 19 + elif version == 1: + playerdata = "playerdata" + game_version = 19 + scores = [] scores_xml = False for xml in automap_0: - tree = ET.ElementTree(ET.fromstring(xml.decode(encoding="shift-jis"))) - root = tree.getroot() - if scores_xml: - for music in root.findall(f"{playerdata}/music"): - mcode = int(music.find("mcode").text) - for difficulty, chart in enumerate(music.findall("note")): - if int(chart.find("count").text) > 0: - rank = int(chart.find("rank").text) - clearkind = int(chart.find("clearkind").text) - score = int(chart.find("score").text) + try: + tree = ET.ElementTree(ET.fromstring(xml.decode(encoding="shift-jis"))) + root = tree.getroot() + except: + continue + if version in (1, 2): + if scores_xml: + for music in root.findall(f"{playerdata}/music"): + mcode = int(music.find("mcode").text) + for difficulty, chart in enumerate(music.findall("note")): + c = chart.find("count") + if c == None: + continue + if int(c.text) > 0: + rank = int(chart.find("rank").text) + clearkind = int(chart.find("clearkind").text) + score = int(chart.find("score").text) + scores.append([mcode, difficulty, rank, clearkind, score, -1]) + break + else: + try: + if root.find(f"{playerdata}/data/mode").text == "userload": + if len(root.find(f"{playerdata}/data/refid").text) == 16: + scores_xml = True + except AttributeError: + continue + elif version == 3: + if scores_xml: + for music in root.findall(f"{playerdata}/score"): + mcode = int(music.find("mcode").text) + for x in music.findall("score_single") + music.findall("score_double"): + s = x.find("score_str").text.split(",") + s = [int(val) for val in s] + difficulty = s[0] + 4 if x.tag == "score_double" else s[0] + rank = s[2] + clearkind = s[3] + score = s[4] + # flare = s[6] scores.append([mcode, difficulty, rank, clearkind, score]) - break - else: - try: - if root.find(f"{playerdata}/data/mode").text == "userload": - if len(root.find(f"{playerdata}/data/refid").text) == 16: - scores_xml = True - except AttributeError: - continue + break + else: + try: + a = root.find(f"{playerdata}") + if "method" in a.attrib: + if a.attrib["method"] == "playerdata_load": + if len(root.find(f"{playerdata}/data/refid").text) == 16: + scores_xml = True + except AttributeError: + continue total_count = len(scores) @@ -73,6 +102,7 @@ def main(automap_xml, version, monkey_db, ddr_id): rank = s[2] lamp = s[3] score = s[4] + # flare = s[5] exscore = 0 print( @@ -81,7 +111,6 @@ def main(automap_xml, version, monkey_db, ddr_id): best = db.table("ddr_scores_best").get( (where("ddr_id") == ddr_id) - & (where("game_version") == game_version) & (where("mcode") == mcode) & (where("difficulty") == difficulty) ) @@ -97,14 +126,14 @@ def main(automap_xml, version, monkey_db, ddr_id): "lamp": max(lamp, best.get("lamp", lamp)), "score": max(score, best.get("score", score)), "exscore": max(exscore, best.get("exscore", exscore)), + # "flare_force": max(flare, best.get("flare_force", flare)), } ghostid = db.table("ddr_scores").get( (where("ddr_id") == ddr_id) - & (where("game_version") == game_version) & (where("mcode") == mcode) & (where("difficulty") == difficulty) - & (where("exscore") == best.get("exscore", exscore)) + & (where("score") == max(score, best.get("score", score))) ) if ghostid: best_score_data["ghostid"] = ghostid.doc_id @@ -114,7 +143,6 @@ def main(automap_xml, version, monkey_db, ddr_id): db.table("ddr_scores_best").upsert( best_score_data, (where("ddr_id") == ddr_id) - & (where("game_version") == game_version) & (where("mcode") == mcode) & (where("difficulty") == difficulty), ) @@ -129,8 +157,8 @@ if __name__ == "__main__": parser.add_argument("--automap_xml", help="Input xml file", required=True) parser.add_argument( "--version", - help="19 is A20P, 20 is A3", - default=19, + help="1=A20P, 2=A3, 3=WORLD (automap_xml source version, not destination)", + default=3, type=int, ) parser.add_argument("--monkey_db", help="Output json file", required=True)