Spaces:
Running
Running
Yuxuan-Zhang-Dexter
commited on
Commit
ยท
90adead
1
Parent(s):
455f800
update app
Browse files
app.py
CHANGED
@@ -133,12 +133,7 @@ def load_rank_data(time_point):
|
|
133 |
return None
|
134 |
return None
|
135 |
|
136 |
-
def update_leaderboard(mario_overall,
|
137 |
-
sokoban_overall, sokoban_details,
|
138 |
-
_2048_overall, _2048_details,
|
139 |
-
candy_overall, candy_details,
|
140 |
-
tetris_overall, tetris_details,
|
141 |
-
tetris_plan_overall, tetris_plan_details):
|
142 |
global leaderboard_state
|
143 |
|
144 |
# Convert current checkbox states to dictionary for easier comparison
|
@@ -151,92 +146,6 @@ def update_leaderboard(mario_overall, mario_details,
|
|
151 |
"Tetris (planning only)": tetris_plan_overall
|
152 |
}
|
153 |
|
154 |
-
current_details = {
|
155 |
-
"Super Mario Bros": mario_details,
|
156 |
-
"Sokoban": sokoban_details,
|
157 |
-
"2048": _2048_details,
|
158 |
-
"Candy Crash": candy_details,
|
159 |
-
"Tetris (complete)": tetris_details,
|
160 |
-
"Tetris (planning only)": tetris_plan_details
|
161 |
-
}
|
162 |
-
|
163 |
-
# Find which game's state changed
|
164 |
-
changed_game = None
|
165 |
-
for game in current_overall.keys():
|
166 |
-
if (current_overall[game] != leaderboard_state["previous_overall"][game] or
|
167 |
-
current_details[game] != leaderboard_state["previous_details"][game]):
|
168 |
-
changed_game = game
|
169 |
-
break
|
170 |
-
|
171 |
-
if changed_game:
|
172 |
-
# If a game's details checkbox was checked
|
173 |
-
if current_details[changed_game] and not leaderboard_state["previous_details"][changed_game]:
|
174 |
-
# Reset all other games' states
|
175 |
-
for game in current_overall.keys():
|
176 |
-
if game != changed_game:
|
177 |
-
current_overall[game] = False
|
178 |
-
current_details[game] = False
|
179 |
-
leaderboard_state["previous_overall"][game] = False
|
180 |
-
leaderboard_state["previous_details"][game] = False
|
181 |
-
|
182 |
-
# Update state for the selected game
|
183 |
-
leaderboard_state["current_game"] = changed_game
|
184 |
-
leaderboard_state["previous_overall"][changed_game] = True
|
185 |
-
leaderboard_state["previous_details"][changed_game] = True
|
186 |
-
current_overall[changed_game] = True
|
187 |
-
|
188 |
-
# If a game's overall checkbox was checked
|
189 |
-
elif current_overall[changed_game] and not leaderboard_state["previous_overall"][changed_game]:
|
190 |
-
# If we were in details view for another game, switch to overall view
|
191 |
-
if leaderboard_state["current_game"] and leaderboard_state["previous_details"][leaderboard_state["current_game"]]:
|
192 |
-
# Reset previous game's details
|
193 |
-
leaderboard_state["previous_details"][leaderboard_state["current_game"]] = False
|
194 |
-
current_details[leaderboard_state["current_game"]] = False
|
195 |
-
leaderboard_state["current_game"] = None
|
196 |
-
|
197 |
-
# Update state
|
198 |
-
leaderboard_state["previous_overall"][changed_game] = True
|
199 |
-
leaderboard_state["previous_details"][changed_game] = False
|
200 |
-
|
201 |
-
# If a game's overall checkbox was unchecked
|
202 |
-
elif not current_overall[changed_game] and leaderboard_state["previous_overall"][changed_game]:
|
203 |
-
# If we're in details view, don't allow unchecking the overall checkbox
|
204 |
-
if leaderboard_state["current_game"] == changed_game:
|
205 |
-
current_overall[changed_game] = True
|
206 |
-
else:
|
207 |
-
leaderboard_state["previous_overall"][changed_game] = False
|
208 |
-
if leaderboard_state["current_game"] == changed_game:
|
209 |
-
leaderboard_state["current_game"] = None
|
210 |
-
|
211 |
-
# If a game's details checkbox was unchecked
|
212 |
-
elif not current_details[changed_game] and leaderboard_state["previous_details"][changed_game]:
|
213 |
-
leaderboard_state["previous_details"][changed_game] = False
|
214 |
-
if leaderboard_state["current_game"] == changed_game:
|
215 |
-
leaderboard_state["current_game"] = None
|
216 |
-
# When exiting details view, reset to show all games
|
217 |
-
for game in current_overall.keys():
|
218 |
-
current_overall[game] = True
|
219 |
-
current_details[game] = False
|
220 |
-
leaderboard_state["previous_overall"][game] = True
|
221 |
-
leaderboard_state["previous_details"][game] = False
|
222 |
-
|
223 |
-
# Special case: If all games are selected and we're trying to view details
|
224 |
-
all_games_selected = all(current_overall.values()) and not any(current_details.values())
|
225 |
-
if all_games_selected and changed_game and current_details[changed_game]:
|
226 |
-
# Reset all other games' states
|
227 |
-
for game in current_overall.keys():
|
228 |
-
if game != changed_game:
|
229 |
-
current_overall[game] = False
|
230 |
-
current_details[game] = False
|
231 |
-
leaderboard_state["previous_overall"][game] = False
|
232 |
-
leaderboard_state["previous_details"][game] = False
|
233 |
-
|
234 |
-
# Update state for the selected game
|
235 |
-
leaderboard_state["current_game"] = changed_game
|
236 |
-
leaderboard_state["previous_overall"][changed_game] = True
|
237 |
-
leaderboard_state["previous_details"][changed_game] = True
|
238 |
-
current_overall[changed_game] = True
|
239 |
-
|
240 |
# Build dictionary for selected games
|
241 |
selected_games = {
|
242 |
"Super Mario Bros": current_overall["Super Mario Bros"],
|
@@ -247,42 +156,18 @@ def update_leaderboard(mario_overall, mario_details,
|
|
247 |
"Tetris (planning only)": current_overall["Tetris (planning only)"]
|
248 |
}
|
249 |
|
250 |
-
# Get the appropriate DataFrame and charts
|
251 |
-
|
252 |
-
|
253 |
-
if leaderboard_state["current_game"] == "Super Mario Bros":
|
254 |
-
df = get_mario_leaderboard(rank_data)
|
255 |
-
elif leaderboard_state["current_game"] == "Sokoban":
|
256 |
-
df = get_sokoban_leaderboard(rank_data)
|
257 |
-
elif leaderboard_state["current_game"] == "2048":
|
258 |
-
df = get_2048_leaderboard(rank_data)
|
259 |
-
elif leaderboard_state["current_game"] == "Candy Crash":
|
260 |
-
df = get_candy_leaderboard(rank_data)
|
261 |
-
elif leaderboard_state["current_game"] == "Tetris (complete)":
|
262 |
-
df = get_tetris_leaderboard(rank_data)
|
263 |
-
else: # Tetris (planning only)
|
264 |
-
df = get_tetris_planning_leaderboard(rank_data)
|
265 |
-
|
266 |
-
# Always create a new chart for detailed view
|
267 |
-
chart = create_horizontal_bar_chart(df, leaderboard_state["current_game"])
|
268 |
-
# For detailed view, we'll use the same chart for all visualizations
|
269 |
-
radar_chart = chart
|
270 |
-
group_bar_chart = chart
|
271 |
-
else:
|
272 |
-
# For overall view
|
273 |
-
df, group_bar_chart = get_combined_leaderboard_with_group_bar(rank_data, selected_games)
|
274 |
-
# Use the same selected_games for radar chart
|
275 |
-
_, radar_chart = get_combined_leaderboard_with_single_radar(rank_data, selected_games)
|
276 |
-
chart = group_bar_chart
|
277 |
|
278 |
-
# Return exactly
|
279 |
-
return (df,
|
280 |
-
current_overall["Super Mario Bros"],
|
281 |
-
current_overall["Sokoban"],
|
282 |
-
current_overall["2048"],
|
283 |
-
current_overall["Candy Crash"],
|
284 |
-
current_overall["Tetris (complete)"],
|
285 |
-
current_overall["Tetris (planning only)"]
|
286 |
|
287 |
def update_leaderboard_with_time(time_point, mario_overall, mario_details,
|
288 |
sokoban_overall, sokoban_details,
|
@@ -297,12 +182,9 @@ def update_leaderboard_with_time(time_point, mario_overall, mario_details,
|
|
297 |
rank_data = new_rank_data
|
298 |
|
299 |
# Use the existing update_leaderboard function
|
300 |
-
return update_leaderboard(mario_overall,
|
301 |
-
|
302 |
-
|
303 |
-
candy_overall, candy_details,
|
304 |
-
tetris_overall, tetris_details,
|
305 |
-
tetris_plan_overall, tetris_plan_details)
|
306 |
|
307 |
def get_initial_state():
|
308 |
"""Get the initial state for the leaderboard"""
|
@@ -348,14 +230,9 @@ def clear_filters():
|
|
348 |
# Reset the leaderboard state to match the default checkbox states
|
349 |
leaderboard_state = get_initial_state()
|
350 |
|
351 |
-
# Return exactly
|
352 |
-
return (df,
|
353 |
-
True,
|
354 |
-
True, False, # sokoban
|
355 |
-
True, False, # 2048
|
356 |
-
True, False, # candy
|
357 |
-
True, False, # tetris
|
358 |
-
True, False) # tetris plan
|
359 |
|
360 |
def create_timeline_slider():
|
361 |
"""Create a custom timeline slider component"""
|
@@ -745,13 +622,6 @@ def build_app():
|
|
745 |
with gr.Row():
|
746 |
gr.Markdown("### ๐ Data Visualization")
|
747 |
|
748 |
-
# Detailed view visualization (single chart)
|
749 |
-
detailed_visualization = gr.Plot(
|
750 |
-
label="Performance Visualization",
|
751 |
-
visible=False,
|
752 |
-
elem_classes="visualization-container"
|
753 |
-
)
|
754 |
-
|
755 |
# Overall view visualizations (two charts)
|
756 |
with gr.Row(visible=True) as overall_visualizations:
|
757 |
with gr.Column(scale=1):
|
@@ -772,27 +642,21 @@ def build_app():
|
|
772 |
with gr.Column():
|
773 |
gr.Markdown("**๐ฎ Super Mario Bros**")
|
774 |
mario_overall = gr.Checkbox(label="Super Mario Bros Score", value=True)
|
775 |
-
mario_details = gr.Checkbox(label="Super Mario Bros Details", value=False)
|
776 |
with gr.Column():
|
777 |
gr.Markdown("**๐ฆ Sokoban**")
|
778 |
sokoban_overall = gr.Checkbox(label="Sokoban Score", value=True)
|
779 |
-
sokoban_details = gr.Checkbox(label="Sokoban Details", value=False)
|
780 |
with gr.Column():
|
781 |
gr.Markdown("**๐ข 2048**")
|
782 |
_2048_overall = gr.Checkbox(label="2048 Score", value=True)
|
783 |
-
_2048_details = gr.Checkbox(label="2048 Details", value=False)
|
784 |
with gr.Column():
|
785 |
gr.Markdown("**๐ฌ Candy Crash**")
|
786 |
candy_overall = gr.Checkbox(label="Candy Crash Score", value=True)
|
787 |
-
candy_details = gr.Checkbox(label="Candy Crash Details", value=False)
|
788 |
with gr.Column():
|
789 |
gr.Markdown("**๐ฏ Tetris (complete)**")
|
790 |
tetris_overall = gr.Checkbox(label="Tetris (complete) Score", value=True)
|
791 |
-
tetris_details = gr.Checkbox(label="Tetris (complete) Details", value=False)
|
792 |
with gr.Column():
|
793 |
gr.Markdown("**๐ Tetris (planning)**")
|
794 |
tetris_plan_overall = gr.Checkbox(label="Tetris (planning) Score", value=True)
|
795 |
-
tetris_plan_details = gr.Checkbox(label="Tetris (planning) Details", value=False)
|
796 |
|
797 |
# Controls
|
798 |
with gr.Row():
|
@@ -822,26 +686,19 @@ def build_app():
|
|
822 |
|
823 |
# List of all checkboxes
|
824 |
checkbox_list = [
|
825 |
-
mario_overall,
|
826 |
-
sokoban_overall,
|
827 |
-
_2048_overall,
|
828 |
-
candy_overall,
|
829 |
-
tetris_overall,
|
830 |
-
tetris_plan_overall
|
831 |
]
|
832 |
|
833 |
# Update visualizations when checkboxes change
|
834 |
def update_visualizations(*checkbox_states):
|
835 |
-
#
|
836 |
-
is_details_view = any([
|
837 |
-
checkbox_states[1], checkbox_states[3], checkbox_states[5],
|
838 |
-
checkbox_states[7], checkbox_states[9], checkbox_states[11]
|
839 |
-
])
|
840 |
-
|
841 |
-
# Update visibility of visualization blocks
|
842 |
return {
|
843 |
-
|
844 |
-
overall_visualizations: gr.update(visible=not is_details_view)
|
845 |
}
|
846 |
|
847 |
# Add change event to all checkboxes
|
@@ -849,7 +706,7 @@ def build_app():
|
|
849 |
checkbox.change(
|
850 |
update_visualizations,
|
851 |
inputs=checkbox_list,
|
852 |
-
outputs=[
|
853 |
)
|
854 |
|
855 |
# Update leaderboard and visualizations when checkboxes change
|
@@ -859,7 +716,6 @@ def build_app():
|
|
859 |
inputs=checkbox_list,
|
860 |
outputs=[
|
861 |
leaderboard_df,
|
862 |
-
detailed_visualization,
|
863 |
radar_visualization,
|
864 |
group_bar_visualization
|
865 |
] + checkbox_list
|
@@ -871,7 +727,6 @@ def build_app():
|
|
871 |
inputs=[],
|
872 |
outputs=[
|
873 |
leaderboard_df,
|
874 |
-
detailed_visualization,
|
875 |
radar_visualization,
|
876 |
group_bar_visualization
|
877 |
] + checkbox_list
|
@@ -883,7 +738,6 @@ def build_app():
|
|
883 |
inputs=[],
|
884 |
outputs=[
|
885 |
leaderboard_df,
|
886 |
-
detailed_visualization,
|
887 |
radar_visualization,
|
888 |
group_bar_visualization
|
889 |
] + checkbox_list
|
|
|
133 |
return None
|
134 |
return None
|
135 |
|
136 |
+
def update_leaderboard(mario_overall, sokoban_overall, _2048_overall, candy_overall, tetris_overall, tetris_plan_overall):
|
|
|
|
|
|
|
|
|
|
|
137 |
global leaderboard_state
|
138 |
|
139 |
# Convert current checkbox states to dictionary for easier comparison
|
|
|
146 |
"Tetris (planning only)": tetris_plan_overall
|
147 |
}
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
# Build dictionary for selected games
|
150 |
selected_games = {
|
151 |
"Super Mario Bros": current_overall["Super Mario Bros"],
|
|
|
156 |
"Tetris (planning only)": current_overall["Tetris (planning only)"]
|
157 |
}
|
158 |
|
159 |
+
# Get the appropriate DataFrame and charts
|
160 |
+
df, group_bar_chart = get_combined_leaderboard_with_group_bar(rank_data, selected_games)
|
161 |
+
_, radar_chart = get_combined_leaderboard_with_single_radar(rank_data, selected_games)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
+
# Return exactly 9 values to match the expected outputs
|
164 |
+
return (df, radar_chart, group_bar_chart,
|
165 |
+
current_overall["Super Mario Bros"],
|
166 |
+
current_overall["Sokoban"],
|
167 |
+
current_overall["2048"],
|
168 |
+
current_overall["Candy Crash"],
|
169 |
+
current_overall["Tetris (complete)"],
|
170 |
+
current_overall["Tetris (planning only)"])
|
171 |
|
172 |
def update_leaderboard_with_time(time_point, mario_overall, mario_details,
|
173 |
sokoban_overall, sokoban_details,
|
|
|
182 |
rank_data = new_rank_data
|
183 |
|
184 |
# Use the existing update_leaderboard function
|
185 |
+
return update_leaderboard(mario_overall, sokoban_overall,
|
186 |
+
_2048_overall, candy_overall,
|
187 |
+
tetris_overall, tetris_plan_overall)
|
|
|
|
|
|
|
188 |
|
189 |
def get_initial_state():
|
190 |
"""Get the initial state for the leaderboard"""
|
|
|
230 |
# Reset the leaderboard state to match the default checkbox states
|
231 |
leaderboard_state = get_initial_state()
|
232 |
|
233 |
+
# Return exactly 9 values to match the expected outputs
|
234 |
+
return (df, radar_chart, group_bar_chart,
|
235 |
+
True, True, True, True, True, True)
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
def create_timeline_slider():
|
238 |
"""Create a custom timeline slider component"""
|
|
|
622 |
with gr.Row():
|
623 |
gr.Markdown("### ๐ Data Visualization")
|
624 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
625 |
# Overall view visualizations (two charts)
|
626 |
with gr.Row(visible=True) as overall_visualizations:
|
627 |
with gr.Column(scale=1):
|
|
|
642 |
with gr.Column():
|
643 |
gr.Markdown("**๐ฎ Super Mario Bros**")
|
644 |
mario_overall = gr.Checkbox(label="Super Mario Bros Score", value=True)
|
|
|
645 |
with gr.Column():
|
646 |
gr.Markdown("**๐ฆ Sokoban**")
|
647 |
sokoban_overall = gr.Checkbox(label="Sokoban Score", value=True)
|
|
|
648 |
with gr.Column():
|
649 |
gr.Markdown("**๐ข 2048**")
|
650 |
_2048_overall = gr.Checkbox(label="2048 Score", value=True)
|
|
|
651 |
with gr.Column():
|
652 |
gr.Markdown("**๐ฌ Candy Crash**")
|
653 |
candy_overall = gr.Checkbox(label="Candy Crash Score", value=True)
|
|
|
654 |
with gr.Column():
|
655 |
gr.Markdown("**๐ฏ Tetris (complete)**")
|
656 |
tetris_overall = gr.Checkbox(label="Tetris (complete) Score", value=True)
|
|
|
657 |
with gr.Column():
|
658 |
gr.Markdown("**๐ Tetris (planning)**")
|
659 |
tetris_plan_overall = gr.Checkbox(label="Tetris (planning) Score", value=True)
|
|
|
660 |
|
661 |
# Controls
|
662 |
with gr.Row():
|
|
|
686 |
|
687 |
# List of all checkboxes
|
688 |
checkbox_list = [
|
689 |
+
mario_overall,
|
690 |
+
sokoban_overall,
|
691 |
+
_2048_overall,
|
692 |
+
candy_overall,
|
693 |
+
tetris_overall,
|
694 |
+
tetris_plan_overall
|
695 |
]
|
696 |
|
697 |
# Update visualizations when checkboxes change
|
698 |
def update_visualizations(*checkbox_states):
|
699 |
+
# Always show overall view with both charts
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
return {
|
701 |
+
overall_visualizations: gr.update(visible=True)
|
|
|
702 |
}
|
703 |
|
704 |
# Add change event to all checkboxes
|
|
|
706 |
checkbox.change(
|
707 |
update_visualizations,
|
708 |
inputs=checkbox_list,
|
709 |
+
outputs=[overall_visualizations]
|
710 |
)
|
711 |
|
712 |
# Update leaderboard and visualizations when checkboxes change
|
|
|
716 |
inputs=checkbox_list,
|
717 |
outputs=[
|
718 |
leaderboard_df,
|
|
|
719 |
radar_visualization,
|
720 |
group_bar_visualization
|
721 |
] + checkbox_list
|
|
|
727 |
inputs=[],
|
728 |
outputs=[
|
729 |
leaderboard_df,
|
|
|
730 |
radar_visualization,
|
731 |
group_bar_visualization
|
732 |
] + checkbox_list
|
|
|
738 |
inputs=[],
|
739 |
outputs=[
|
740 |
leaderboard_df,
|
|
|
741 |
radar_visualization,
|
742 |
group_bar_visualization
|
743 |
] + checkbox_list
|