Ripple's score server https://ripple.moe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wifipiano3.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. Wifipiano 3
  3. """
  4. import subprocess
  5. from common.log import logUtils as log
  6. from helpers import mapsHelper
  7. class PianoError(Exception):
  8. pass
  9. class WiFiPiano:
  10. __slots__ = ["beatmap", "score", "pp"]
  11. def __init__(self, beatmap_, score_):
  12. self.beatmap = beatmap_
  13. self.score = score_
  14. self.pp = 0
  15. self.getPP()
  16. def _runProcess(self):
  17. # Run with dotnet
  18. command = \
  19. "dotnet pp/maniapp-osu-tools/PerformanceCalculator/bin/Release/netcoreapp2.0/PerformanceCalculator.dll " \
  20. "performance {map} " \
  21. "-mode 3 " \
  22. "-score {score_.score} " \
  23. "-acc {acc} " \
  24. "-mods {score_.mods} ".format(
  25. map=self.mapPath,
  26. score_=self.score,
  27. acc=self.score.accuracy * 100
  28. )
  29. log.debug("wifipiano3 ~> running {}".format(command))
  30. process = subprocess.run(command, shell=True, stdout=subprocess.PIPE)
  31. # Get pp from output
  32. output = process.stdout.decode("utf-8", errors="ignore")
  33. log.debug("wifipiano3 ~> output: {}".format(output))
  34. lines = output.split("\n")
  35. found = False
  36. pp = 0.
  37. for line in lines:
  38. parts = [x.strip().lower() for x in line.split(":")]
  39. if parts[0] != "pp":
  40. continue
  41. found = True
  42. try:
  43. pp = float(parts[1])
  44. except ValueError:
  45. raise PianoError("Invalid 'pp' value (got '{}', expected a float)".format(parts[1]))
  46. if not found:
  47. raise PianoError("No 'pp' in PerformanceCalculator.dll output")
  48. log.debug("wifipiano3 ~> returned pp: {}".format(pp))
  49. return pp
  50. def getPP(self):
  51. try:
  52. # Reset pp
  53. self.pp = 0
  54. # Cache map
  55. mapsHelper.cacheMap(self.mapPath, self.beatmap)
  56. # Calculate pp
  57. self.pp = self._runProcess()
  58. except PianoError:
  59. log.warning("Invalid beatmap {}".format(self.beatmap.beatmapID))
  60. self.pp = 0
  61. finally:
  62. return self.pp
  63. @property
  64. def mapPath(self):
  65. return mapsHelper.cachedMapPath(self.beatmap.beatmapID)