diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index 3d82447..8bde33c 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -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 diff --git a/classquiz/socket_server/__init__.py b/classquiz/socket_server/__init__.py index 8ac4665..f870bbf 100644 --- a/classquiz/socket_server/__init__.py +++ b/classquiz/socket_server/__init__.py @@ -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}",