diff --git a/server/matchmaker/matchmaker_queue.py b/server/matchmaker/matchmaker_queue.py index 778407981..a12a05fe5 100644 --- a/server/matchmaker/matchmaker_queue.py +++ b/server/matchmaker/matchmaker_queue.py @@ -278,6 +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: + active_rating_groups = { + round(search.ratings[0].mean / granularity) * granularity for search in self._queue.keys() + } + else: + 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( @@ -288,9 +299,13 @@ def to_dict(self): ndigits=2 ), "num_players": self.num_players, + "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, the client is supposed to use active_rating_groups instead "boundary_75s": [search.boundary_75 for search in self._queue.keys()], - # TODO: Remove, the client should query the API for this + # DEPRECATED, the client should query the API for this "team_size": self.team_size, } diff --git a/tests/integration_tests/test_matchmaker.py b/tests/integration_tests/test_matchmaker.py index be58d7ae4..13d8891ed 100644 --- a/tests/integration_tests/test_matchmaker.py +++ b/tests/integration_tests/test_matchmaker.py @@ -450,6 +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["active_rating_groups"] == [] assert queue["boundary_80s"] == [] assert queue["boundary_75s"] == [] @@ -484,6 +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["active_rating_groups"] == [] assert queue["boundary_80s"] == [] assert queue["boundary_75s"] == [] @@ -512,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["boundary_80s"]: + if not queue_message["active_rating_groups"]: continue - assert len(queue_message["boundary_80s"]) == 1 + assert len(queue_message["active_rating_groups"]) == 1 return @@ -530,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["boundary_80s"]) == 0 + assert len(queue_message["active_rating_groups"]) == 0 @fast_forward(10) diff --git a/tests/integration_tests/test_teammatchmaker.py b/tests/integration_tests/test_teammatchmaker.py index e07d795ef..bc4603fc3 100644 --- a/tests/integration_tests/test_teammatchmaker.py +++ b/tests/integration_tests/test_teammatchmaker.py @@ -84,11 +84,14 @@ async def test_info_message(lobby_server): assert msg["queues"] for queue in msg["queues"]: boundaries = queue["boundary_80s"] + ratings = queue["active_rating_groups"] if queue["queue_name"] == "tmm2v2": assert boundaries == [[300, 700]] + assert ratings == [0] # team queues use displayed rating for matching else: assert boundaries == [] + assert ratings == [] @fast_forward(10) diff --git a/tests/unit_tests/test_lobbyconnection.py b/tests/unit_tests/test_lobbyconnection.py index 248102f7c..a402b9a58 100644 --- a/tests/unit_tests/test_lobbyconnection.py +++ b/tests/unit_tests/test_lobbyconnection.py @@ -1003,13 +1003,13 @@ async def test_command_matchmaker_info( player_factory, mocker ): - queue = queue_factory("test", rating_type=RatingType.LADDER_1V1) + queue = queue_factory("test", team_size=3, rating_type=RatingType.LADDER_1V1) queue.timer.next_queue_pop = 1_562_000_000 queue.push(Search([ player_factory(player_id=1, ladder_rating=(2000, 100), ladder_games=200), ])) queue.push(Search([ - player_factory(player_id=2, ladder_rating=(500, 120), ladder_games=100), + player_factory(player_id=2, ladder_rating=(600, 120), ladder_games=100), player_factory(player_id=3, ladder_rating=(1500, 500), ladder_games=0), ])) queue.push(Search([ @@ -1036,11 +1036,12 @@ async def test_command_matchmaker_info( { "queue_name": "test", "queue_pop_time": "2019-07-01T16:53:20+00:00", - "queue_pop_time_delta": 1.0, - "team_size": 1, + "queue_pop_time_delta": 1, + "team_size": 3, "num_players": 6, - "boundary_80s": [(1800, 2200), (300, 700), (800, 1200)], - "boundary_75s": [(1900, 2100), (400, 600), (900, 1100)] + "active_rating_groups": [125, 1125, 1700], + "boundary_80s": [(1800, 2200), (400, 800), (800, 1200)], + "boundary_75s": [(1900, 2100), (500, 700), (900, 1100)] } ] })