Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps committed Jul 11, 2024
1 parent 3c031b7 commit c0d1ac0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
20 changes: 14 additions & 6 deletions server/matchmaker/matchmaker_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,17 @@ def to_dict(self):
"""
Return a fuzzy representation of the searches currently in the queue
"""

granularity = 25
# Average rating is based on displayed rating, while the 1v1 queue uses mean rating for matching.
if self.team_size == 1:
ratings = {round(search.ratings[0].mean / 25) * 25 for search in self._queue.keys()}
active_rating_groups = {
round(search.ratings[0].mean / granularity) * granularity for search in self._queue.keys()
}
else:
ratings = {round(search.average_rating / 25) * 25 for search in self._queue.keys()}
active_rating_groups = {
round(search.average_rating / granularity) * granularity for search in self._queue.keys()
}
return {
"queue_name": self.name,
"queue_pop_time": datetime.fromtimestamp(
Expand All @@ -292,12 +299,13 @@ def to_dict(self):
ndigits=2
),
"num_players": self.num_players,
"ratings": sorted(ratings),
# DEPRECATED
"active_rating_groups": sorted(active_rating_groups),
# TODO: Remove deprecated keys
# DEPRECATED, the client is supposed to use active_rating_groups instead
"boundary_80s": [search.boundary_80 for search in self._queue.keys()],
# DEPRECATED
# DEPRECATED, the client is supposed to use active_rating_groups instead
"boundary_75s": [search.boundary_75 for search in self._queue.keys()],
# DEPRECATED TODO: Remove, the client should query the API for this
# DEPRECATED, the client should query the API for this
"team_size": self.team_size,
}

Expand Down
10 changes: 5 additions & 5 deletions tests/integration_tests/test_matchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def test_matchmaker_info_message(lobby_server, mocker):
assert queue["queue_pop_time_delta"] == math.ceil(
config.QUEUE_POP_TIME_MAX / 2
)
assert queue["ratings"] == []
assert queue["active_rating_groups"] == []
assert queue["boundary_80s"] == []
assert queue["boundary_75s"] == []

Expand Down Expand Up @@ -485,7 +485,7 @@ async def test_command_matchmaker_info(lobby_server, mocker):
assert queue["queue_pop_time_delta"] == math.ceil(
config.QUEUE_POP_TIME_MAX / 2
)
assert queue["ratings"] == []
assert queue["active_rating_groups"] == []
assert queue["boundary_80s"] == []
assert queue["boundary_75s"] == []

Expand Down Expand Up @@ -514,10 +514,10 @@ async def read_update_msg():
queue_message = next(
q for q in msg["queues"] if q["queue_name"] == "ladder1v1"
)
if not queue_message["ratings"]:
if not queue_message["active_rating_groups"]:
continue

assert len(queue_message["ratings"]) == 1
assert len(queue_message["active_rating_groups"]) == 1

return

Expand All @@ -532,7 +532,7 @@ async def read_update_msg():
msg = await read_until_command(proto, "matchmaker_info")

queue_message = next(q for q in msg["queues"] if q["queue_name"] == "ladder1v1")
assert len(queue_message["ratings"]) == 0
assert len(queue_message["active_rating_groups"]) == 0


@fast_forward(10)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_teammatchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def test_info_message(lobby_server):
assert msg["queues"]
for queue in msg["queues"]:
boundaries = queue["boundary_80s"]
ratings = queue["ratings"]
ratings = queue["active_rating_groups"]

if queue["queue_name"] == "tmm2v2":
assert boundaries == [[300, 700]]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ async def test_command_matchmaker_info(
"queue_pop_time_delta": 1,
"team_size": 3,
"num_players": 6,
"ratings": [125, 1125, 1700],
"active_rating_groups": [125, 1125, 1700],
"boundary_80s": [(1800, 2200), (400, 800), (800, 1200)],
"boundary_75s": [(1900, 2100), (500, 700), (900, 1100)]
}
Expand Down

0 comments on commit c0d1ac0

Please sign in to comment.