Muthuraja18 commited on
Commit
9fe47d5
·
verified ·
1 Parent(s): 96c6b3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -41
app.py CHANGED
@@ -176,6 +176,7 @@ def generate_ai_questions(topic, num_questions=5, gid=None, questions_db=None):
176
  -Different questions
177
  - ONLY valid JSON array.
178
  - No extra text.
 
179
  - No markdown.
180
  - No explanations.
181
  """
@@ -613,50 +614,18 @@ def get_weekly_leaderboard(limit=10, game_id=None):
613
  # ---------------------------
614
  # Get all-time leaderboard
615
  # ---------------------------
616
- def get_alltime_leaderboard(limit=10, game_id=None):
617
- """
618
- Returns top scores of all time
619
- Optional: filter by game_id
620
- """
621
-
622
- mode = st.session_state.get("mode_selection", "Offline")
623
- rows = []
624
-
625
- # ---------------- ONLINE MODE ----------------
626
- if mode == "Online":
627
- ok, _ = init_firebase_if_needed()
628
-
629
- if ok:
630
- fb_rows = fb_get("/leaderboard") or []
631
- if isinstance(fb_rows, dict):
632
- fb_rows = list(fb_rows.values())
633
- rows.extend(fb_rows)
634
-
635
- # Optional online CSV
636
- try:
637
- online_df = pd.read_csv("leaderboard_online.csv")
638
- rows.extend(online_df.to_dict("records"))
639
- except:
640
- pass
641
-
642
- # ---------------- OFFLINE MODE ----------------
643
- else:
644
- try:
645
- rows = pd.read_csv(LEADERBOARD_FILE).to_dict("records")
646
- except FileNotFoundError:
647
- rows = []
648
-
649
- if not rows:
650
- return []
651
-
652
- # Optional filter
653
- if game_id:
654
- rows = [r for r in rows if r.get("game_id") == game_id]
655
 
656
- rows.sort(key=lambda x: float(x.get("score", 0)), reverse=True)
 
657
 
658
- return rows[:limit]
659
 
 
660
 
661
 
662
 
 
176
  -Different questions
177
  - ONLY valid JSON array.
178
  - No extra text.
179
+ -updated questions show questions related answers in sports
180
  - No markdown.
181
  - No explanations.
182
  """
 
614
  # ---------------------------
615
  # Get all-time leaderboard
616
  # ---------------------------
617
+ def get_alltime_leaderboard():
618
+ try:
619
+ df = pd.read_csv(LEADERBOARD_FILE)
620
+ except FileNotFoundError:
621
+ return pd.DataFrame()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
 
623
+ if df.empty:
624
+ return df
625
 
626
+ df = df.sort_values(by="score", ascending=False)
627
 
628
+ return df.head(10)
629
 
630
 
631