Lilli98 commited on
Commit
1f0dbe0
·
verified ·
1 Parent(s): b76c27b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -3
app.py CHANGED
@@ -39,6 +39,30 @@ FACTORY_SHIPPING_DELAY = 1
39
  HOLDING_COST = 0.5
40
  BACKLOG_COST = 1.0
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  # --- Model & Log Configuration ---
43
  OPENAI_MODEL = "gpt-4o-mini"
44
  LOCAL_LOG_DIR = Path("logs")
@@ -619,6 +643,9 @@ if 'consent_given' not in st.session_state:
619
  # --- NEW: Storage for Consent Timestamp ---
620
  if 'consent_timestamp' not in st.session_state:
621
  st.session_state['consent_timestamp'] = None
 
 
 
622
 
623
  # --- Initialization Check ---
624
  if st.session_state.get('initialization_error'):
@@ -628,13 +655,10 @@ if st.session_state.get('initialization_error'):
628
  elif not st.session_state['consent_given']:
629
  st.header("📝 Participant Consent Form")
630
  st.markdown("""
631
-
632
  **Lead Researcher:** Xinyu Li
633
  **Supervisor:** Professor Li Ding & Dr Yanlu Zhao
634
  **Contact Email:** xinyu.li3@durham.ac.uk
635
-
636
  Please read the following statements carefully. If you have any questions, please ask the researcher or contact them at the email address provided above.
637
-
638
  By agreeing to participate, you are confirming that you understand all of the following:
639
 
640
  - You have listened to the in-class explanation of this study and have had the opportunity to ask questions.
@@ -671,6 +695,42 @@ elif not st.session_state['consent_given']:
671
  else:
672
  st.warning("Please select an option to continue.")
673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
674
 
675
  # --- Main Application Flow ---
676
  else:
@@ -724,6 +784,7 @@ else:
724
  # 在重置游戏时清除所有与实验相关的时间戳
725
  if 'consent_timestamp' in st.session_state: del st.session_state['consent_timestamp']
726
  if 'consent_given' in st.session_state: del st.session_state['consent_given']
 
727
  del st.session_state.game_state
728
  st.rerun()
729
 
 
39
  HOLDING_COST = 0.5
40
  BACKLOG_COST = 1.0
41
 
42
+ # --- NEW: Comprehension Questions Data ---
43
+ COMPREHENSION_QUESTIONS = [
44
+ {
45
+ "q": "1. Which role are you playing in this supply chain experiment?",
46
+ "options": ["Retailer", "Wholesaler", "Distributor", "Factory"],
47
+ "correct_index": 2, # Distributor
48
+ },
49
+ {
50
+ "q": "2. What is your primary objective as a manager in this game?",
51
+ "options": ["Maximize on-hand inventory.", "Minimize total accumulated costs (holding + backlog).", "Maximize weekly order quantity.", "Minimize customer demand."],
52
+ "correct_index": 1, # Minimize total costs
53
+ },
54
+ {
55
+ "q": "3. Your final order quantity for the Factory will typically arrive at your location after how many weeks?",
56
+ "options": ["1 week", "2 weeks", "3 weeks", "4 weeks"],
57
+ "correct_index": 2, # 3 weeks
58
+ },
59
+ {
60
+ "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?",
61
+ "options": ["$7.50", "$15.00", "$15.50", "$0.00"],
62
+ "correct_index": 1, # 15.00
63
+ },
64
+ ]
65
+
66
  # --- Model & Log Configuration ---
67
  OPENAI_MODEL = "gpt-4o-mini"
68
  LOCAL_LOG_DIR = Path("logs")
 
643
  # --- NEW: Storage for Consent Timestamp ---
644
  if 'consent_timestamp' not in st.session_state:
645
  st.session_state['consent_timestamp'] = None
646
+ # --- NEW: Check for Comprehension ---
647
+ if 'comprehension_passed' not in st.session_state:
648
+ st.session_state['comprehension_passed'] = False
649
 
650
  # --- Initialization Check ---
651
  if st.session_state.get('initialization_error'):
 
655
  elif not st.session_state['consent_given']:
656
  st.header("📝 Participant Consent Form")
657
  st.markdown("""
 
658
  **Lead Researcher:** Xinyu Li
659
  **Supervisor:** Professor Li Ding & Dr Yanlu Zhao
660
  **Contact Email:** xinyu.li3@durham.ac.uk
 
661
  Please read the following statements carefully. If you have any questions, please ask the researcher or contact them at the email address provided above.
 
662
  By agreeing to participate, you are confirming that you understand all of the following:
663
 
664
  - You have listened to the in-class explanation of this study and have had the opportunity to ask questions.
 
695
  else:
696
  st.warning("Please select an option to continue.")
697
 
698
+ # --- NEW: Comprehension Questions Section ---
699
+ elif not st.session_state['comprehension_passed']:
700
+ st.header("🧠 Comprehension Check")
701
+ st.markdown("Before starting the experiment, please answer the following questions to ensure you understand the game rules and your role.")
702
+
703
+ with st.form("comprehension_quiz"):
704
+ user_answers = {}
705
+ for i, q_data in enumerate(COMPREHENSION_QUESTIONS):
706
+ st.subheader(q_data['q'])
707
+ # Create a radio button for each question
708
+ user_answers[i] = st.radio(
709
+ "Select an option:",
710
+ q_data['options'],
711
+ key=f"comp_q_{i}",
712
+ index=None, # Require explicit selection
713
+ label_visibility="collapsed"
714
+ )
715
+ st.markdown("---")
716
+
717
+ submit_quiz = st.form_submit_button("Submit Answers")
718
+
719
+ if submit_quiz:
720
+ all_correct = True
721
+ for i, q_data in enumerate(COMPREHENSION_QUESTIONS):
722
+ selected = user_answers.get(i)
723
+ correct_option = q_data['options'][q_data['correct_index']]
724
+
725
+ if selected != correct_option:
726
+ all_correct = False
727
+ st.error(f"❌ Question {i+1} is incorrect.")
728
+
729
+ if all_correct:
730
+ st.success("✅ All answers are correct! Proceeding to game setup...")
731
+ st.session_state['comprehension_passed'] = True
732
+ time.sleep(1.5) # Brief pause for user to see success
733
+ st.rerun()
734
 
735
  # --- Main Application Flow ---
736
  else:
 
784
  # 在重置游戏时清除所有与实验相关的时间戳
785
  if 'consent_timestamp' in st.session_state: del st.session_state['consent_timestamp']
786
  if 'consent_given' in st.session_state: del st.session_state['consent_given']
787
+ if 'comprehension_passed' in st.session_state: del st.session_state['comprehension_passed']
788
  del st.session_state.game_state
789
  st.rerun()
790