From ce38298666c080447e5cc530469dda6028d91389 Mon Sep 17 00:00:00 2001 From: NumberPigeon Date: Wed, 30 Aug 2023 22:02:22 +0800 Subject: [PATCH 1/3] feat: add mmr for User class --- sc2reader/objects.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sc2reader/objects.py b/sc2reader/objects.py index d6c9491..54fd3e8 100644 --- a/sc2reader/objects.py +++ b/sc2reader/objects.py @@ -285,6 +285,21 @@ def __init__(self, uid, init_data): #: This is deprecated because it doesn't actually work. self.recorder = None + #: The user's mmr at the time of the game + #: Currently, there are three cases observed for a user that does not have a current mmr: + #: 1. The user has no 'scaled_rating' key in their init_data, + #: 2. The user has a None value for their 'scaled_rating' key, or + #: 3. The user has a negative rating, often -36400. + #: For ease of use, this property will return None in both cases. + if ( + "scaled_rating" in init_data + and init_data["scaled_rating"] is not None + and init_data["scaled_rating"] > 0 + ): + self.mmr = init_data["scaled_rating"] + else: + self.mmr = None + @property def url(self): """ From 77a82cb77f4a2515f6ba0160f7c982146a993d06 Mon Sep 17 00:00:00 2001 From: NumberPigeon <108506296+NumberPigeon@users.noreply.github.com> Date: Wed, 30 Aug 2023 22:54:51 +0800 Subject: [PATCH 2/3] refactor: cleaner code Co-authored-by: Christian Clauss --- sc2reader/objects.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sc2reader/objects.py b/sc2reader/objects.py index 54fd3e8..b49f72a 100644 --- a/sc2reader/objects.py +++ b/sc2reader/objects.py @@ -291,14 +291,8 @@ def __init__(self, uid, init_data): #: 2. The user has a None value for their 'scaled_rating' key, or #: 3. The user has a negative rating, often -36400. #: For ease of use, this property will return None in both cases. - if ( - "scaled_rating" in init_data - and init_data["scaled_rating"] is not None - and init_data["scaled_rating"] > 0 - ): - self.mmr = init_data["scaled_rating"] - else: - self.mmr = None + mmr = int(init_data.get("scaled_rating") or 0) + self.mmr = mmr if mmr > 0 else None @property def url(self): From 50a137e778786d720b0633c31f5ded9fdc4e9a58 Mon Sep 17 00:00:00 2001 From: NumberPigeon <108506296+NumberPigeon@users.noreply.github.com> Date: Thu, 31 Aug 2023 00:03:27 +0800 Subject: [PATCH 3/3] doc: meaningful tmp var name, while keeping the attribute's name simple Co-authored-by: Christian Clauss --- sc2reader/objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sc2reader/objects.py b/sc2reader/objects.py index b49f72a..0c5877e 100644 --- a/sc2reader/objects.py +++ b/sc2reader/objects.py @@ -291,8 +291,8 @@ def __init__(self, uid, init_data): #: 2. The user has a None value for their 'scaled_rating' key, or #: 3. The user has a negative rating, often -36400. #: For ease of use, this property will return None in both cases. - mmr = int(init_data.get("scaled_rating") or 0) - self.mmr = mmr if mmr > 0 else None + matchmaking_rating = int(init_data.get("scaled_rating") or 0) + self.mmr = matchmaking_rating if matchmaking_rating > 0 else None @property def url(self):