def sortRotation(data, stat) -> None: """ Print the sorted rotations by the average of the given stat. :param data: the data file name :type data: str :param stat: the statistic to sort by :type stat: str """ rotationList: List[int] = [] rotationResultsList: List[ Dict[str, Union[int, float, Union[None, Dict[str, Union[str, List[str]]]]]] ] = [] for line in data: job = Job(**ujson.loads(zlib.decompress(line))) if job.shift_start_at.time not in rotationList: rotationList.append(job.shift_start_at.time) for rotation in rotationList: print(rotation) result: Dict[ str, Union[int, float, Union[None, Dict[str, Union[str, List[str]]]]] ] = {} filterPaths: Tuple[List[bytes], List[bytes]] = cast( Tuple[List[bytes], List[bytes]], filters.duringRotationInts("mem", data, [rotation]), ) withVal: List[bytes] = filterPaths[0] withoutVal: List[bytes] = filterPaths[1] if hasJobs("mem", withVal): if (hasJobs("mem", withVal)) and (hasJobs("mem", withoutVal)): result["name"] = rotation result["data"] = core.findWeaponsAndStageByRotation( "mem", withVal, rotation ) result["value"] = ( statSummary("mem", withVal, stat)[0] - statSummary("mem", withoutVal, stat)[0] ) rotationResultsList.append(result) pprint.pprint( sorted(rotationResultsList, key=lambda val: cast(float, val["value"])) )
def sortWeapons(data, stat) -> None: """ :param data: :type data: str :param stat: :type stat: str """ weaponsList: List[Dict[str, Union[str, Dict[str, str]]]] = requests.get( "https://stat.ink/api/v2/weapon" ).json() for grizzWeapon in core.grizzcoWeapons: new = { "name": {locale: grizzWeapon[0]}, "key": grizzWeapon[1], "main_ref": grizzWeapon[1], } cast(List[Dict[str, Dict[str, str]]], weaponsList).append( cast(Dict[str, Dict[str, str]], new) ) results: List[Dict[str, Union[str, float]]] = [] for weapon in weaponsList: print(weapon["key"]) result: Dict[str, Union[str, float]] = {} filterPaths: Tuple[List[bytes], List[bytes]] = cast( Tuple[List[bytes], List[bytes]], filters.hasWeapons("mem", data, cast(List[str], [weapon["main_ref"]])), ) withVal: List[bytes] = filterPaths[0] withoutVal: List[bytes] = filterPaths[1] if hasJobs("mem", withVal) and not hasVal( cast(List[Dict[str, str]], results), cast(str, weapon["main_ref"]) ): if (hasJobs("mem", withVal)) and (hasJobs("mem", withoutVal)): result["key"] = cast(str, weapon["main_ref"]) result["name"] = cast(Dict[str, str], weapon["name"])[locale] result["value"] = ( statSummary("mem", withVal, stat)[0] - statSummary("mem", withoutVal, stat)[0] ) results.append(result) pprint.pprint(sorted(results, key=lambda val: val["value"]))
def filterJobsOr( location, data: Union[str, List[bytes]], filterFunctions: List[Callable], outpath) -> Union[Tuple[str, str], Tuple[List[bytes], List[bytes]]]: if location == "disk": if not (os.path.exists( cast(str, data[:-6]) + "/" + outpath + ".jl.gz") and os.path. exists(cast(str, data[:-6]) + "/not" + outpath + ".jl.gz")): with gzip.open(cast(str, data)) as reader: if hasJobs("disk", data): with gzip.open( cast(str, data[:-6]) + "/" + outpath + ".jl.gz", "at", encoding="utf8", ) as writerA: with gzip.open( cast(str, data[:-6]) + "/not" + outpath + ".jl.gz", "at", encoding="utf8", ) as writerB: for line in reader: job = Job(**ujson.loads(line)) found = False for funct in filterFunctions: found = found or funct(job) if found: json.dump(job, writerA, default=lambda x: x.__dict__) writerA.write("\n") else: json.dump(job, writerB, default=lambda x: x.__dict__) writerB.write("\n") return ( cast(str, data[:-6]) + "/" + outpath + ".jl.gz", cast(str, data[:-6]) + "/not" + outpath + ".jl.gz", ) jobsWith: List[bytes] = [] jobsWithout: List[bytes] = [] for jobLine in cast(List[bytes], data): job = Job(**ujson.loads(zlib.decompress(jobLine))) found = False for funct in filterFunctions: found = found or funct(job) if found: jobsWith.append(jobLine) else: jobsWithout.append(jobLine) return (jobsWith, jobsWithout)