Endpoint for live player-scores

This commit is contained in:
Mawoka
2022-09-25 21:04:38 +02:00
parent 50eeb3fa84
commit c8402c697a
2 changed files with 7 additions and 1 deletions
+6
View File
@@ -348,3 +348,9 @@ async def set_next_question(game_pin: int, question_number: int, api_key: str):
},
room=game_pin,
)
@router.get("/live/scores", tags=["live"])
async def get_live_player_scores(game_pin: int):
res = await redis.hgetall(f"game_session:{game_pin}:player_scores")
return res
+1 -1
View File
@@ -272,7 +272,7 @@ async def submit_answer(sid: str, data: dict):
score = 0
if answer_right:
score = calculate_score(abs(diff) - latency, int(game_data.questions[int(data.question_index)].time))
await redis.hincrby(f"game_session:{session['game_pin']}:player_scores", session["username"], score)
if answers is None:
await redis.set(
f"game_session:{session['game_pin']}:{data.question_index}",