Skip to content

Commit

Permalink
Merge pull request #172 from Syriiin/add-json-mods
Browse files Browse the repository at this point in the history
Add json mods field
  • Loading branch information
Syriiin authored Nov 30, 2024
2 parents adc69c2 + c48258f commit 1f46c84
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 45 deletions.
12 changes: 6 additions & 6 deletions common/osu/difficultycalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class Score(NamedTuple):
beatmap_id: str
mods: int | None = None
is_classic: bool = True
is_stable: bool = True
statistics: dict[str, int] = {}
combo: int | None = None

Expand Down Expand Up @@ -144,7 +144,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_mods(
score.mods if score.mods is not None else 0, score.is_classic
score.mods if score.mods is not None else 0, score.is_stable
),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
Expand Down Expand Up @@ -177,7 +177,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_mods(
score.mods if score.mods is not None else 0, score.is_classic
score.mods if score.mods is not None else 0, score.is_stable
),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
Expand Down Expand Up @@ -209,7 +209,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_mods(
score.mods if score.mods is not None else 0, score.is_classic
score.mods if score.mods is not None else 0, score.is_stable
),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
Expand Down Expand Up @@ -242,7 +242,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_mods(
score.mods if score.mods is not None else 0, score.is_classic
score.mods if score.mods is not None else 0, score.is_stable
),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
Expand Down Expand Up @@ -279,7 +279,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_mods(
score.mods if score.mods is not None else 0, score.is_classic
score.mods if score.mods is not None else 0, score.is_stable
),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
Expand Down
32 changes: 24 additions & 8 deletions common/osu/osuapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ossapi import Beatmap, GameMode, Ossapi, Score, ScoreType, User, UserLookupKey

from common.osu.enums import BeatmapStatus, Gamemode
from common.osu.utils import get_bitwise_mods
from common.osu.utils import get_bitwise_mods, get_json_mods


class MalformedResponseError(Exception):
Expand Down Expand Up @@ -272,7 +272,8 @@ def from_apiv1(cls, data: dict) -> "UserData":
class ScoreData(NamedTuple):
beatmap_id: int
mods: int
is_classic: bool
mods_json: list[dict]
is_stable: bool

score: int
best_combo: int
Expand All @@ -292,7 +293,8 @@ def as_json(self):
return {
"beatmap_id": self.beatmap_id,
"mods": self.mods,
"is_classic": self.is_classic,
"mods_json": self.mods_json,
"is_stable": self.is_stable,
"score": self.score,
"best_combo": self.best_combo,
"count_300": self.count_300,
Expand All @@ -312,7 +314,8 @@ def from_json(cls, data: dict) -> "ScoreData":
return cls(
beatmap_id=data["beatmap_id"],
mods=data["mods"],
is_classic=data["is_classic"],
mods_json=data["mods_json"],
is_stable=data["is_stable"],
score=data["score"],
best_combo=data["best_combo"],
count_300=data["count_300"],
Expand Down Expand Up @@ -374,14 +377,17 @@ def from_apiv1(
if data["countmiss"] != "0":
statistics["miss"] = int(data["countmiss"])

is_stable = data["score"] != "0" # lazer uses new scoring

return cls(
beatmap_id=(
beatmap_id_override
if beatmap_id_override is not None
else int(data["beatmap_id"])
),
mods=int(data["enabled_mods"]),
is_classic=data["score"] != "0", # lazer uses new scoring
mods_json=get_json_mods(int(data["enabled_mods"]), is_stable),
is_stable=is_stable,
score=int(data["score"]),
best_combo=int(data["maxcombo"]),
count_300=int(data["count300"]),
Expand Down Expand Up @@ -589,7 +595,16 @@ def __score_data_from_ossapi(
else:
beatmap_id = beatmap_id_override

bitwise_mods, is_classic = get_bitwise_mods([mod.acronym for mod in score.mods])
is_stable = score.legacy_score_id is not None

bitwise_mods = get_bitwise_mods([mod.acronym for mod in score.mods])

mods_json = []
for mod in score.mods:
mod_json = {"acronym": mod.acronym}
if mod.settings is not None:
mod_json["settings"] = mod.settings
mods_json.append(mod_json)

if gamemode == Gamemode.STANDARD:
count_300 = (
Expand Down Expand Up @@ -698,8 +713,9 @@ def __score_data_from_ossapi(
return ScoreData(
beatmap_id=beatmap_id,
mods=bitwise_mods,
is_classic=is_classic,
score=score.legacy_total_score if is_classic else score.total_score,
mods_json=mods_json,
is_stable=is_stable,
score=score.legacy_total_score if is_stable else score.total_score,
best_combo=score.max_combo,
count_300=count_300,
count_100=count_100,
Expand Down
149 changes: 138 additions & 11 deletions common/osu/stubdata/osuapi/scores.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
{
"beatmap_id": 362949,
"mods": 72,
"is_classic": true,
"mods_json": [
{
"acronym": "HD"
},
{
"acronym": "DT"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 3502092,
"best_combo": 404,
"count_300": 278,
Expand All @@ -25,7 +36,15 @@
{
"beatmap_id": 362949,
"mods": 1024,
"is_classic": true,
"mods_json": [
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 2475834,
"best_combo": 342,
"count_300": 283,
Expand All @@ -46,7 +65,18 @@
{
"beatmap_id": 362949,
"mods": 66,
"is_classic": true,
"mods_json": [
{
"acronym": "EZ"
},
{
"acronym": "DT"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 1718512,
"best_combo": 404,
"count_300": 279,
Expand All @@ -66,7 +96,15 @@
{
"beatmap_id": 362949,
"mods": 2,
"is_classic": true,
"mods_json": [
{
"acronym": "EZ"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 1602032,
"best_combo": 404,
"count_300": 289,
Expand All @@ -86,7 +124,21 @@
{
"beatmap_id": 362949,
"mods": 74,
"is_classic": true,
"mods_json": [
{
"acronym": "EZ"
},
{
"acronym": "HD"
},
{
"acronym": "DT"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 1078214,
"best_combo": 311,
"count_300": 274,
Expand All @@ -107,7 +159,18 @@
{
"beatmap_id": 362949,
"mods": 1088,
"is_classic": true,
"mods_json": [
{
"acronym": "DT"
},
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 1060393,
"best_combo": 180,
"count_300": 263,
Expand All @@ -129,7 +192,18 @@
{
"beatmap_id": 362949,
"mods": 1032,
"is_classic": true,
"mods_json": [
{
"acronym": "HD"
},
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 870281,
"best_combo": 119,
"count_300": 282,
Expand All @@ -150,7 +224,18 @@
{
"beatmap_id": 362949,
"mods": 1600,
"is_classic": true,
"mods_json": [
{
"acronym": "NC"
},
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 681752,
"best_combo": 128,
"count_300": 238,
Expand All @@ -172,7 +257,21 @@
{
"beatmap_id": 362949,
"mods": 1089,
"is_classic": true,
"mods_json": [
{
"acronym": "NF"
},
{
"acronym": "DT"
},
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 334024,
"best_combo": 103,
"count_300": 264,
Expand All @@ -194,7 +293,18 @@
{
"beatmap_id": 362949,
"mods": 1026,
"is_classic": true,
"mods_json": [
{
"acronym": "EZ"
},
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 302882,
"best_combo": 94,
"count_300": 259,
Expand All @@ -216,7 +326,24 @@
{
"beatmap_id": 362949,
"mods": 1097,
"is_classic": true,
"mods_json": [
{
"acronym": "NF"
},
{
"acronym": "HD"
},
{
"acronym": "DT"
},
{
"acronym": "FL"
},
{
"acronym": "CL"
}
],
"is_stable": true,
"score": 214157,
"best_combo": 52,
"count_300": 234,
Expand Down
Loading

0 comments on commit 1f46c84

Please sign in to comment.