Skip to content

Commit

Permalink
matches: добавил список матчей в виде json-а для Робота
Browse files Browse the repository at this point in the history
  • Loading branch information
em92 committed Apr 6, 2024
1 parent 3318df6 commit 33fdfdc
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
16 changes: 15 additions & 1 deletion qllr/blueprints/matches/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from time import time

from asyncpg import Connection
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.routing import Route

from qllr.endpoints import Endpoint
from qllr.endpoints import Endpoint, NoCacheEndpoint
from qllr.templating import templates

from .methods import get_best_matches_of_player, get_last_matches
Expand Down Expand Up @@ -35,6 +37,17 @@ async def get_document(self, request: Request, con: Connection):
return templates.TemplateResponse("match_list.html", context)


class Last24HoursMatchesForRobot(NoCacheEndpoint):
async def get_document(self, request: Request, con: Connection):
gametype = request.path_params["gametype"]

context = await get_last_matches(
con, gametype, None, 0, int(time() - 60 * 60 * 24), int(time())
)
context["gametype"] = gametype
return JSONResponse(context)


routes = [
Route("/", endpoint=MatchesHtml),
Route("/{page:int}/", endpoint=MatchesHtml),
Expand All @@ -44,5 +57,6 @@ async def get_document(self, request: Request, con: Connection):
Route("/player/{steam_id:int}/{gametype}/{page:int}/", endpoint=MatchesHtml),
Route("/player/{steam_id:int}/{gametype}/top", endpoint=BestMatchesHtml),
Route("/{gametype}/", endpoint=MatchesHtml),
Route("/{gametype}/robot24hour.json", endpoint=Last24HoursMatchesForRobot),
Route("/{gametype}/{page:int}/", endpoint=MatchesHtml),
]
110 changes: 110 additions & 0 deletions tests/samples/match_list_24hour_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[
{
"datetime": "2019-03-10 05:23 +05",
"gametype": "tdm",
"map": "ragnarok",
"match_id": "7807b4f5-3c98-459c-b2f9-8ad6b4f75d58",
"team1_score": 147,
"team2_score": 157,
"timestamp": 1552177424
},
{
"datetime": "2019-03-10 04:52 +05",
"gametype": "tdm",
"map": "limbus",
"match_id": "a254f41d-125f-4d4b-b66e-564bf095b8f1",
"team1_score": 152,
"team2_score": 157,
"timestamp": 1552175533
},
{
"datetime": "2019-03-10 04:20 +05",
"gametype": "tdm",
"map": "hiddenfortress",
"match_id": "0778f428-2606-4f3c-83dc-b4099b970814",
"team1_score": 202,
"team2_score": 176,
"timestamp": 1552173642
},
{
"datetime": "2019-03-10 03:51 +05",
"gametype": "tdm",
"map": "purgatory",
"match_id": "6e34afa3-a8e0-4dba-a496-3fc17e615e8e",
"team1_score": 124,
"team2_score": 165,
"timestamp": 1552171881
},
{
"datetime": "2019-03-10 03:22 +05",
"gametype": "tdm",
"map": "grimdungeons",
"match_id": "9cbb425a-b7a9-4376-9b1a-e68e8622f851",
"team1_score": 128,
"team2_score": 118,
"timestamp": 1552170124
},
{
"datetime": "2019-03-10 02:48 +05",
"gametype": "tdm",
"map": "dreadfulplace",
"match_id": "55ef6e6a-f7ab-4f4b-ba26-c77963147b98",
"team1_score": 165,
"team2_score": 137,
"timestamp": 1552168122
},
{
"datetime": "2019-03-10 02:20 +05",
"gametype": "tdm",
"map": "purgatory",
"match_id": "a22d0122-1382-4533-bf01-403114fac08f",
"team1_score": 123,
"team2_score": 140,
"timestamp": 1552166418
},
{
"datetime": "2019-03-10 01:48 +05",
"gametype": "tdm",
"map": "purgatory",
"match_id": "c0ac214d-b228-440b-a3fd-b5fe6ce3081d",
"team1_score": 151,
"team2_score": 148,
"timestamp": 1552164488
},
{
"datetime": "2019-03-10 01:16 +05",
"gametype": "tdm",
"map": "dreadfulplace",
"match_id": "8d599bb1-6f7f-4dcf-9e95-da62f2b1a698",
"team1_score": 103,
"team2_score": 153,
"timestamp": 1552162600
},
{
"datetime": "2019-03-10 00:49 +05",
"gametype": "tdm",
"map": "hiddenfortress",
"match_id": "61aad138-b69d-4ae7-b02e-23a9cfb7935f",
"team1_score": 207,
"team2_score": 181,
"timestamp": 1552160956
},
{
"datetime": "2019-03-10 00:18 +05",
"gametype": "tdm",
"map": "purgatory",
"match_id": "4b4ee658-0140-46ea-9d84-5bb802199400",
"team1_score": 144,
"team2_score": 130,
"timestamp": 1552159115
},
{
"datetime": "2019-03-09 23:41 +05",
"gametype": "tdm",
"map": "ragnarok",
"match_id": "dd961b26-bafe-4bd3-a515-c0ec156fd85c",
"team1_score": 137,
"team2_score": 146,
"timestamp": 1552156868
}
]
11 changes: 11 additions & 0 deletions tests/samples/match_list_24hour_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"datetime": "2019-03-09 23:41 +05",
"gametype": "tdm",
"map": "ragnarok",
"match_id": "dd961b26-bafe-4bd3-a515-c0ec156fd85c",
"team1_score": 137,
"team2_score": 146,
"timestamp": 1552156868
}
]
21 changes: 21 additions & 0 deletions tests/test_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,24 @@ def test_old_routes(service, old_uri, new_uri):
def test_root_route(service):
resp = service.get("/", 307)
assert resp.headers["Location"].endswith("/matches/")


@mark.parametrize(
"time_value,match_sample",
[
param(1552177500, "match_list_24hour_1"),
param(1552159110, "match_list_24hour_2"),
],
)
def test_matches_json24hours(service, monkeypatch, time_value, match_sample):
from qllr.blueprints import matches

with monkeypatch.context() as m:

def time():
return time_value

m.setattr(matches, "time", time)

resp = service.get("/matches/tdm/robot24hour.json")
assert resp.json()["matches"] == read_json_sample(match_sample)

0 comments on commit 33fdfdc

Please sign in to comment.