GSMEthesis commited on
Commit
c4af725
·
verified ·
1 Parent(s): 088182c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -27
app.py CHANGED
@@ -461,6 +461,51 @@ div[data-testid="stVerticalBlock"] > div[data-testid="stHorizontalBlock"] > div
461
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important; /* سایه بیشتر */
462
  }
463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  /* استایل تضمینی برای رادیو باتن‌ها - نسخه نهایی */
465
  .stRadio > div > div > div > div > div > label,
466
  .stRadio > div > div > div > div > label,
@@ -861,6 +906,43 @@ def save_to_sheet(data):
861
  st.error(f"خطا در ذخیره‌سازی: {str(e)}")
862
  return False
863
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
864
  # ========== بخش‌های فرم ==========
865
 
866
  def welcome_page():
@@ -1038,7 +1120,7 @@ def attention_check1():
1038
 
1039
 
1040
  def random_likert_questions():
1041
- """نمایش تصادفی سوالات لیکرت"""
1042
  if 'all_questions' not in st.session_state:
1043
  # تعریف تمام سوالات با نوع مقیاس و لیبل مربوطه
1044
  st.session_state.all_questions = [
@@ -1073,8 +1155,8 @@ def random_likert_questions():
1073
  st.markdown("""
1074
  <div style="background-color: #f8f9fa; padding: 15px; border-radius: 10px; margin-bottom: 20px;">
1075
  <p style="font-weight: bold;">راهنمای پاسخگویی:</p>
1076
- <p>لطفا موافقت خود را با سوالات زیر طبق گزینه‌ها اعلام کنید.</p>
1077
- <p>با کلیک روی هر گزینه پاسخ شما انتخاب خواهد شد. لطفا با صبوری و بررسی سوالات را پاسخ دهید و تا بارگزاری سوال بعدی کمی صبر کنید.</p>
1078
  </div>
1079
  """, unsafe_allow_html=True)
1080
 
@@ -1083,17 +1165,7 @@ def random_likert_questions():
1083
 
1084
  # نمایش سوال attention_check2 به صورت خاص
1085
  if q["scale"] == "attention":
1086
-
1087
- st.markdown("""
1088
- <style>
1089
- /* تضمین رنگ متن برای تمام سطوح */
1090
- .st-ec, .st-ed, .st-ee, .st-ef, .st-eg, .st-eh, .st-ei, .st-ej {
1091
- color: black !important;
1092
- }
1093
- </style>
1094
- """, unsafe_allow_html=True)
1095
- st.markdown("### سوال")
1096
-
1097
  answer = st.radio(
1098
  "حاصل ۵ × ۳ به اضافه ۲ چقدر می‌شود؟",
1099
  ["1", "13", "15", "17", "دیگر"],
@@ -1110,13 +1182,15 @@ def random_likert_questions():
1110
  else:
1111
  st.warning("لطفاً یک گزینه را انتخاب کنید")
1112
  else:
1113
- # نمایش سوالات لیکرت به صورت معمول
1114
  answer = create_likert_question(q["question"], q["key"], q["scale"])
1115
 
1116
  if answer:
1117
- st.session_state.current_question_index += 1
1118
- time.sleep(0.5)
1119
- st.rerun()
 
 
1120
  else:
1121
  st.session_state.current_page = "explanation_questions"
1122
  st.rerun()
@@ -1329,12 +1403,6 @@ def main():
1329
  user_agent = st.query_params.get("user_agent", [""])[0]
1330
  st.session_state.is_desktop = "mobile" not in user_agent.lower()
1331
 
1332
-
1333
- # اینجا می‌توانید از is_desktop برای تعیین اینکه نمایشگر موبایل اعمال شود، استفاده کنید
1334
- if st.session_state.is_desktop:
1335
- # اطمینان از نمایش همان حالت موبایل برای همه دستگاه‌ها
1336
- st.session_state.is_desktop = False
1337
-
1338
  if 'current_page' not in st.session_state:
1339
  st.session_state.current_page = "welcome"
1340
  st.session_state.scenario_type = random.choice(["control", "input", "counterfactual"])
@@ -1342,8 +1410,14 @@ def main():
1342
  st.session_state.user_contact = None
1343
  st.session_state.demographic_data = None
1344
  st.session_state.price_accepted = 0
 
 
 
 
 
 
 
1345
 
1346
-
1347
  pages = {
1348
  "welcome": welcome_page,
1349
  "scenario_explanation": scenario_explanation,
@@ -1351,8 +1425,8 @@ def main():
1351
  "attention_check1": attention_check1,
1352
  "random_likert_questions": random_likert_questions,
1353
  "explanation_questions": explanation_questions,
1354
- "demographic": demographic_form, # دموگرافیک قبل از کانتکت
1355
- "contact": user_contact, # کانتکت در انتها
1356
  "thank_you": thank_you_page
1357
  }
1358
 
 
461
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important; /* سایه بیشتر */
462
  }
463
 
464
+ /* استایل جدید برای اسلایدر لیکرت */
465
+ .stSlider > div > div > div > div {
466
+ background: linear-gradient(90deg, #E6E6FA, #6A0DAD) !important;
467
+ height: 8px !important;
468
+ }
469
+
470
+ /* نقطه‌های اسلایدر */
471
+ .stSlider > div > div > div > div > div > div {
472
+ width: 16px !important;
473
+ height: 16px !important;
474
+ border-radius: 50% !important;
475
+ background-color: #6A0DAD !important;
476
+ border: 2px solid white !important;
477
+ box-shadow: 0 0 4px rgba(0,0,0,0.3) !important;
478
+ }
479
+
480
+ /* متن دو طرف اسلایدر */
481
+ .slider-labels {
482
+ display: flex;
483
+ justify-content: space-between;
484
+ margin-top: 10px;
485
+ font-family: 'B Nazanin' !important;
486
+ font-size: 14px !important;
487
+ color: #6A0DAD;
488
+ }
489
+
490
+ /* دکمه ادامه برای سوالات لیکرت */
491
+ .likert-continue-btn {
492
+ background-color: #6A0DAD !important;
493
+ color: white !important;
494
+ border: none !important;
495
+ border-radius: 8px !important;
496
+ padding: 10px 20px !important;
497
+ font-weight: bold !important;
498
+ margin-top: 20px !important;
499
+ transition: all 0.3s ease !important;
500
+ float: left;
501
+ }
502
+
503
+ .likert-continue-btn:hover {
504
+ background-color: #5A0A96 !important;
505
+ transform: translateY(-1px) !important;
506
+ box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important;
507
+ }
508
+
509
  /* استایل تضمینی برای رادیو باتن‌ها - نسخه نهایی */
510
  .stRadio > div > div > div > div > div > label,
511
  .stRadio > div > div > div > div > label,
 
906
  st.error(f"خطا در ذخیره‌سازی: {str(e)}")
907
  return False
908
 
909
+ def create_likert_question(question, key, scale_type="5point"):
910
+ """نمایش سوال لیکرت با اسلایدر نقطه‌ای 7 قسمتی"""
911
+
912
+ # تعریف لیبل‌های دو طرف بر اساس نوع مقیاس
913
+ if scale_type == "5point":
914
+ left_label = "کاملاً مخالفم"
915
+ right_label = "کاملاً موافقم"
916
+ else: # 7-point scale
917
+ left_label = "کاملاً مخالفم"
918
+ right_label = "کاملاً موافقم"
919
+
920
+ st.markdown(f"<p style='font-size:16px; margin-bottom:10px;'>{question}</p>", unsafe_allow_html=True)
921
+
922
+ # ایجاد اسلایدر با 7 نقطه
923
+ value = st.slider(
924
+ label="",
925
+ min_value=1,
926
+ max_value=7,
927
+ value=4, # مقدار پیش‌فرض وسط
928
+ step=1,
929
+ key=key,
930
+ label_visibility="collapsed"
931
+ )
932
+
933
+ # نمایش متن دو طرف اسلایدر
934
+ st.markdown(
935
+ f"""
936
+ <div class="slider-labels">
937
+ <span>{left_label}</span>
938
+ <span>{right_label}</span>
939
+ </div>
940
+ """,
941
+ unsafe_allow_html=True
942
+ )
943
+
944
+ return value
945
+
946
  # ========== بخش‌های فرم ==========
947
 
948
  def welcome_page():
 
1120
 
1121
 
1122
  def random_likert_questions():
1123
+ """نمایش تصادفی سوالات لیکرت با اسلایدر جدید"""
1124
  if 'all_questions' not in st.session_state:
1125
  # تعریف تمام سوالات با نوع مقیاس و لیبل مربوطه
1126
  st.session_state.all_questions = [
 
1155
  st.markdown("""
1156
  <div style="background-color: #f8f9fa; padding: 15px; border-radius: 10px; margin-bottom: 20px;">
1157
  <p style="font-weight: bold;">راهنمای پاسخگویی:</p>
1158
+ <p>لطفا موافقت خود را با سوالات زیر با حرکت دادن اسلایدر نقطه‌ای اعلام کنید.</p>
1159
+ <p>سمت چپ: کمترین میزان موافقت | سمت راست: بیشترین میزان موافقت</p>
1160
  </div>
1161
  """, unsafe_allow_html=True)
1162
 
 
1165
 
1166
  # نمایش سوال attention_check2 به صورت خاص
1167
  if q["scale"] == "attention":
1168
+ st.markdown("### سوال")
 
 
 
 
 
 
 
 
 
 
1169
  answer = st.radio(
1170
  "حاصل ۵ × ۳ به اضافه ۲ چقدر می‌شود؟",
1171
  ["1", "13", "15", "17", "دیگر"],
 
1182
  else:
1183
  st.warning("لطفاً یک گزینه را انتخاب کنید")
1184
  else:
1185
+ # نمایش سوالات لیکرت با اسلایدر جدید
1186
  answer = create_likert_question(q["question"], q["key"], q["scale"])
1187
 
1188
  if answer:
1189
+ st.session_state[q["key"]] = answer
1190
+ if st.button("ادامه", key=f"continue_{q['key']}"):
1191
+ st.session_state.current_question_index += 1
1192
+ time.sleep(0.5)
1193
+ st.rerun()
1194
  else:
1195
  st.session_state.current_page = "explanation_questions"
1196
  st.rerun()
 
1403
  user_agent = st.query_params.get("user_agent", [""])[0]
1404
  st.session_state.is_desktop = "mobile" not in user_agent.lower()
1405
 
 
 
 
 
 
 
1406
  if 'current_page' not in st.session_state:
1407
  st.session_state.current_page = "welcome"
1408
  st.session_state.scenario_type = random.choice(["control", "input", "counterfactual"])
 
1410
  st.session_state.user_contact = None
1411
  st.session_state.demographic_data = None
1412
  st.session_state.price_accepted = 0
1413
+ st.session_state.attention_check1 = None
1414
+ st.session_state.attention_check2 = None
1415
+
1416
+ # اضافه کردن متغیرهای جدید برای سوالات لیکرت
1417
+ if 'all_questions' not in st.session_state:
1418
+ st.session_state.all_questions = []
1419
+ st.session_state.current_question_index = 0
1420
 
 
1421
  pages = {
1422
  "welcome": welcome_page,
1423
  "scenario_explanation": scenario_explanation,
 
1425
  "attention_check1": attention_check1,
1426
  "random_likert_questions": random_likert_questions,
1427
  "explanation_questions": explanation_questions,
1428
+ "demographic": demographic_form,
1429
+ "contact": user_contact,
1430
  "thank_you": thank_you_page
1431
  }
1432