def __init__(self, adventurer, dps_dict=None, rank_db=None): if not dps_dict: print(f"NO DPS RECORDS FOR {adventurer.name}") return self.adventurer = adventurer self.owner = adventurer.internal_name self.wyrmprints = dps_dict["wyrmprints"] self.element = adventurer.element.lower() if "dps" in dps_dict["dragon"]: split = dps_dict["dragon"].split(";") dps_range = split[1].lower().replace("dpsrange:", "DPS Range: ") dps_range = dps_range.replace("~", " ~ ") self.dragon = f"{split[0]}\n*{dps_range}*" else: self.dragon = dps_dict["dragon"] self.parse = CONST.copy_parses() for parse_value in dps_dict["parses"].keys(): for coabs in dps_dict["parses"][parse_value].keys(): self.parse[parse_value][coabs] = Parse( dps_dict["parses"][parse_value][coabs], coabs ) self.image = adventurer.image self.alt = dps_dict["alt"] for parse_value, coab_dict in self.parse.items(): for coabs in coab_dict.keys(): self.parse[parse_value][coabs].rank_element = str( rank_db[parse_value][coabs][self.element].index(self.owner) + 1 ) self.parse[parse_value][coabs].rank_overall = str( rank_db[parse_value][coabs]["all"].index(self.owner) + 1 )
def load_csvs(path): dps_dict = CONST.copy_parses() for root, dirs, files in os.walk(DPS_PATH): for filename in files: with open(f"{DPS_PATH}/{filename}", newline="") as f: name = filename.split("optimal_dps_")[1].split("_", 1) parse = str(name[0]) coabs = str(name[1]).replace(".csv", "") reader = csv.reader(f) dps_dict[parse][coabs] = list(reader) return dps_dict
def gen_ranks(dps_db): """ Given a dps dict, builds a rankings of overall and each adventurers specific element. """ rankings_db = CONST.copy_parses() for parse in CONST.parses: for coabs in CONST.coab_combos: sorted_list = sorted( [ ( adven, int(dps_db[adven]["parses"][parse][coabs]["damage"]["dps"]), ) for adven in dps_db.keys() ], key=lambda x: x[1], reverse=True, ) rankings_db[parse][coabs] = {} rankings_db[parse][coabs]["all"] = [i[0] for i in sorted_list] for element in CONST.dragalia_elements: sorted_list = sorted( [ ( adven, int( dps_db[adven]["parses"][parse][coabs]["damage"][ "dps" ] ), ) for adven in dps_db.keys() if dps_db[adven]["element"] == element ], key=lambda x: x[1], reverse=True, ) rankings_db[parse][coabs][element] = [i[0] for i in sorted_list] return rankings_db
async def async_pull_csvs(session, path, force=False): """ Given a path, gets and saves all csvs for all co-ability combinations from source, returning a complete dictionary of all combinations and all parses. ++ASYNC version++ """ if DPS.check_version() is True or force is True: dps_dict = CONST.copy_parses() MISC.check_dir(path) for coabs in CONST.coab_combos: for parse in CONST.parses: request = await MISC.async_fetch_text( session, CONST.GET_URL(parse, coabs) ) dps_dict[parse][coabs] = [i.split(",") for i in request.split("\n")] path_to_file = f"{path}/optimal_dps_{parse}_{coabs}.csv" MISC.save_csv(path_to_file, dps_dict[parse][coabs]) DPS.update_master_hash() return DPS.build_dps_dict(dps_dict) else: print(skip_msg) return DPS.build_dps_dict(load_csvs(path))