Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# app.py
|
| 2 |
-
# @title Beer Game Final Version (
|
| 3 |
# -----------------------------------------------------------------------------
|
| 4 |
# 1. Import Libraries
|
| 5 |
# -----------------------------------------------------------------------------
|
|
@@ -38,6 +38,7 @@ FACTORY_LEAD_TIME = 1
|
|
| 38 |
FACTORY_SHIPPING_DELAY = 1
|
| 39 |
HOLDING_COST = 0.5
|
| 40 |
BACKLOG_COST = 1.0
|
|
|
|
| 41 |
|
| 42 |
# --- NEW: Comprehension Questions Data ---
|
| 43 |
COMPREHENSION_QUESTIONS = [
|
|
@@ -57,7 +58,7 @@ COMPREHENSION_QUESTIONS = [
|
|
| 57 |
"correct_index": 2, # 3 weeks
|
| 58 |
},
|
| 59 |
{
|
| 60 |
-
"q": "4. At the end of the week, your holding cost is
|
| 61 |
"options": ["$7.50", "$15.00", "$15.50", "$0.00"],
|
| 62 |
"correct_index": 1, # 15.00
|
| 63 |
},
|
|
@@ -477,7 +478,7 @@ def save_leaderboard_data(data):
|
|
| 477 |
local_path = LOCAL_LOG_DIR / LEADERBOARD_FILE
|
| 478 |
with open(local_path, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2, ensure_ascii=False)
|
| 479 |
hf_api.upload_file(path_or_fileobj=str(local_path), path_in_repo=LEADERBOARD_FILE, repo_id=HF_REPO_ID, repo_type="dataset", token=HF_TOKEN, commit_message="Update leaderboard")
|
| 480 |
-
st.sidebar.success("Leaderboard updated!")
|
| 481 |
st.cache_data.clear()
|
| 482 |
except Exception as e:
|
| 483 |
st.sidebar.error(f"Failed to upload leaderboard: {e}")
|
|
@@ -531,7 +532,7 @@ def display_rankings(df, top_n=10):
|
|
| 531 |
def show_leaderboard_ui():
|
| 532 |
st.markdown("---")
|
| 533 |
st.header("📊 The Bullwhip Leaderboard")
|
| 534 |
-
st.caption("
|
| 535 |
leaderboard_data = load_leaderboard_data()
|
| 536 |
if not leaderboard_data:
|
| 537 |
st.info("No leaderboard data yet. Be the first to finish a game!")
|
|
@@ -587,7 +588,7 @@ def save_logs_and_upload(state: dict):
|
|
| 587 |
st.error(f"Error processing or saving log CSV: {e_save}")
|
| 588 |
return
|
| 589 |
if logs_df is None: return
|
| 590 |
-
st.subheader("Updating Leaderboard...")
|
| 591 |
try:
|
| 592 |
human_role = state['human_role']
|
| 593 |
|
|
@@ -780,7 +781,8 @@ else:
|
|
| 780 |
except Exception as e:
|
| 781 |
st.error(f"Error generating final report or saving data: {e}")
|
| 782 |
|
| 783 |
-
show_leaderboard_ui()
|
|
|
|
| 784 |
if st.button("✨ Start a New Game"):
|
| 785 |
# 在重置游戏时清除所有与实验相关的时间戳
|
| 786 |
if 'consent_timestamp' in st.session_state: del st.session_state['consent_timestamp']
|
|
@@ -1001,4 +1003,25 @@ else:
|
|
| 1001 |
st.rerun()
|
| 1002 |
# ===========================================================
|
| 1003 |
|
| 1004 |
-
show_leaderboard_ui()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
# @title Beer Game Final Version (v13 - Hidden Leaderboard for Instructor)
|
| 3 |
# -----------------------------------------------------------------------------
|
| 4 |
# 1. Import Libraries
|
| 5 |
# -----------------------------------------------------------------------------
|
|
|
|
| 38 |
FACTORY_SHIPPING_DELAY = 1
|
| 39 |
HOLDING_COST = 0.5
|
| 40 |
BACKLOG_COST = 1.0
|
| 41 |
+
ADMIN_PASSWORD = "lixinyu" # <--- SET YOUR INSTRUCTOR PASSWORD HERE
|
| 42 |
|
| 43 |
# --- NEW: Comprehension Questions Data ---
|
| 44 |
COMPREHENSION_QUESTIONS = [
|
|
|
|
| 58 |
"correct_index": 2, # 3 weeks
|
| 59 |
},
|
| 60 |
{
|
| 61 |
+
"q": "4. At the end of the week, your holding cost is $0.50 per unit, and your backlog cost is $1.00 per unit. If your final inventory is 0 units and you have a remaining Backlog of 15 units, what is your Total Weekly Cost?",
|
| 62 |
"options": ["$7.50", "$15.00", "$15.50", "$0.00"],
|
| 63 |
"correct_index": 1, # 15.00
|
| 64 |
},
|
|
|
|
| 478 |
local_path = LOCAL_LOG_DIR / LEADERBOARD_FILE
|
| 479 |
with open(local_path, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2, ensure_ascii=False)
|
| 480 |
hf_api.upload_file(path_or_fileobj=str(local_path), path_in_repo=LEADERBOARD_FILE, repo_id=HF_REPO_ID, repo_type="dataset", token=HF_TOKEN, commit_message="Update leaderboard")
|
| 481 |
+
# st.sidebar.success("Leaderboard updated!") # Removed notification to keep it hidden
|
| 482 |
st.cache_data.clear()
|
| 483 |
except Exception as e:
|
| 484 |
st.sidebar.error(f"Failed to upload leaderboard: {e}")
|
|
|
|
| 532 |
def show_leaderboard_ui():
|
| 533 |
st.markdown("---")
|
| 534 |
st.header("📊 The Bullwhip Leaderboard")
|
| 535 |
+
st.caption("This is the dynamic leaderboard. It updates automatically when students finish games (approx 60s cache).")
|
| 536 |
leaderboard_data = load_leaderboard_data()
|
| 537 |
if not leaderboard_data:
|
| 538 |
st.info("No leaderboard data yet. Be the first to finish a game!")
|
|
|
|
| 588 |
st.error(f"Error processing or saving log CSV: {e_save}")
|
| 589 |
return
|
| 590 |
if logs_df is None: return
|
| 591 |
+
# st.subheader("Updating Leaderboard...") # HIDDEN FROM STUDENTS
|
| 592 |
try:
|
| 593 |
human_role = state['human_role']
|
| 594 |
|
|
|
|
| 781 |
except Exception as e:
|
| 782 |
st.error(f"Error generating final report or saving data: {e}")
|
| 783 |
|
| 784 |
+
# show_leaderboard_ui() # <--- HIDDEN FROM STUDENTS
|
| 785 |
+
|
| 786 |
if st.button("✨ Start a New Game"):
|
| 787 |
# 在重置游戏时清除所有与实验相关的时间戳
|
| 788 |
if 'consent_timestamp' in st.session_state: del st.session_state['consent_timestamp']
|
|
|
|
| 1003 |
st.rerun()
|
| 1004 |
# ===========================================================
|
| 1005 |
|
| 1006 |
+
# show_leaderboard_ui() # <--- HIDDEN FROM STUDENTS
|
| 1007 |
+
|
| 1008 |
+
# ==============================================================================
|
| 1009 |
+
# --- NEW: Admin / Instructor Zone (Sidebar) ---
|
| 1010 |
+
# ==============================================================================
|
| 1011 |
+
# This section is always available but hidden in a collapsed sidebar expander.
|
| 1012 |
+
# It requires a password to open.
|
| 1013 |
+
st.sidebar.markdown("---")
|
| 1014 |
+
with st.sidebar.expander("🔐 Instructor Zone"):
|
| 1015 |
+
admin_password_input = st.text_input("Admin Password:", type="password", key="admin_pass_input")
|
| 1016 |
+
|
| 1017 |
+
if admin_password_input == ADMIN_PASSWORD:
|
| 1018 |
+
st.success("Access Granted")
|
| 1019 |
+
show_admin_leaderboard = st.checkbox("Show Global Leaderboard (Dynamic)", value=False)
|
| 1020 |
+
|
| 1021 |
+
if show_admin_leaderboard:
|
| 1022 |
+
# When checked, the leaderboard will render at the bottom of whatever page is active
|
| 1023 |
+
st.markdown("---")
|
| 1024 |
+
st.markdown("### 👨🏫 Instructor View: Global Leaderboard")
|
| 1025 |
+
show_leaderboard_ui()
|
| 1026 |
+
elif admin_password_input:
|
| 1027 |
+
st.error("Incorrect Password")
|