GSMEthesis commited on
Commit
286d1f4
·
verified ·
1 Parent(s): 51c9cf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -739,7 +739,7 @@ h3 {
739
 
740
  # ========== توابع اصلی ==========
741
  def custom_likert_slider(question_data):
742
- """نمایش سوال لیکرت با اسلایدر سفارشی و اطمینان از ذخیره مقدار"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  points = question_data["scale"]
@@ -777,11 +777,11 @@ def custom_likert_slider(question_data):
777
  window.parent.postMessage({{
778
  type: 'streamlit:setComponentValue',
779
  value: value,
780
- key: 'custom_' + key
781
  }}, '*');
782
 
783
- // به‌روزرسانی مقدار در input برای اطمینان
784
- slider.value = value;
785
  }}
786
 
787
  // تنظیم مقدار اولیه
@@ -794,7 +794,10 @@ def custom_likert_slider(question_data):
794
  components.html(html, height=150)
795
 
796
  # دریافت مقدار از Streamlit
797
- component_value = st.session_state.get(f"custom_{key}", current_value)
 
 
 
798
 
799
  # ذخیره مقدار در session_state
800
  st.session_state[key] = component_value
@@ -1221,7 +1224,7 @@ def random_likert_questions():
1221
  "key": "distributive_1",
1222
  "question": "قیمتی که به شما ارائه شد، چگونه بود؟",
1223
  "scale": 7,
1224
- "labels": ["کاملاً نامنصفانه", "کاملاً منصفانه"] # لیبل‌های سفارشی برای این سوال
1225
  },
1226
  {
1227
  "key": "distributive_2",
@@ -1241,7 +1244,7 @@ def random_likert_questions():
1241
  "title": "سوال توجه",
1242
  "key": "attention_check",
1243
  "questions": [
1244
- {"key": "attention_check2", "question": "تا چه مقدار با دقت به سوالات پاسخ می‌دهید؟", "scale": 7,"labels": ["خیلی کم", "خیلی زیاد"]}
1245
  ]
1246
  },
1247
  {
@@ -1266,7 +1269,6 @@ def random_likert_questions():
1266
  }
1267
  ]
1268
 
1269
-
1270
  # مقداردهی اولیه
1271
  if 'current_likert_group' not in st.session_state:
1272
  st.session_state.current_likert_group = 0
@@ -1302,12 +1304,17 @@ def random_likert_questions():
1302
  for question in current_group['questions']:
1303
  answer = custom_likert_slider(question)
1304
  st.session_state.answers[question["key"]] = answer
1305
-
 
 
 
1306
 
1307
  # دکمه ادامه/اتمام
1308
  button_label = "ادامه به گروه بعدی" if st.session_state.current_likert_group < len(question_groups)-1 else "اتمام پرسشنامه"
1309
 
1310
  if st.button(button_label):
 
 
1311
  # رفتن به گروه بعدی یا صفحه پایانی
1312
  if st.session_state.current_likert_group < len(question_groups) - 1:
1313
  st.session_state.current_likert_group += 1
 
739
 
740
  # ========== توابع اصلی ==========
741
  def custom_likert_slider(question_data):
742
+ """نمایش سوال لیکرت با اسلایدر سفارشی و دیباگ کامل"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  points = question_data["scale"]
 
777
  window.parent.postMessage({{
778
  type: 'streamlit:setComponentValue',
779
  value: value,
780
+ key: key
781
  }}, '*');
782
 
783
+ // دیباگ: چاپ مقدار در کنسول مرورگر
784
+ console.log('Slider key: ' + key + ', Value: ' + value);
785
  }}
786
 
787
  // تنظیم مقدار اولیه
 
794
  components.html(html, height=150)
795
 
796
  # دریافت مقدار از Streamlit
797
+ component_value = st.session_state.get(key, default_value)
798
+
799
+ # دیباگ: نمایش مقدار دریافت‌شده
800
+ st.write(f"Debug: مقدار دریافت‌شده برای {key}: {component_value}")
801
 
802
  # ذخیره مقدار در session_state
803
  st.session_state[key] = component_value
 
1224
  "key": "distributive_1",
1225
  "question": "قیمتی که به شما ارائه شد، چگونه بود؟",
1226
  "scale": 7,
1227
+ "labels": ["کاملاً نامنصفانه", "کاملاً منصفانه"]
1228
  },
1229
  {
1230
  "key": "distributive_2",
 
1244
  "title": "سوال توجه",
1245
  "key": "attention_check",
1246
  "questions": [
1247
+ {"key": "attention_check2", "question": "تا چه مقدار با دقت به سوالات پاسخ می‌دهید؟", "scale": 7, "labels": ["خیلی کم", "خیلی زیاد"]}
1248
  ]
1249
  },
1250
  {
 
1269
  }
1270
  ]
1271
 
 
1272
  # مقداردهی اولیه
1273
  if 'current_likert_group' not in st.session_state:
1274
  st.session_state.current_likert_group = 0
 
1304
  for question in current_group['questions']:
1305
  answer = custom_likert_slider(question)
1306
  st.session_state.answers[question["key"]] = answer
1307
+ st.write(f"Debug: پاسخ ذخیره‌شده برای {question['key']}: {st.session_state.answers[question['key']]}")
1308
+
1309
+ # دیباگ: نمایش کل session_state
1310
+ st.write("Debug: کل session_state:", st.session_state)
1311
 
1312
  # دکمه ادامه/اتمام
1313
  button_label = "ادامه به گروه بعدی" if st.session_state.current_likert_group < len(question_groups)-1 else "اتمام پرسشنامه"
1314
 
1315
  if st.button(button_label):
1316
+ # بررسی مقادیر ذخیره‌شده قبل از رفتن به گروه بعدی
1317
+ st.write("Debug: مقادیر ذخیره‌شده قبل از ادامه:", st.session_state.answers)
1318
  # رفتن به گروه بعدی یا صفحه پایانی
1319
  if st.session_state.current_likert_group < len(question_groups) - 1:
1320
  st.session_state.current_likert_group += 1