def get_sim_target_module_dict(advs=None, conds=None, mass=None, special=False): target_modules = {} advs = advs or list_advs() for adv in advs: try: name = core.simulate.load_adv_module(adv, in_place=target_modules) if conds is not None: adv_data = load_adv_json(name) if not all([cond(adv_data) for cond in conds]): del target_modules[name] continue if mass is not None: if (mass and "mass" not in target_modules[name]) or ( not mass and "mass" in target_modules[name]): del target_modules[name] continue if special and all((variant == None or variant in SKIP_VARIANT for variant in target_modules[name].keys())): del target_modules[name] continue except Exception as e: printlog("load", monotonic() - t_start, adv, None, err=e, color=93) return target_modules
def repair_equips(name, variants): t_start = monotonic() try: module = variants[None] adv_ele = load_adv_json(name)['c']['ele'] adv_equip = deepcopy(load_equip_json(name)) for dkey, equip_d in adv_equip.items(): pref = equip_d.get('pref', 'base') for ekey, conf in equip_d.items(): if ekey == 'pref': continue run_and_save(name, module, adv_ele, dkey, ekey, conf, repair=True) # if affliction, check if base equip actually better if ekey == 'affliction': try: run_and_save(name, module, adv_ele, dkey, ekey, equip_d['base']) except KeyError: pass # check if 180 equip is actually better for 120/60 if dkey == '180': continue try: run_and_save(name, module, adv_ele, dkey, ekey, adv_equip['180'][ekey]) except KeyError: pass except Exception as e: print(f'\033[91m{monotonic()-t_start:.4f}s - repair:{name} {e}\033[0m', flush=True) return print('{:.4f}s - repair:{}'.format(monotonic() - t_start, name), flush=True)
def repair_equips(adv_file): t_start = monotonic() try: adv_file = os.path.basename(adv_file) adv_name = adv_file if adv_file.endswith('.py'): adv_name = adv_file.split('.')[0] adv_module = core.simulate.load_adv_module(adv_name) adv_name = adv_module.__name__ adv_ele = load_adv_json(adv_name)['c']['ele'] adv_equip = deepcopy(load_equip_json(adv_name)) eleaff = None for dkey, equip_d in adv_equip.items(): for ekey, conf in equip_d.items(): if ekey == 'pref': continue run_and_save(adv_module, adv_ele, dkey, ekey, conf) # check if 180 equip is actually better for 120/60 if dkey == '180': continue try: run_and_save(adv_module, adv_ele, dkey, ekey, equip_d['180'][ekey]) except KeyError: pass except Exception as e: print( f'\033[91m{monotonic()-t_start:.4f}s - repair:{adv_file} {e}\033[0m', flush=True) return print('{:.4f}s - repair:{}'.format(monotonic() - t_start, adv_file), flush=True)
def get_adv_wp_list(): if not (request.method == 'GET' or request.method == 'POST'): return 'Wrong request method.' result = {} result['adv'] = {} for name in ADV_MODULES.keys(): try: result['adv'][name] = load_adv_json(name)['c']['name'] except FileNotFoundError: result['adv'][name] = SPECIAL_ADV[name]['fullname'] wplists = {'gold': {}, 'silver': {}} for wp, data in wyrmprints.items(): ab_str = f'-{data["union"]}' if data['a']: ab_str = '[' + '|'.join(map(str, data['a'][0])) + ']' + ab_str else: ab_str = '[]' + ab_str if data['rarity'] == 5: wplists['gold'][wp] = data['name'] + ' ' + ab_str else: wplists['silver'][wp] = data['name'] + ' ' + ab_str result['wyrmprints'] = wplists result['skillshare'] = { k: { 'fullname': get_fullname(k), **v } for k, v in skillshare.items() } return jsonify(result)
def combine(): t_start = monotonic() dst_dict = {} pages = [str(d) for d in DURATIONS] + ['sp'] aff = ['_', 'affliction'] for p in pages: dst_dict[p] = {} for a in aff: dst_dict[p][a] = open( os.path.join(ROOT_DIR, CHART_DIR, 'page/{}_{}.csv'.format(p, a)), 'w') for fn in os.listdir(os.path.join(ROOT_DIR, CHART_DIR, 'chara')): if not fn.endswith('.csv'): continue with open(os.path.join(ROOT_DIR, CHART_DIR, 'chara', fn), 'r', encoding='utf8') as chara: for line in chara: if line[0] == '-': _, c_page, c_aff = line.strip().split(',') else: dst_dict[c_page][c_aff].write(line.strip()) dst_dict[c_page][c_aff].write('\n') for p in pages: for a in aff: dst_dict[p][a].close() dst_dict[p][a].close() with open(os.path.join(ROOT_DIR, CHART_DIR, 'page/lastmodified.json'), 'r+') as f: try: lastmod = json.load(f) except: lastmod = {} f.truncate(0) f.seek(0) lastmod['timestamp'] = time_ns() // 1000000 try: sort_message = [ load_adv_json(adv)['c']['icon'] for adv in sorted(set(lastmod['changed']), key=msg_sort) ] lastmod['message'] = list(sort_message) del lastmod['changed'] except KeyError: lastmod['message'] = [] json.dump(lastmod, f) print(f'{monotonic() - t_start:.4f}s - combine', flush=True)
def combine(): t_start = monotonic() dst_dict = {} pages = [str(d) for d in DURATIONS] + ["mono", "sp"] aff = ["_", "affliction", "noaffliction"] for p in pages: dst_dict[p] = {} for a in aff: dst_dict[p][a] = open( os.path.join(ROOT_DIR, CHART_DIR, "page/{}_{}.csv".format(p, a)), "w") for fn in os.listdir(os.path.join(ROOT_DIR, CHART_DIR, "chara")): if not fn.endswith(".csv"): continue with open(os.path.join(ROOT_DIR, CHART_DIR, "chara", fn), "r", encoding="utf8") as chara: for line in chara: if line[0] == "-": _, c_page, c_aff = line.strip().split(",") else: dst_dict[c_page][c_aff].write(line.strip()) dst_dict[c_page][c_aff].write("\n") for p in pages: for a in aff: dst_dict[p][a].close() dst_dict[p][a].close() with open(os.path.join(ROOT_DIR, CHART_DIR, "page/lastmodified.json"), "r+") as f: try: lastmod = json.load(f) except: lastmod = {} f.truncate(0) f.seek(0) lastmod["timestamp"] = time_ns() // 1000000 try: sort_message = [ load_adv_json(adv)["c"]["icon"] for adv in sorted(set(lastmod["changed"]), key=msg_sort) ] lastmod["message"] = list(sort_message) del lastmod["changed"] except KeyError: lastmod["message"] = [] json.dump(lastmod, f) print(f"{monotonic() - t_start:.4f}s - combine", flush=True)
def find_offele_backline(): secondary = {'Axe2': ('flame', 'wind'), 'Dagger2': ('flame', 'water')} advequip = load_all_equip_json() offele = defaultdict(lambda: []) for adv, allequip in advequip.items(): element = load_adv_json(adv)['c']['ele'] for duration, keyequip in allequip.items(): for key, conf in keyequip.items(): try: for coab in conf['coabs']: try: coab_element = load_adv_json(coab)['c']['ele'] if coab_element != element: offele[coab].append( (adv, element, duration, key, coab)) except: if coab in secondary and element not in secondary[ coab]: offele[coab].append( (adv, element, duration, key, coab)) except TypeError: continue pprint(dict(offele), width=200)
def get_sim_target_module_dict(advs=None, conds=None, mass=None): target_modules = {} advs = advs or list_advs() for adv in advs: try: name = core.simulate.load_adv_module(adv, in_place=target_modules) if conds is not None: adv_data = load_adv_json(name) if not all([cond(adv_data) for cond in conds]): del target_modules[name] if mass is not None: if (mass and 'mass' not in target_modules[name]) or (not mass and 'mass' in target_modules[name]): del target_modules[name] except Exception as e: print(f'\033[93m{0:.4f}s - load:{adv} {e}\033[0m', flush=True) return target_modules
def repair_entries(self): adv_module, _ = core.simulate.load_adv_module(self.advname) element = load_adv_json(self.advname)['c']['ele'] for duration in list(self.keys()): for kind in list(self[duration].keys()): if kind.endswith('pref'): continue self.repair_entry(adv_module, element, self[duration][kind], duration, kind) for duration in list(self.keys()): for kind in list(self[duration].keys()): # if duration != '180': # try: # self.repair_entry(adv_module, element, self['180'][kind], duration, kind, do_compare=True) # except KeyError: # pass # for affkind, basekind in (('affliction', 'base'), ('mono_affliction', 'mono_base')): # try: # self.repair_entry(adv_module, element, self[duration][basekind], duration, affkind, do_compare=True) # except KeyError: # pass for basekind in ('base', 'buffer', 'affliction'): monokind = f'mono_{basekind}' if not basekind in self[duration]: continue if not EQUIP_ENTRY_MAP[monokind].acceptable( self[duration][basekind], element): continue try: current_entry = self[duration][monokind] if not current_entry.better_than( self[duration][basekind]): self[duration][monokind] = deepcopy( self[duration][basekind]) except KeyError: self[duration][monokind] = deepcopy( self[duration][basekind]) self.update_tdps_threshold(duration) save_equip_json(self.advname, self)
def rank_ss(): ranked = [] for adv, ss in skillshare.items(): if ss.get('type') != 1: continue adv_data = load_adv_json(adv) try: skill = adv_data[f's{ss["s"]}'] except: skill = adv_data[f's{ss["s"]}_phase1'] try: mod_t = 0 for attr in skill['attr']: dmg = attr.get('dmg', 0) killer = attr.get('killer') if killer: dmg *= killer[0] mod_t += dmg except: continue ss_sp = ss['sp'] normalized_t = skill['startup'] + skill['recovery'] + ss_sp / SPPS ranked.append((mod_t / normalized_t, adv_data['c']['name'])) pprint(sorted(ranked, reverse=True))
return self.c.hp + self.d.hp + self.w.hp + self.a.hp def oninit(self, adv=None): # self.c.oninit(adv) self.d.oninit(adv) # self.w.oninit(adv) # self.a.oninit(adv) for kind, slot in (('c', self.c), ('d', self.d), ('a', self.a), ('w', self.w)): for aidx, ab in enumerate(slot.ab): name = ab[0] if '_' in name: acat = name.split('_')[0] else: acat = name self.abilities[f'{kind}_{aidx}_{name}'] = (kind, ability_dict[acat](*ab)) for name, val in self.abilities.items(): kind, abi = val abi.oninit(adv, kind) self.abilities[name] = abi if __name__ == '__main__': from conf import load_adv_json conf = Conf(load_adv_json('Xania')) # conf['slots.a'] = ['Candy_Couriers', 'Me_and_My_Bestie'] conf['slots.d'] = 'Gala_Mars' slots = Slots(conf.c, True) slots.set_slots(conf.slots) print(type(slots.d))
def msg_sort(adv): advconf = load_adv_json(adv) return ELE_IDX[advconf['c']['ele']], adv
def msg_sort(adv): advconf = load_adv_json(adv) return ELE_IDX[advconf["c"]["ele"]], adv
def repair_entries(self): adv_module, _ = core.simulate.load_adv_module(self.advname) element = load_adv_json(self.advname)["c"]["ele"] for duration in list(self.keys()): if not int(duration) in DURATIONS: del self[duration] for duration in list(self.keys()): for kind in list(self[duration].keys()): if kind.endswith("pref"): continue if self.check_skip_entry(self[duration][kind], duration, kind, SKIP_IF_IDENTICAL, do_compare=False)[0]: continue if self.check_skip_entry(self[duration][kind], duration, kind, SKIP_IF_SAME_COAB, do_compare=False)[0]: continue self.repair_entry(adv_module, element, self[duration][kind], duration, kind) for duration in list(self.keys()): for basekind in ("base", "buffer", "affliction", "noaffliction"): monokind = f"mono_{basekind}" if not basekind in self[duration]: try: del self[duration][monokind] except KeyError: continue continue if not EQUIP_ENTRY_MAP[monokind].acceptable( self[duration][basekind], element): if monokind not in self[duration]: # try auto populate filtered_entry = filtered_monoele_coabs( self[duration][basekind], element) if len(filtered_entry["coabs"]) == 3: # same amount of coab, no need to populate continue advcoabs = get_adv_coability(self.advname) for coab in DEFAULT_MONO_COABS[element]: if len(filtered_entry["coabs"]) == 3: break if coab not in filtered_entry[ "coabs"] and coab not in advcoabs: filtered_entry["coabs"].append(coab) self.repair_entry(adv_module, element, filtered_entry, duration, monokind) continue # try: # current_entry = self[duration][monokind] # if not current_entry.better_than(self[duration][basekind]): # self[duration][monokind] = EQUIP_ENTRY_MAP[monokind](filter_coab_only(self[duration][basekind])) # except KeyError: # self[duration][monokind] = EQUIP_ENTRY_MAP[monokind](filter_coab_only(self[duration][basekind])) self.update_tdps_threshold(duration) if not self.debug: save_equip_json(self.advname, self)