def calculate_statistics(self): ez = oppai.ezpp_new() oppai.ezpp_set_autocalc(ez, 1) with open(self.map_path, encoding='utf-8') as file: data = file.read() oppai.ezpp_data_dup(ez, data, len(data.encode('utf-8'))) oppai.ezpp_set_mods(ez, reduce(lambda a, v: a | v.value, self.mods, 0)) self.max_combo = max(self.combo, oppai.ezpp_max_combo(ez)) oppai.ezpp_set_combo(ez, self.combo) oppai.ezpp_set_nmiss(ez, self.misses) oppai.ezpp_set_accuracy_percent(ez, self.accuracy) if self.submission is not None and self.ranked and self.submitted: self.pp = self.submission['pp'] else: self.pp = oppai.ezpp_pp(ez) oppai.ezpp_set_combo(ez, self.max_combo) oppai.ezpp_set_nmiss(ez, 0) self.fcpp = oppai.ezpp_pp(ez) oppai.ezpp_free(ez)
def calculatePP(self): """ Calculate total pp value with oppai and return it return -- total pp """ # Set variables self.pp = None ez = None try: # Build .osu map file path mapFile = mapsHelper.cachedMapPath(self.beatmap.beatmapID) mapsHelper.cacheMap(mapFile, self.beatmap) # Use only mods supported by oppai modsFixed = self.mods & 5983 # Check gamemode if self.gameMode not in (gameModes.STD, gameModes.TAIKO): raise exceptions.unsupportedGameModeException() ez = oppai.ezpp_new() if self.misses > 0: oppai.ezpp_set_nmiss(ez, self.misses) if self.combo >= 0: oppai.ezpp_set_combo(ez, self.combo) if self.gameMode == gameModes.TAIKO: oppai.ezpp_set_mode_override(ez, gameModes.TAIKO) if not self.tillerino: if self.acc > 0: oppai.ezpp_set_accuracy_percent(ez, self.acc) if self.mods > mods.NOMOD: oppai.ezpp_set_mods(ez, modsFixed) relax = (self.mods & mods.RELAX) > 0 autopilot = (self.mods & mods.RELAX2) > 0 if relax or autopilot: oppai.ezpp_set_relax_version(ez, 1) if relax: oppai.ezpp_set_relax(ez, 1) elif autopilot: oppai.ezpp_set_autopilot(ez, 1) if not self.tillerino: oppai.ezpp_dup(ez, mapFile) temp_pp = oppai.ezpp_pp(ez) self.stars = oppai.ezpp_stars(ez) if (self.gameMode == gameModes.TAIKO and self.beatmap.starsStd > 0 and temp_pp > 800) or \ self.stars > 50: # Invalidate pp for bugged taiko converteds and bugged inf pp std maps self.pp = 0 else: self.pp = temp_pp else: with open(mapFile, "r") as f: data = f.read() oppai.ezpp_data_dup(ez, data, len(data.encode())) pp_list = [] self.stars = oppai.ezpp_stars(ez) oppai.ezpp_set_autocalc(ez, 1) for acc in (100, 99, 98, 95): oppai.ezpp_set_accuracy_percent(ez, acc) pp = oppai.ezpp_pp(ez) # If this is a broken converted, set all pp to 0 and break the loop if self.gameMode == gameModes.TAIKO and self.beatmap.starsStd > 0 and pp > 800: pp_list = [0, 0, 0, 0] break pp_list.append(pp) self.pp = pp_list log.debug("oppai ~> Calculated PP: {}, stars: {}".format( self.pp, self.stars)) except exceptions.osuApiFailException: log.error("oppai ~> osu!api error!") self.pp = 0 except exceptions.unsupportedGameModeException: log.error("oppai ~> Unsupported gamemode") self.pp = 0 except Exception as e: log.error("oppai ~> Unhandled exception: {}".format(str(e))) self.pp = 0 raise finally: if ez is not None: oppai.ezpp_free(ez) log.debug("oppai ~> Shutting down, pp = {}".format(self.pp))
def close(self): oppai.ezpp_free(self._ez)