Skip to main content

Difficulty and performance calculation for osu!

Project description

rina-pp-pyb

Library to calculate difficulty and performance attributes for all osu! modes.

This is a python binding to the Rust library rina-pp which was bootstrapped through PyO3. As such, its performance is much faster than a native python library.

Usage

The library exposes multiple classes:

Example

Calculating performance

import rina_pp_pyb as rosu

# either `path`, `bytes`, or `content` must be specified when parsing a map
map = rosu.Beatmap(path = "/path/to/file.osu")

# Optionally convert to a specific mode
map.convert(rosu.GameMode.Mania)

perf = rosu.Performance(
    # various kwargs available
    accuracy = 98.76,
    misses = 2,
    combo = 700,
    hitresult_priority = rosu.HitResultPriority.WorstCase, # favors bad hitresults
)

# Each kwarg can also be specified afterwards through setters
perf.set_accuracy(99.11) # override previously specified accuracy
perf.set_mods(8 + 64)    # HDDT
perf.set_clock_rate(1.4)

# Second argument of map attributes specifies whether mods still need to be accounted for
# `True`: mods already considered; `False`: value should still be adjusted
perf.set_ar(10.5, True)
perf.set_od(5, False)

# Calculate for the map
attrs = perf.calculate(map)

# Note that calculating via map will have to calculate difficulty attributes
# internally which is fairly expensive. To speed it up, you can also pass in
# previously calculated attributes, but be sure they were calculated for the
# same difficulty settings like mods, clock rate, custom map attributes, ...

perf.set_accuracy(100)
perf.set_misses(None)
perf.set_combo(None)

# Calculate a new set of attributes by re-using previous attributes instead of the map
max_attrs = perf.calculate(attrs)

print(f'PP: {attrs.pp}/{max_attrs.pp} | Stars: {max_attrs.difficulty.stars}')

Gradual calculation

import rina_pp_pyb as rosu

# Parsing the map, this time through the `content` kwarg
with open("/path/to/file.osu") as file:
    map = rosu.Beatmap(content = file.read())

# Specifying some difficulty parameters
diff = rosu.Difficulty(
    mods = 16 + 1024, # HRFL
    clock_rate = 1.1,
    ar = 10.2,
    ar_with_mods = True,
)

# Gradually calculating *difficulty* attributes
gradual_diff = diff.gradual_difficulty(map)

for i, attrs in enumerate(gradual_diff, 1):
    print(f'Stars after {i} hitobjects: {attrs.stars}')

# Gradually calculating *performance* attributes
gradual_perf = diff.gradual_performance(map)
i = 1

while True:
    state = rosu.ScoreState(
        max_combo = i,
        n300 = i,
        n100 = 0,
        # ...
    )

    attrs = gradual_perf.next(state)

    if attrs is None:
        # All hitobjects have been processed
        break

    print(f'PP: {attrs.pp}')
    i += 1

Installing rina-pp-pyb

Installing rina-pp-pyb requires a supported version of Python and Rust.

Once Python and Rust are ready to go, you can install the project with pip:

$ pip install rina-pp-pyb

or

$ pip install git+https://github.com/osuthailand/rina-pp-pyb

Learn More

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rina_pp_pyb-1.0.0.tar.gz (33.0 kB view hashes)

Uploaded Source

Built Distributions

rina_pp_pyb-1.0.0-pp310-pypy310_pp73-win_amd64.whl (315.7 kB view hashes)

Uploaded PyPy Windows x86-64

rina_pp_pyb-1.0.0-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl (589.1 kB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl (566.1 kB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl (358.7 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-pp310-pypy310_pp73-macosx_10_12_x86_64.whl (388.7 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

rina_pp_pyb-1.0.0-pp39-pypy39_pp73-win_amd64.whl (316.2 kB view hashes)

Uploaded PyPy Windows x86-64

rina_pp_pyb-1.0.0-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl (589.6 kB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl (566.5 kB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl (359.2 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl (389.4 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

rina_pp_pyb-1.0.0-cp312-none-win_arm64.whl (289.3 kB view hashes)

Uploaded CPython 3.12 Windows ARM64

rina_pp_pyb-1.0.0-cp312-none-win_amd64.whl (318.4 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

rina_pp_pyb-1.0.0-cp312-cp312-musllinux_1_1_x86_64.whl (589.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-cp312-cp312-musllinux_1_1_aarch64.whl (566.7 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (359.2 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-cp312-cp312-macosx_10_12_x86_64.whl (388.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

rina_pp_pyb-1.0.0-cp311-none-win_arm64.whl (287.1 kB view hashes)

Uploaded CPython 3.11 Windows ARM64

rina_pp_pyb-1.0.0-cp311-none-win_amd64.whl (315.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rina_pp_pyb-1.0.0-cp311-cp311-musllinux_1_1_x86_64.whl (589.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-cp311-cp311-musllinux_1_1_aarch64.whl (566.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (359.0 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-cp311-cp311-macosx_10_12_x86_64.whl (388.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

rina_pp_pyb-1.0.0-cp310-none-win_amd64.whl (315.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rina_pp_pyb-1.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (589.5 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-cp310-cp310-musllinux_1_1_aarch64.whl (566.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (359.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-cp310-cp310-macosx_10_12_x86_64.whl (389.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

rina_pp_pyb-1.0.0-cp39-none-win_amd64.whl (316.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rina_pp_pyb-1.0.0-cp39-cp39-musllinux_1_1_x86_64.whl (589.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-cp39-cp39-musllinux_1_1_aarch64.whl (567.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-cp39-cp39-macosx_11_0_arm64.whl (359.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-cp39-cp39-macosx_10_12_x86_64.whl (389.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

rina_pp_pyb-1.0.0-cp38-none-win_amd64.whl (316.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rina_pp_pyb-1.0.0-cp38-cp38-musllinux_1_1_x86_64.whl (589.9 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

rina_pp_pyb-1.0.0-cp38-cp38-musllinux_1_1_aarch64.whl (567.0 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

rina_pp_pyb-1.0.0-cp38-cp38-macosx_11_0_arm64.whl (359.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

rina_pp_pyb-1.0.0-cp38-cp38-macosx_10_12_x86_64.whl (389.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page