Joffrey Thomas commited on
Commit
3e464ec
·
1 Parent(s): add3bed

upload AI scores too

Browse files
Files changed (2) hide show
  1. app.py +6 -6
  2. data_manager.py +10 -6
app.py CHANGED
@@ -881,11 +881,11 @@ with gr.Blocks(css=APP_CSS, title="LLM GeoGuessr") as demo:
881
  "round_number": round_idx,
882
  "actual_location": {"lat": rnd.get('lat'), "lng": rnd.get('lng')},
883
  "human_guess": rnd.get('human_guess'),
884
- "human_distance_km": rnd.get('human_distance_km'),
885
- "human_score": rnd.get('human_score'),
886
  "ai_guess": rnd.get('ai_guess'),
887
- "ai_distance_km": rnd.get('ai_distance_km'),
888
- "ai_score": rnd.get('ai_score'),
889
  "ai_analysis": rnd.get('ai_analysis', ''),
890
  }
891
  data_manager.update_game_record(username, round_data=round_record)
@@ -962,8 +962,8 @@ with gr.Blocks(css=APP_CSS, title="LLM GeoGuessr") as demo:
962
  total_human = sum(float(r.get('human_score', 0.0)) for r in sess.get('rounds', []))
963
  total_ai = sum(float(r.get('ai_score', 0.0)) for r in sess.get('rounds', []))
964
 
965
- # Update the final score (rounds already recorded incrementally)
966
- data_manager.update_game_record(username, final_score=total_human)
967
 
968
  winner_message = "It's a tie!"
969
  if total_human > total_ai:
 
881
  "round_number": round_idx,
882
  "actual_location": {"lat": rnd.get('lat'), "lng": rnd.get('lng')},
883
  "human_guess": rnd.get('human_guess'),
884
+ "human_distance_km": round(rnd.get('human_distance_km', 0), 2),
885
+ "human_score": int(round(rnd.get('human_score', 0))),
886
  "ai_guess": rnd.get('ai_guess'),
887
+ "ai_distance_km": round(rnd.get('ai_distance_km', 0), 2) if rnd.get('ai_distance_km') else None,
888
+ "ai_score": int(round(rnd.get('ai_score', 0))) if rnd.get('ai_score') else 0,
889
  "ai_analysis": rnd.get('ai_analysis', ''),
890
  }
891
  data_manager.update_game_record(username, round_data=round_record)
 
962
  total_human = sum(float(r.get('human_score', 0.0)) for r in sess.get('rounds', []))
963
  total_ai = sum(float(r.get('ai_score', 0.0)) for r in sess.get('rounds', []))
964
 
965
+ # Update the final scores (rounds already recorded incrementally)
966
+ data_manager.update_game_record(username, final_score=total_human, final_ai_score=total_ai)
967
 
968
  winner_message = "It's a tie!"
969
  if total_human > total_ai:
data_manager.py CHANGED
@@ -54,7 +54,7 @@ def get_user_game_today(username: str, todays_games: list) -> dict:
54
  return game
55
  return None
56
 
57
- def update_game_record(username: str, round_data: dict = None, final_score: float = None):
58
  """
59
  Updates or creates a game record for a user after each round.
60
  This ensures data is recorded incrementally and prevents abuse.
@@ -62,7 +62,8 @@ def update_game_record(username: str, round_data: dict = None, final_score: floa
62
  Args:
63
  username: The player's username
64
  round_data: Single round details to append to the record
65
- final_score: Final total score (only set when game is complete)
 
66
  """
67
  write_token = os.getenv("HF_TOKEN", "")
68
  if not write_token:
@@ -83,13 +84,16 @@ def update_game_record(username: str, round_data: dict = None, final_score: floa
83
  existing_game["rounds"] = []
84
  existing_game["rounds"].append(round_data)
85
  if final_score is not None:
86
- existing_game["score"] = final_score
87
  existing_game["completed"] = True
 
 
88
  else:
89
  # Create new game record
90
  game_record = {
91
  "username": username,
92
- "score": 0, # Will be updated when game completes
 
93
  "timestamp": datetime.now(timezone.utc).isoformat(),
94
  "rounds": [round_data] if round_data else [],
95
  "completed": False
@@ -118,9 +122,9 @@ def update_game_record(username: str, round_data: dict = None, final_score: floa
118
  if 'tmp_file_path' in locals() and os.path.exists(tmp_file_path):
119
  os.remove(tmp_file_path)
120
 
121
- def record_game(username: str, score: float, rounds_data: list = None):
122
  """
123
  Legacy function - now just calls update_game_record with final score.
124
  Kept for backwards compatibility.
125
  """
126
- update_game_record(username, final_score=score)
 
54
  return game
55
  return None
56
 
57
+ def update_game_record(username: str, round_data: dict = None, final_score: float = None, final_ai_score: float = None):
58
  """
59
  Updates or creates a game record for a user after each round.
60
  This ensures data is recorded incrementally and prevents abuse.
 
62
  Args:
63
  username: The player's username
64
  round_data: Single round details to append to the record
65
+ final_score: Final total human score (only set when game is complete)
66
+ final_ai_score: Final total AI score (only set when game is complete)
67
  """
68
  write_token = os.getenv("HF_TOKEN", "")
69
  if not write_token:
 
84
  existing_game["rounds"] = []
85
  existing_game["rounds"].append(round_data)
86
  if final_score is not None:
87
+ existing_game["human_score"] = int(round(final_score))
88
  existing_game["completed"] = True
89
+ if final_ai_score is not None:
90
+ existing_game["ai_score"] = int(round(final_ai_score))
91
  else:
92
  # Create new game record
93
  game_record = {
94
  "username": username,
95
+ "human_score": 0, # Will be updated when game completes
96
+ "ai_score": 0, # Will be updated when game completes
97
  "timestamp": datetime.now(timezone.utc).isoformat(),
98
  "rounds": [round_data] if round_data else [],
99
  "completed": False
 
122
  if 'tmp_file_path' in locals() and os.path.exists(tmp_file_path):
123
  os.remove(tmp_file_path)
124
 
125
+ def record_game(username: str, score: float, rounds_data: list = None, ai_score: float = None):
126
  """
127
  Legacy function - now just calls update_game_record with final score.
128
  Kept for backwards compatibility.
129
  """
130
+ update_game_record(username, final_score=score, final_ai_score=ai_score)