✨ Endpoint for live player-scores
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}",
|
||||
|
||||
Reference in New Issue
Block a user