|
1 | 1 | from fastapi import APIRouter, Request, Response, status |
2 | 2 | from fastapi.responses import JSONResponse |
3 | 3 | from pydantic import BaseModel |
| 4 | +from decimal import Decimal |
| 5 | +import simplejson as json |
4 | 6 | from sql import selectQuery, insertQuery |
5 | 7 | from globals import ( |
6 | 8 | set_cache, |
7 | 9 | get_cache, |
8 | 10 | ) |
9 | | -import time, json, surftimer.queries |
| 11 | +import time, surftimer.queries |
10 | 12 |
|
11 | 13 |
|
12 | 14 | class NewBonus(BaseModel): |
13 | 15 | steamid32: str |
14 | 16 | name: str |
15 | 17 | mapname: str |
16 | | - runtime: int |
| 18 | + runtime: Decimal |
17 | 19 | zonegroup: int |
18 | 20 | velStartXY: int |
19 | 21 | velStartXYZ: int |
@@ -42,8 +44,8 @@ def insertBonus( |
42 | 44 | response: Response, |
43 | 45 | data: NewBonus, |
44 | 46 | ): |
45 | | - """Inserts a new record to the table\n |
46 | | - ```char sql_insertLatestRecords[] = ....```""" |
| 47 | + """Inserts a new `Bonus` record to the table\n |
| 48 | + ```char sql_insertBonus[] = ....```""" |
47 | 49 | tic = time.perf_counter() |
48 | 50 |
|
49 | 51 | sql = surftimer.queries.sql_insertBonus.format( |
@@ -127,7 +129,7 @@ def selectBonusCount(request: Request, response: Response, mapname: str): |
127 | 129 | if cached_data: |
128 | 130 | print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)") |
129 | 131 | return JSONResponse( |
130 | | - status_code=status.HTTP_200_OK, content=json.loads(cached_data) |
| 132 | + status_code=status.HTTP_200_OK, content=json.loads(cached_data, use_decimal=True, parse_nan=True) |
131 | 133 | ) |
132 | 134 |
|
133 | 135 | xquery = selectQuery(surftimer.queries.sql_selectBonusCount.format(mapname)) |
@@ -166,7 +168,7 @@ def selectPersonalBonusRecords( |
166 | 168 | print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)") |
167 | 169 |
|
168 | 170 | return JSONResponse( |
169 | | - status_code=status.HTTP_200_OK, content=json.loads(cached_data) |
| 171 | + status_code=status.HTTP_200_OK, content=json.loads(cached_data, use_decimal=True, parse_nan=True) |
170 | 172 | ) |
171 | 173 |
|
172 | 174 | xquery = selectQuery( |
@@ -210,7 +212,7 @@ def selectPlayerRankBonus( |
210 | 212 | if cached_data is not None: |
211 | 213 | print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)") |
212 | 214 | return JSONResponse( |
213 | | - status_code=status.HTTP_200_OK, content=json.loads(cached_data) |
| 215 | + status_code=status.HTTP_200_OK, content=json.loads(cached_data, use_decimal=True, parse_nan=True) |
214 | 216 | ) |
215 | 217 |
|
216 | 218 | xquery = selectQuery( |
@@ -257,7 +259,7 @@ def selectFastestBonus( |
257 | 259 | if cached_data is not None: |
258 | 260 | print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)") |
259 | 261 | return JSONResponse( |
260 | | - status_code=status.HTTP_200_OK, content=json.loads(cached_data) |
| 262 | + status_code=status.HTTP_200_OK, content=json.loads(cached_data, use_decimal=True, parse_nan=True) |
261 | 263 | ) |
262 | 264 |
|
263 | 265 | xquery = selectQuery(surftimer.queries.sql_selectFastestBonus.format(mapname)) |
@@ -296,7 +298,7 @@ def selectAllBonusTimesinMap( |
296 | 298 | if cached_data is not None: |
297 | 299 | print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)") |
298 | 300 | return JSONResponse( |
299 | | - status_code=status.HTTP_200_OK, content=json.loads(cached_data) |
| 301 | + status_code=status.HTTP_200_OK, content=json.loads(cached_data, use_decimal=True, parse_nan=True) |
300 | 302 | ) |
301 | 303 |
|
302 | 304 | xquery = selectQuery(surftimer.queries.sql_selectAllBonusTimesinMap.format(mapname)) |
@@ -337,7 +339,7 @@ def selectTopBonusSurfers( |
337 | 339 | if cached_data is not None: |
338 | 340 | print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)") |
339 | 341 | return JSONResponse( |
340 | | - status_code=status.HTTP_200_OK, content=json.loads(cached_data) |
| 342 | + status_code=status.HTTP_200_OK, content=json.loads(cached_data, use_decimal=True, parse_nan=True) |
341 | 343 | ) |
342 | 344 |
|
343 | 345 | xquery = selectQuery( |
|
0 commit comments