Example #1
0
    def recalc_score(score_data: Dict,
                     no_download=False) -> Optional[score.score]:
        """
        Recalculates pp for a score

        :param score_data: dict containing score and beatmap information about a score.
        :param no_download: if True, raise FileNotFoundError() if the map should be re-downloaded.
                            this ensures no requests are made to osu!
        :return: new `score` object, with `pp` attribute set to the new value
        """
        # Create score object and set its data
        s: score.score = score.score()
        s.setDataFromDict(score_data)
        s.passed = True

        # Create beatmap object and set its data
        b: beatmap.beatmap = beatmap.beatmap()
        b.setDataFromDict(score_data)

        # Abort if we are running in no_download mode and the map should be re-downloaded
        if no_download and mapsHelper.shouldDownloadMap(
                mapsHelper.cachedMapPath(b.beatmapID), b):
            raise FileNotFoundError("no_download mode and local map not found")

        # Calculate score pp
        s.calculatePP(b)
        del b
        return s
Example #2
0
    def recalcFromScoreData(scoreData):
        """
		Recalculate pp value for a score.
		Does every check, output and queries needed.

		score -- score+beatmap dictionary (returned from db with JOIN) of score to recalc
		return -- calculated pp value or None
		"""

        # Create score object and set its data
        s = score.score()
        s.setDataFromDict(scoreData)
        if s.scoreID == 0:
            # Make sure the score exists
            if glob.debug:
                consoleHelper.printColored(
                    "[!] No score with id {}".format(scoreData["id"]),
                    bcolors.RED)

        # Create beatmap object
        b = beatmap.beatmap()

        # Check if we have data for this song
        if scoreData["song_name"] is None or args.apirefresh == True:
            # If we don't have song data in scoreData, get with get_scores method (mysql, osuapi blabla)
            b.setData(scoreData["beatmap_md5"], 0)
        else:
            # If we have data, set data from dict
            b.setDataFromDict(scoreData)

        # Make sure the beatmap is ranked
        if b.rankedStatus < rankedStatuses.RANKED:
            if glob.debug:
                consoleHelper.printColored(
                    "[!] Beatmap {} is not ranked ().".format(s.fileMd5),
                    bcolors.RED)
            # Don't calculate pp if the beatmap is not ranked
            return False

        # Calculate score pp
        s.calculatePP(b)

        # Update score pp in dictionary
        scoreData["pp"] = s.pp
        return True
Example #3
0
    def recalc_score(self, score_data: Dict) -> score:
        """
        Recalculates pp for a score

        :param score_data: dict containing score and beatmap information about a score.
        :return: new `score` object, with `pp` attribute set to the new value
        """
        # Create score object and set its data
        s: score.score = score.score()
        s.setDataFromDict(score_data)
        s.passed = True

        # Create beatmap object and set its data
        b: beatmap.beatmap = beatmap.beatmap()
        b.setDataFromDict(score_data)

        # Calculate score pp
        s.calculatePP(b)
        del b
        return s