Return player names on match join
This commit is contained in:
parent
96d77a8e60
commit
732d236599
33
main.py
33
main.py
|
@ -26,7 +26,7 @@ class LoginRequest(BaseModel):
|
|||
|
||||
class ResetPasswordRequest(BaseModel):
|
||||
uid: int
|
||||
email: EmailStr
|
||||
email: str
|
||||
new_password: str
|
||||
|
||||
class FriendRequest(BaseModel):
|
||||
|
@ -207,7 +207,33 @@ def join_match(request: JoinMatchRequest):
|
|||
(player2_uid, request.match_id)
|
||||
)
|
||||
conn.commit()
|
||||
return {"message": "Joined match successfully", "match_id": request.match_id}
|
||||
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT
|
||||
m.match_id,
|
||||
m.player1_uid,
|
||||
m.player2_uid,
|
||||
u1.display_name AS player1_name,
|
||||
u2.display_name AS player2_name
|
||||
FROM matches m
|
||||
LEFT JOIN users u1 ON m.player1_uid = u1.uid
|
||||
LEFT JOIN users u2 ON m.player2_uid = u2.uid
|
||||
WHERE m.match_id = %s;
|
||||
""",
|
||||
(request.match_id,)
|
||||
)
|
||||
updated_match = cursor.fetchone()
|
||||
|
||||
return {
|
||||
"message": "Joined match successfully",
|
||||
"match_id": updated_match["match_id"],
|
||||
"player1_uid": updated_match["player1_uid"],
|
||||
"player2_uid": updated_match["player2_uid"],
|
||||
"player1_name": updated_match["player1_name"],
|
||||
"player2_name": updated_match["player2_name"],
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
conn.rollback()
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
@ -215,6 +241,7 @@ def join_match(request: JoinMatchRequest):
|
|||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
def calculate_elo(player1_elo, player2_elo, player1_score, player2_score):
|
||||
k_factor = 32
|
||||
expected1 = 1 / (1 + 10 ** ((player2_elo - player1_elo) / 400))
|
||||
|
@ -427,6 +454,7 @@ def get_latest_commit_hashes():
|
|||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
|
||||
'''
|
||||
## EXPERIMENTAL: 4 player match TS calculation
|
||||
import trueskill
|
||||
ts = trueskill.TrueSkill(mu=25.0, sigma=8.333, beta=4.166, tau=0.083, draw_probability=0.1)
|
||||
|
@ -539,3 +567,4 @@ async def end_four_match(request: EndFourMatch):
|
|||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue