def find_waldo(db_file): tbl = "Parts_HIT_ATTRIBUTE" db = DBManager(db_file) meta = db.check_table(tbl) results = db.query_many( f"SELECT * FROM {tbl} WHERE act=202800 OR act=202801 OR act=202802 OR act=202803", tuple(), dict) common = {} for res in results: for k, v in res.items(): if k == "pk" or k in meta.foreign_keys: continue if k not in common: common[k] = {v} else: common[k].add(v) results = db.query_many( f"SELECT * FROM {tbl} WHERE act!=202800 AND act!=202801 AND act!=202802 AND act!=202803", tuple(), dict) for res in results: for k, v in res.items(): if k == "pk" or k in meta.foreign_keys: continue if k in common and v in common[k]: common[k].remove(v) if not common[k]: del common[k] pprint(common)
def transfer_sim_db(dl_sim_db): db = DBManager() db.transfer(dl_sim_db, SIM_TABLE_LIST) db = DBManager(DL9_DB) adv_ele_passives, adv_wep_passives, drg_passives = count_fort_passives( include_album=True) halidom_data = [] for elebonus, wepbonus in itertools.product(adv_ele_passives.items(), adv_wep_passives.items()): halidom_data.append({ "form": 1, "ele": elebonus[0][0], "wep": wepbonus[0][0], "hp": elebonus[1][0] + wepbonus[1][0], "atk": elebonus[1][1] + wepbonus[1][1], }) for drgbonus in drg_passives.items(): halidom_data.append({ "form": 2, "ele": drgbonus[0][0], "wep": None, "hp": drgbonus[1][0], "atk": drgbonus[1][1], }) meta = DBTableMetadata("HalidomBonus") meta.init_from_row(halidom_data[0], auto_pk=True) db.create_table(meta) db.insert_many(meta.name, halidom_data)
def transfer_actions_db(db_file, actions_dir): processed = { PARTS_INDEX.name: [], # PARTS_HITLABEL.name: [], } tablemetas = { PARTS_INDEX.name: PARTS_INDEX, # PARTS_HITLABEL.name: PARTS_HITLABEL, } for filename in tqdm(glob(actions_dir + "/PlayerAction_*.json"), desc="read_actions"): action_id = filename.split("_")[-1].replace(".json", "") with open(filename, "r") as fn: for seq, part in enumerate(json.load(fn)): process_action_part(action_id, seq, part, processed, tablemetas) db = DBManager(db_file) for tbl, meta in tqdm(tablemetas.items(), desc="load_actions"): db.drop_table(tbl) db.create_table(meta) db.insert_many(tbl, processed[tbl], mode=DBManager.REPLACE)
def get_timeattack_data(quest_id): response = urllib.request.urlopen(TIMEATTACK_URL.format(quest_id=quest_id)) if response.code != 200: return res_json = json.load(response) if res_json["data_headers"]["result_code"] == 0: return data = res_json["data"] timestamp = data["ranking"]["update_time"] raw_outfile = os.path.join(OUTPUT_DIR, f"{quest_id}_raw_{timestamp}.json") with open(raw_outfile, "w") as fn: json.dump(data, fn, indent=2, ensure_ascii=False, sort_keys=True) print(f"Wrote {raw_outfile}") dbm = DBManager() iconmap_outfile = os.path.join(OUTPUT_DIR, f"iconmap_{timestamp}.json") if os.path.isfile(iconmap_outfile): with open(iconmap_outfile, "r") as fn: seen_icons = json.load(fn) seen_icons.update({"": ("Empty", None), None: ("Empty", None)}) else: seen_icons = {"": ("Empty", None), None: ("Empty", None)} for entry in tqdm(data["ranking"]["ranking_data"], desc="icon to names"): for player_slots in entry["player_list"]: convert_player_slots(player_slots, dbm, seen_icons) converted_outfile = os.path.join(OUTPUT_DIR, f"{quest_id}_converted_{timestamp}.json") with open(converted_outfile, "w") as fn: json.dump(data, fn, indent=2, ensure_ascii=False, sort_keys=True) print(f"Wrote {converted_outfile}") del seen_icons[""] del seen_icons[None] with open(iconmap_outfile, "w") as fn: json.dump(seen_icons, fn, indent=2, sort_keys=True) print(f"Wrote {iconmap_outfile}") return timestamp
LABEL_PATTERNS_JP = { r'^master$': 'master', r'^actions$': 'actions', r'^characters/motion': 'characters_motion', r'characters/motion/animationclips$': 'characters_motion', r'^dragon/motion': 'dragon_motion', } if __name__ == '__main__': parser = argparse.ArgumentParser(description='Import data to database.') parser.add_argument('--do_prep', help='Do downloading and extracting of assets', action='store_true') parser.add_argument('-o', type=str, help='output file', default='dl.sqlite') args = parser.parse_args() if args.do_prep: ex = Extractor(MANIFEST_JP, MANIFEST_EN, stdout_log=True) ex.download_and_extract_all(LABEL_PATTERNS_JP, region='jp') ex.download_and_extract_all(LABEL_PATTERNS_EN, region='en') in_dir = '_extract' db = DBManager(args.o) load_master(db, os.path.join(in_dir, EN, MASTER)) load_json(db, os.path.join(in_dir, JP, MASTER, TEXT_LABEL), 'TextLabelJP') load_actions(db, os.path.join(in_dir, JP, ACTIONS)) load_character_motion(db, os.path.join(in_dir, JP, CHARACTERS_MOTION)) load_dragon_motion(db, os.path.join(in_dir, JP, DRAGON_MOTION))
"_TextJP": None, "_TextCN": None, } def load_ui_skill_detail(db, path): skilldetails = {} for region in ("en", "jp", "cn"): for root, _, files in os.walk(os.path.join(path, region, "skilldetail")): for fn in tqdm(files, desc=f"{region}_detail"): for sd_info in build_skilldetail_row(root, fn): sd_text, sd_row = sd_info if sd_row["_Id"] not in skilldetails: skilldetails[sd_row["_Id"]] = sd_row if region == "en": skilldetails[sd_row["_Id"]]["_Text"] = sd_text else: skilldetails[ sd_row["_Id"]][f"_Text{region.upper()}"] = sd_text tablename = "SkillDetail" if not db.check_table("SkillDetail"): metadata = DBTableMetadata(tablename, pk="_Id", field_type=FIELD_TYPE) db.create_table(metadata) db.insert_many(tablename, skilldetails.values(), mode=DBManager.REPLACE) if __name__ == "__main__": db = DBManager() load_ui_skill_detail(db, "./_ex_sim")
def count_fort_passives(include_album=True): dbm = DBManager() adv_ele_passives = {(idx, ele): [0, 0] for idx, ele in ELEMENTS.items()} if include_album: for mlb, factor in ALBUM_BONUS_ADV.items(): for res in dbm.query_many(COUNT_ADV_BY_MAX_LIMIT_BREAK, (mlb, ), dict): try: eletype = res["_ElementalType"] elename = ELEMENTS[eletype] except KeyError: continue adv_ele_passives[(eletype, elename)][0] += round( res["_Count"] * factor, 1) adv_ele_passives[(eletype, elename)][1] += round( res["_Count"] * factor, 1) adv_wep_passives = {(idx, wep): [0, 0] for idx, wep in WEAPON_TYPES.items()} for res in dbm.query_many(COUNT_WEAPON_BONUS, tuple(), dict): try: weptype = res["_WeaponType"] wepname = WEAPON_TYPES[weptype] except KeyError: continue adv_wep_passives[(weptype, wepname)][0] += res["_Bonus"] adv_wep_passives[(weptype, wepname)][1] += res["_Bonus"] drg_passives = {(idx, ele): [0, 0] for idx, ele in ELEMENTS.items()} if include_album: for mlb, factor in ALBUM_BONUS_DRG.items(): for res in dbm.query_many(COUNT_DRG_BY_MAX_LIMIT_BREAK, (mlb, ), dict): try: eletype = res["_ElementalType"] elename = ELEMENTS[eletype] except KeyError: continue drg_passives[(eletype, elename)][0] += round( res["_Count"] * factor["hp"], 1) drg_passives[(eletype, elename)][1] += round( res["_Count"] * factor["atk"], 1) for res in dbm.query_many(COUNT_HALIDOM, (), dict): if res["_EffectId"] == 1: passive_dict = adv_wep_passives passive_types = WEAPON_TYPES elif res["_EffectId"] == 2: passive_dict = adv_ele_passives passive_types = ELEMENTS elif res["_EffectId"] == 6: passive_dict = drg_passives passive_types = ELEMENTS mult = 1 if "Altar" in res["_Name"] or "Dojo" in res["_Name"]: mult = 2 for eff in (res["_EffType1"], res["_EffType2"]): if not eff: continue passive_dict[(eff, passive_types[eff])][0] += res["_EffArgs1"] * mult passive_dict[(eff, passive_types[eff])][1] += res["_EffArgs2"] * mult return adv_ele_passives, adv_wep_passives, drg_passives