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):
|
class ResetPasswordRequest(BaseModel):
|
||||||
uid: int
|
uid: int
|
||||||
email: EmailStr
|
email: str
|
||||||
new_password: str
|
new_password: str
|
||||||
|
|
||||||
class FriendRequest(BaseModel):
|
class FriendRequest(BaseModel):
|
||||||
|
@ -207,7 +207,33 @@ def join_match(request: JoinMatchRequest):
|
||||||
(player2_uid, request.match_id)
|
(player2_uid, request.match_id)
|
||||||
)
|
)
|
||||||
conn.commit()
|
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:
|
except Exception as e:
|
||||||
conn.rollback()
|
conn.rollback()
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
@ -215,6 +241,7 @@ def join_match(request: JoinMatchRequest):
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def calculate_elo(player1_elo, player2_elo, player1_score, player2_score):
|
def calculate_elo(player1_elo, player2_elo, player1_score, player2_score):
|
||||||
k_factor = 32
|
k_factor = 32
|
||||||
expected1 = 1 / (1 + 10 ** ((player2_elo - player1_elo) / 400))
|
expected1 = 1 / (1 + 10 ** ((player2_elo - player1_elo) / 400))
|
||||||
|
@ -427,6 +454,7 @@ def get_latest_commit_hashes():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"error": str(e)}
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
'''
|
||||||
## EXPERIMENTAL: 4 player match TS calculation
|
## EXPERIMENTAL: 4 player match TS calculation
|
||||||
import trueskill
|
import trueskill
|
||||||
ts = trueskill.TrueSkill(mu=25.0, sigma=8.333, beta=4.166, tau=0.083, draw_probability=0.1)
|
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()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
Loading…
Reference in a new issue