Update app.py
Browse files
app.py
CHANGED
|
@@ -34,10 +34,21 @@ def load_leaderboard_data(csv_file_path):
|
|
| 34 |
|
| 35 |
df['model_type_sort'] = df.apply(get_type_sort_value, axis=1)
|
| 36 |
|
| 37 |
-
# Convert date columns to datetime
|
| 38 |
for col in ['Release Date', 'Test Date']:
|
| 39 |
df[col] = pd.to_datetime(df[col], format='%m/%d/%Y', errors='coerce')
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Calculate the date two weeks ago from today
|
| 43 |
two_weeks_ago = (datetime.now() - timedelta(days=6)).strftime('%Y-%m-%d') #temp 6
|
|
@@ -66,7 +77,11 @@ def load_leaderboard_data(csv_file_path):
|
|
| 66 |
for col in numeric_columns:
|
| 67 |
df[col] = df[col].apply(lambda x: None if pd.isna(x) else round(x, 3))
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
return df
|
| 72 |
except Exception as e:
|
|
@@ -1108,9 +1123,6 @@ def update_grid(selected_types, show_na, pinned_rows):
|
|
| 1108 |
|
| 1109 |
filtered_df = df.copy()
|
| 1110 |
|
| 1111 |
-
# Sort by UGI initially
|
| 1112 |
-
filtered_df = filtered_df.sort_values('UGI π', ascending=False)
|
| 1113 |
-
|
| 1114 |
# Get pinned model IDs
|
| 1115 |
pinned_models = []
|
| 1116 |
if pinned_rows:
|
|
@@ -1143,8 +1155,11 @@ def update_grid(selected_types, show_na, pinned_rows):
|
|
| 1143 |
if show_na is None or not show_na:
|
| 1144 |
filtered_df = filtered_df[~has_na]
|
| 1145 |
|
| 1146 |
-
#
|
| 1147 |
-
filtered_df = filtered_df.sort_values(
|
|
|
|
|
|
|
|
|
|
| 1148 |
|
| 1149 |
records = filtered_df.to_dict('records')
|
| 1150 |
|
|
|
|
| 34 |
|
| 35 |
df['model_type_sort'] = df.apply(get_type_sort_value, axis=1)
|
| 36 |
|
| 37 |
+
# Convert date columns to datetime
|
| 38 |
for col in ['Release Date', 'Test Date']:
|
| 39 |
df[col] = pd.to_datetime(df[col], format='%m/%d/%Y', errors='coerce')
|
| 40 |
+
|
| 41 |
+
# Store original release date for sorting (earliest first for tertiary sort)
|
| 42 |
+
df['Release_Date_Sort'] = df['Release Date']
|
| 43 |
+
|
| 44 |
+
# Create a multi-tiered sorting key
|
| 45 |
+
# 1. UGI score (highest first) - primary sort
|
| 46 |
+
# 2. NatInt score (highest first) - secondary sort for same UGI
|
| 47 |
+
# 3. Release Date (earliest first) - tertiary sort for same UGI and NatInt
|
| 48 |
+
|
| 49 |
+
# Format dates as strings for display
|
| 50 |
+
df['Release Date'] = df['Release Date'].dt.strftime('%Y-%m-%d')
|
| 51 |
+
df['Test Date'] = df['Test Date'].dt.strftime('%Y-%m-%d')
|
| 52 |
|
| 53 |
# Calculate the date two weeks ago from today
|
| 54 |
two_weeks_ago = (datetime.now() - timedelta(days=6)).strftime('%Y-%m-%d') #temp 6
|
|
|
|
| 77 |
for col in numeric_columns:
|
| 78 |
df[col] = df[col].apply(lambda x: None if pd.isna(x) else round(x, 3))
|
| 79 |
|
| 80 |
+
# Sort with multiple keys in the required order
|
| 81 |
+
df = df.sort_values(
|
| 82 |
+
by=['UGI π', 'NatInt π‘', 'Release_Date_Sort'],
|
| 83 |
+
ascending=[False, False, True] # UGI desc, NatInt desc, Release date asc (earliest first)
|
| 84 |
+
)
|
| 85 |
|
| 86 |
return df
|
| 87 |
except Exception as e:
|
|
|
|
| 1123 |
|
| 1124 |
filtered_df = df.copy()
|
| 1125 |
|
|
|
|
|
|
|
|
|
|
| 1126 |
# Get pinned model IDs
|
| 1127 |
pinned_models = []
|
| 1128 |
if pinned_rows:
|
|
|
|
| 1155 |
if show_na is None or not show_na:
|
| 1156 |
filtered_df = filtered_df[~has_na]
|
| 1157 |
|
| 1158 |
+
# Use the same multi-key sorting as in load_leaderboard_data
|
| 1159 |
+
filtered_df = filtered_df.sort_values(
|
| 1160 |
+
by=['UGI π', 'NatInt π‘', 'Release_Date_Sort'],
|
| 1161 |
+
ascending=[False, False, True] # UGI desc, NatInt desc, Release date asc (earliest first)
|
| 1162 |
+
)
|
| 1163 |
|
| 1164 |
records = filtered_df.to_dict('records')
|
| 1165 |
|