Created
May 5, 2021 15:20
-
-
Save Jakads/4d5a88c1e900f9c55c38a84fd85e06fd to your computer and use it in GitHub Desktop.
nps graph visualizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
nps graph visualizer by Jakads | |
should work with any modes i think | |
also prints max nps and when it happens | |
bonus feature pog | |
open .osu with this .py (i.e. drag .osu into the .py) | |
install matplotlib beforehand (pip install matplotlib) | |
''' | |
import matplotlib.pyplot as plt | |
import os | |
import sys | |
osu_file = sys.argv[1] | |
with open(osu_file, 'r', encoding='utf-8') as f: | |
while True: | |
line = f.readline() | |
if line == '[HitObjects]\n': | |
note_list = f.readlines() | |
break | |
count_dict = {} | |
ms_check = set() | |
for note in note_list: | |
ms = int(note.split(',')[2]) | |
if ms in count_dict: | |
count_dict[ms] += 1 | |
else: | |
count_dict[ms] = 1 | |
ms_check.update([ms - 0.1, ms, ms + 999.9, ms + 1000]) | |
ms_checklist = sorted(ms_check) | |
count = 0 | |
count_list = [] | |
for ms in ms_checklist: | |
pluscount = count_dict.get(ms, 0) | |
minuscount = count_dict.get(ms - 1000, 0) | |
count += pluscount - minuscount | |
count_list.append(count) | |
max_count = max(count_list) | |
max_index = [i for i, count in enumerate(count_list) if count == max_count] | |
max_ms = [str(ms_checklist[i]) for i in max_index if type(ms_checklist[i]) == int] | |
print(f'Max NPS: {max_count} at {", ".join(max_ms)}ms') | |
plt.plot(ms_checklist, count_list) | |
plt.xlabel('Time (ms)') | |
plt.ylabel('NPS') | |
plt.title(os.path.split(osu_file)[1]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment