def dump_data(args): input_dir = args.input_dir output_dir = args.output_dir save_region_files(output_dir, Server.jp, padtools.regions.japan.server) save_region_files(output_dir, Server.kr, padtools.regions.north_america.server) save_region_files(output_dir, Server.na, padtools.regions.korea.server) if args.image_data_only: exit(0) print('Processing JP') jp_db = merged_database.Database(Server.jp, input_dir) jp_db.load_database(skip_extra=True) print('Processing NA') na_db = merged_database.Database(Server.na, input_dir) na_db.load_database(skip_extra=True) print('Processing KR') kr_db = merged_database.Database(Server.kr, input_dir) kr_db.load_database(skip_extra=True) print('Merging and saving') cross_db = CrossServerDatabase(jp_db, na_db, kr_db) save_cross_database(output_dir, cross_db)
def dump_data(args): input_dir = args.input_dir output_dir = args.output_dir save_region_files(output_dir, Server.jp, padtools.regions.japan.server) save_region_files(output_dir, Server.kr, padtools.regions.north_america.server) save_region_files(output_dir, Server.na, padtools.regions.korea.server) if args.image_data_only: exit(0) print('Processing JP') jp_db = merged_database.Database(Server.jp, input_dir) jp_db.load_database(skip_extra=True) print('Processing NA') na_db = merged_database.Database(Server.na, input_dir) na_db.load_database(skip_extra=True) print('Processing KR') kr_db = merged_database.Database(Server.kr, input_dir) kr_db.load_database(skip_extra=True) print('Merging and saving') if args.server.lower() == "jp": server = Server.jp elif args.server.lower() == "na": server = Server.na elif args.server.lower() == "kr": server = Server.kr else: raise ValueError("Server must be JP, NA, or KR") cross_db = CrossServerDatabase(jp_db, na_db, kr_db, server) save_cross_database(output_dir, cross_db)
def run(args): behavior_data_dir = os.path.join(args.output_dir, 'behavior_data') os.makedirs(behavior_data_dir, exist_ok=True) behavior_text_dir = os.path.join(args.output_dir, 'behavior_text') os.makedirs(behavior_text_dir, exist_ok=True) jp_db = merged_database.Database(Server.jp, args.input_dir) na_db = merged_database.Database(Server.na, args.input_dir) jp_db.load_database(skip_skills=True, skip_bonus=True, skip_extra=True) na_db.load_database(skip_skills=True, skip_bonus=True, skip_extra=True) print('merging data') # Skipping KR database; we don't need it to compute ES cross_db = CrossServerDatabase(jp_db, na_db, na_db) combined_cards = cross_db.all_cards fixed_card_id = args.card_id if args.interactive: fixed_card_id = input("enter a card id:").strip() count = 0 for csc in combined_cards: merged_card = csc.na_card card = merged_card.card if fixed_card_id and csc.monster_id != int(fixed_card_id): continue try: count += 1 if count % 100 == 0: print('processing {} of {}'.format(count, len(combined_cards))) monster_behavior = process_card(csc) if monster_behavior is None: continue # Do some sanity cleanup on the behavior monster_behavior = clean_monster_behavior(monster_behavior) behavior_data_file = os.path.join(behavior_data_dir, '{}.textproto'.format(csc.monster_id)) safe_save_to_file(behavior_data_file, monster_behavior) behavior_text_file = os.path.join(behavior_text_dir, '{}.txt'.format(csc.monster_id)) save_monster_behavior(behavior_text_file, csc, monster_behavior) # TODO: Add raw behavior dump except Exception as ex: print('failed to process', csc.monster_id, card.name) print(ex) # if 'unsupported operation' not in str(ex): import traceback traceback.print_exc() exit(0)
def run(args): enemy_skillset_dump.set_data_dir(args.output_dir) raw_input_dir = os.path.join(args.input_dir, 'raw') jp_db = merged_database.Database(Server.jp, raw_input_dir) na_db = merged_database.Database(Server.na, raw_input_dir) jp_db.load_database(skip_skills=True, skip_bonus=True, skip_extra=True) na_db.load_database(skip_skills=True, skip_bonus=True, skip_extra=True) print('merging data') cross_db = CrossServerDatabase(jp_db, na_db, na_db) combined_cards = cross_db.all_cards fixed_card_id = args.card_id if args.interactive: fixed_card_id = input("enter a card id:").strip() count = 0 for csc in combined_cards: merged_card = csc.na_card card = merged_card.card if fixed_card_id and csc.monster_id != int(fixed_card_id): continue try: count += 1 if count % 100 == 0: print('processing {} of {}'.format(count, len(combined_cards))) process_card(csc) except Exception as ex: print('failed to process', card.name) print(ex) # if 'unsupported operation' not in str(ex): import traceback traceback.print_exc() exit(0)
def run_test(args): input_dir = args.input_dir output_dir = args.output_dir new_output_dir = os.path.join(output_dir, 'new') pathlib.Path(new_output_dir).mkdir(parents=True, exist_ok=True) golden_output_dir = os.path.join(output_dir, 'golden') pathlib.Path(golden_output_dir).mkdir(parents=True, exist_ok=True) jp_db = merged_database.Database(Server.jp, input_dir) na_db = merged_database.Database(Server.na, input_dir) kr_db = merged_database.Database(Server.kr, input_dir) print('loading JP') jp_db.load_database(skip_extra=True) print('loading NA') na_db.load_database(skip_extra=True) print('loading KR') kr_db.load_database(skip_extra=True) print('merging data') cross_db = CrossServerDatabase(jp_db, na_db, kr_db) print('saving merged data') cross_db.save_all(new_output_dir, True) # Add sort by something, bonuses seem to be non-deterministicly ordered. files = { 'all_cards.json': cross_db.all_cards, 'dungeons.json': cross_db.dungeons, 'active_skills.json': cross_db.active_skills, 'leader_skills.json': cross_db.leader_skills, 'enemy_skills.json': cross_db.enemy_skills, # 'jp_bonuses.json': cross_db.jp_bonuses, # 'na_bonuses.json': cross_db.na_bonuses, # 'kr_bonuses.json': cross_db.kr_bonuses, } failed_comparisons = 0 bad_records = 0 print('starting diff') for file, data in files.items(): new_file = os.path.join(new_output_dir, file) golden_file = os.path.join(golden_output_dir, file) if not os.path.exists(golden_file): print('golden file does not exist, creating', golden_file) shutil.copy(new_file, golden_file) continue print('diffing', golden_file, 'against', new_file) with open(golden_file, encoding="utf-8") as f: golden_data = json.load(f) if len(golden_data) != len(data): print('ERROR') print( 'ERROR: file lengths differed ({} vs {}), indicates old golden data for {}' .format(len(golden_data), len(data), file)) print('ERROR') failed_comparisons += 1 continue failures = [] for i in range(len(golden_data)): gold_row = golden_data[i] new_row = data[i] gold_str = json_string_dump(gold_row, pretty=True) new_str = json_string_dump(new_row, pretty=True) if gold_str != new_str: failures.append([gold_str, new_str]) if not failures: continue fail_count = len(failures) disp_count = min(fail_count, 6) print('encountered', fail_count, 'errors, displaying the first', disp_count) failed_comparisons += 1 bad_records += fail_count failure_ids = [] for failure in failures: gold_str = failure[0] failure_ids.append(find_ids(gold_str)) print('All failing ids:\n' + '\n'.join(failure_ids)) for i in range(disp_count): gold_str = failures[i][0] new_str = failures[i][1] print('row identifiers:\n{}\n'.format(find_ids(gold_str))) diff_lines = difflib.context_diff(gold_str.split('\n'), new_str.split('\n'), fromfile='golden', tofile='new', n=1) print('\n'.join(diff_lines)) if failed_comparisons: print('Bad files:', failed_comparisons) print('Bad records:', bad_records) exit(1)
def run(args): behavior_data_dir = os.path.join(args.output_dir, 'behavior_data') os.makedirs(behavior_data_dir, exist_ok=True) behavior_text_dir = os.path.join(args.output_dir, 'behavior_text') os.makedirs(behavior_text_dir, exist_ok=True) behavior_plain_dir = os.path.join(args.output_dir, 'behavior_plain') os.makedirs(behavior_plain_dir, exist_ok=True) jp_db = merged_database.Database(Server.jp, args.input_dir) na_db = merged_database.Database(Server.na, args.input_dir) jp_db.load_database(skip_bonus=True, skip_extra=True) na_db.load_database(skip_bonus=True, skip_extra=True) print('merging data') if args.server.lower() == "jp": server = Server.jp elif args.server.lower() == "na": server = Server.na elif args.server.lower() == "kr": server = Server.kr else: raise ValueError("Server must be JP, NA, or KR") # Skipping KR database; we don't need it to compute ES cross_db = CrossServerDatabase(jp_db, na_db, na_db, server) combined_cards = cross_db.all_cards fixed_card_id = args.card_id if args.interactive: fixed_card_id = input("enter a card id:").strip() count = 0 for csc in combined_cards[count:]: merged_card = csc.na_card card = merged_card.card if fixed_card_id and csc.monster_id != int(fixed_card_id): continue try: count += 1 if count % 100 == 0: print('processing {:4d} of {}'.format(count, len(combined_cards))) monster_behavior = process_card(csc) if monster_behavior is None: continue # Do some sanity cleanup on the behavior monster_behavior = clean_monster_behavior(monster_behavior) behavior_data_file = os.path.join( behavior_data_dir, '{}.textproto'.format(csc.monster_id)) safe_save_to_file(behavior_data_file, monster_behavior) behavior_text_file = os.path.join(behavior_text_dir, '{}.txt'.format(csc.monster_id)) save_monster_behavior(behavior_text_file, csc, monster_behavior) enemy_behavior = [x.na_skill for x in csc.enemy_behavior] behavior_plain_file = os.path.join(behavior_plain_dir, '{}.txt'.format(csc.monster_id)) save_behavior_plain(behavior_plain_file, csc, enemy_behavior) except Exception as ex: print('failed to process', csc.monster_id, card.name) print(ex) # if 'unsupported operation' not in str(ex): import traceback traceback.print_exc() exit(0)