New function that makes playlists for every star level and sorts by lowest accuracy.
This commit is contained in:
parent
3818be41eb
commit
1116a4c59f
@ -34,5 +34,6 @@ Homepage = "https://git.satstack.dev/blee/beatsaber-playlist-tool"
|
||||
# https://setuptools.pypa.io/en/latest/userguide/entry_point.html
|
||||
[project.scripts]
|
||||
player_scores_by_stars = "saberlist.scoresaber:replay_ranked"
|
||||
replay_all_by_acc = "saberlist.scoresaber:replay_all_by_acc"
|
||||
leaderboard_songs_by_stars = "saberlist.scoresaber:leaderboard_songs"
|
||||
#replay_ranked_bl = "saberlist.beatleader:replay_ranked"
|
@ -18,6 +18,13 @@ def filter_and_sort_scores_by_stars(scores, min_stars: float, max_stars: float):
|
||||
sorted_scores = sorted(filtered_scores, key=lambda x: x.leaderboard.stars)
|
||||
return sorted_scores
|
||||
|
||||
def filter_and_sort_scores_by_acc(scores, min_stars: float, max_stars: float):
|
||||
# Exclude scores outside the specified star range
|
||||
filtered_scores = [score for score in scores if min_stars <= score.leaderboard.stars < max_stars]
|
||||
# Calculate the score percentage for sorting
|
||||
sorted_scores = sorted(filtered_scores, key=lambda x: (x.score.base_score / x.leaderboard.max_score) * 100)
|
||||
return sorted_scores
|
||||
|
||||
# TODO: combine with scores_to_playlist()
|
||||
def leaderboards_to_playlist(leaderboards: list, playlist_title: str, playlist_author: str = "SaberList Tool") -> str:
|
||||
playlist = {
|
||||
@ -76,6 +83,44 @@ def scores_to_playlist(scores: list, playlist_title, playlist_author = "SaberLis
|
||||
|
||||
return playlist_json
|
||||
|
||||
async def async_replay_all_by_acc():
|
||||
"""Generate playlists for each star level and sort by lowest accuracy."""
|
||||
|
||||
scoresaber = ExtendedScoreSaberAPI()
|
||||
try:
|
||||
await scoresaber.start()
|
||||
score_sort = ScoreSort.TOP
|
||||
scores = []
|
||||
default_title = "Replay SS"
|
||||
default_player_id = '76561199407393962'
|
||||
player_id = input(f"Enter the playerid (Default: {default_player_id}): ") or default_player_id
|
||||
|
||||
async for player_scores in scoresaber.player_scores_all(player_id, score_sort):
|
||||
scores.extend(player_scores)
|
||||
|
||||
if scores:
|
||||
max_stars = max(score.leaderboard.stars for score in scores)
|
||||
|
||||
for stars in range(1, int(max_stars) + 1):
|
||||
playlist_title = f"{default_title} {stars}★"
|
||||
filtered_sorted_scores = filter_and_sort_scores_by_acc(scores, stars, stars + 1)
|
||||
if filtered_sorted_scores:
|
||||
scores_to_playlist(filtered_sorted_scores, playlist_title)
|
||||
else:
|
||||
print(f"No scores found for {stars}★")
|
||||
else:
|
||||
print("No scores found for the given player.")
|
||||
|
||||
finally:
|
||||
await scoresaber._http_client.close()
|
||||
|
||||
def replay_all_by_acc():
|
||||
try:
|
||||
asyncio.run(async_replay_all_by_acc())
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
|
||||
async def async_replay_ranked():
|
||||
scoresaber = ExtendedScoreSaberAPI()
|
||||
try:
|
||||
@ -95,7 +140,8 @@ async def async_replay_ranked():
|
||||
async for player_scores in scoresaber.player_scores_all(player_id, score_sort):
|
||||
scores.extend(player_scores)
|
||||
|
||||
filtered_sorted_scores = filter_and_sort_scores_by_stars(scores, min_stars, max_stars)
|
||||
# filtered_sorted_scores = filter_and_sort_scores_by_stars(scores, min_stars, max_stars)
|
||||
filtered_sorted_scores = filter_and_sort_scores_by_acc(scores, min_stars, max_stars)
|
||||
scores_to_playlist(filtered_sorted_scores, playlist_title)
|
||||
finally:
|
||||
await scoresaber._http_client.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user