ArkenB commited on
Commit
9ad4ee8
·
verified ·
1 Parent(s): be1f2c1

Update data/db.py

Browse files
Files changed (1) hide show
  1. data/db.py +11 -3
data/db.py CHANGED
@@ -98,18 +98,26 @@ def get_leaderboard(category: str, limit: int = 10) -> list[dict]:
98
  col = f"score_{category}"
99
  df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0)
100
  df["is_brag"] = pd.to_numeric(df["is_brag"], errors="coerce").fillna(0)
 
101
  result = (
102
  df[(df["is_brag"] == 0) & (df[col] > 0)]
103
  .sort_values(col, ascending=False)
104
  .head(limit)
 
105
  )
106
- keep = ["id", "text", col,
 
 
 
 
107
  "score_hilarious", "score_tragic", "score_unhinged",
108
  "score_awkward", "score_chaotic",
109
  "top_category", "commentary", "created_at"]
110
- result = result[keep].rename(columns={col: "score"})
111
- return result.to_dict(orient="records")
 
112
 
 
113
  def get_top_posts_for_podcast(category: str, limit: int = 10) -> list[dict]:
114
  df = _load(POSTS_CSV, POSTS_COLS)
115
  col = f"score_{category}"
 
98
  col = f"score_{category}"
99
  df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0)
100
  df["is_brag"] = pd.to_numeric(df["is_brag"], errors="coerce").fillna(0)
101
+
102
  result = (
103
  df[(df["is_brag"] == 0) & (df[col] > 0)]
104
  .sort_values(col, ascending=False)
105
  .head(limit)
106
+ .copy()
107
  )
108
+
109
+ # Rename BEFORE selecting to avoid duplicate "score" column
110
+ result = result.rename(columns={col: "score"})
111
+
112
+ keep = ["id", "text", "score",
113
  "score_hilarious", "score_tragic", "score_unhinged",
114
  "score_awkward", "score_chaotic",
115
  "top_category", "commentary", "created_at"]
116
+ keep = [c for c in keep if c in result.columns]
117
+
118
+ return result[keep].to_dict(orient="records")
119
 
120
+
121
  def get_top_posts_for_podcast(category: str, limit: int = 10) -> list[dict]:
122
  df = _load(POSTS_CSV, POSTS_COLS)
123
  col = f"score_{category}"