GSMEthesis commited on
Commit
bf1f364
·
verified ·
1 Parent(s): 889692c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -106
app.py CHANGED
@@ -461,49 +461,37 @@ 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
  .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
  /* استایل تضمینی برای رادیو باتن‌ها - نسخه نهایی */
@@ -782,46 +770,39 @@ def show_explanation(exp_type):
782
  st.markdown(f"<p class='explanation-item'>• {item}</p>", unsafe_allow_html=True)
783
 
784
  def create_likert_question(question, key, scale_type="5point"):
785
- """سوال لیکرت با دکمه‌ها"""
786
- if scale_type == "5point":
787
- options = {
788
- 1: "کاملاً مخالفم",
789
- 2: "مخالفم",
790
- 3: "نظری ندارم",
791
- 4: "موافقم",
792
- 5: "کاملاً موافقم"
793
- }
794
- else: # 7-point scale
795
- options = {
796
- 1: "کاملاً مخالفم",
797
- 2: "مخالفم",
798
- 3: "تا حدی مخالفم",
799
- 4: "نظری ندارم",
800
- 5: "تا حدی موافقم",
801
- 6: "موافقم",
802
- 7: "کاملاً موافقم"
803
- }
804
 
805
- st.markdown(f"<p style='margin-bottom: 10px;'>{question}</p>", unsafe_allow_html=True)
 
 
806
 
807
- cols = st.columns(len(options))
808
- selected = st.session_state.get(key, None)
809
 
810
- # نمایش گزینه‌ها از کاملاً موافقم (راست) تا کاملاً مخالفم (چپ)
811
- for value, label in reversed(options.items()):
812
- with cols[len(options) - value]:
813
- if st.button(
814
- label,
815
- key=f"{key}_{value}",
816
- on_click=lambda v=value: st.session_state.update({key: v}),
817
- type="primary" if selected == value else "secondary"
818
- ):
819
- pass
820
 
821
- if selected:
822
- st.markdown(f"<p style='color: #6a0dad;'>پاسخ شما: {options[selected]}</p>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
823
 
824
- return selected
825
 
826
  # ========== توابع مدیریت داده‌ها ==========
827
  def get_credentials():
@@ -1118,61 +1099,40 @@ def attention_check1():
1118
 
1119
  def random_likert_questions():
1120
  """نمایش تصادفی سوالات لیکرت با اسلایدر جدید"""
1121
- if not st.session_state.all_questions:
1122
- # تعریف تمام سوالات فقط اگر خالی باشند
1123
- st.session_state.all_questions = [
1124
  {"key": "informational_1", "question": "پلتفرم به صورت صادقانه دلایل تعیین قیمت را توضیح داد.", "scale": "5point"},
1125
  {"key": "informational_2", "question": "پلتفرم به طور کامل عوامل مؤثر بر تعیین قیمت را شرح داد.", "scale": "5point"},
1126
- {"key": "informational_3", "question": "دلایل ارائه‌شده برای تعیین قیمت منطقی و قابل قبول بود.", "scale": "5point"},
1127
- {"key": "informational_4", "question": "توضیحات درباره تعیین قیمت بلافاصله و در زمان مناسب نمایش داده شد.", "scale": "5point"},
1128
- {"key": "informational_5", "question": "توضیحات پلتفرم درباره تعیین قیمت، متناسب با شرایط سفر من بود.", "scale": "5point"},
1129
- {"key": "distributive_1", "question": "قیمتی که به شما ارائه شد، منصفانه است.", "scale": "7point"},
1130
- {"key": "distributive_2", "question": "قیمتی که به شما ارائه شد، معقول است.", "scale": "7point"},
1131
- {"key": "distributive_3", "question": "قیمتی که به شما ارائه شد، قابل قبول است.", "scale": "7point"},
1132
- {"key": "procedural_1", "question": "فرآیند و رویه قیمت‌گذاری پلتفرم قابل قبول است.", "scale": "7point"},
1133
- {"key": "procedural_2", "question": "فرآیند و رویه قیمت‌گذاری پلتفرم منصفانه است.", "scale": "7point"},
1134
- {"key": "procedural_3", "question": "فرآیند و رویه قیمت‌گذاری پلتفرم معقول است.", "scale": "7point"},
1135
- {"key": "attention_check2", "question": "حاصل ۵ × ۳ به اضافه ۲ چقدر می‌شود؟", "scale": "attention"}
1136
  ]
1137
- random.shuffle(st.session_state.all_questions)
1138
  st.session_state.current_question_index = 0
1139
-
1140
  # نمایش سوال جاری
1141
- if st.session_state.current_question_index < len(st.session_state.all_questions):
1142
- q = st.session_state.all_questions[st.session_state.current_question_index]
1143
-
1144
- if q["scale"] == "attention":
1145
- st.markdown("### سوال")
1146
- answer = st.radio(
1147
- q["question"],
1148
- ["1", "13", "15", "17", "دیگر"],
1149
- index=None,
1150
- key=f"att2_{st.session_state.current_question_index}"
1151
- )
 
 
 
 
 
 
1152
 
1153
- if st.button("ادامه", key=f"att2_btn_{st.session_state.current_question_index}"):
1154
- if answer:
1155
- st.session_state.attention_check2 = answer
1156
- st.session_state.current_question_index += 1
1157
- st.rerun()
1158
- else:
1159
- st.warning("لطفاً یک گزینه را انتخاب کنید")
1160
  else:
1161
- st.markdown(f"<h3>سوال {st.session_state.current_question_index+1} از {len(st.session_state.all_questions)}</h3>",
1162
- unsafe_allow_html=True)
1163
-
1164
- answer = create_likert_question(q["question"], q["key"], q["scale"])
1165
-
1166
- if st.button("ادامه", key=f"continue_{st.session_state.current_question_index}"):
1167
- if answer:
1168
- st.session_state[q["key"]] = answer
1169
- st.session_state.current_question_index += 1
1170
- st.rerun()
1171
- else:
1172
- st.warning("لطفاً پاسخ خود را با حرکت دادن اسلایدر مشخص کنید")
1173
- else:
1174
- st.session_state.current_page = "explanation_questions"
1175
- st.rerun()
1176
 
1177
  def explanation_questions():
1178
  """سوالات درباره توضیحات قیمت"""
 
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: 10px !important;
468
  }
469
 
470
+ /* نقاط اسلایدر */
471
  .stSlider > div > div > div > div > div > div {
472
+ width: 18px !important;
473
+ height: 18px !important;
474
  border-radius: 50% !important;
475
  background-color: #6A0DAD !important;
476
+ border: 3px solid white !important;
477
+ box-shadow: 0 0 5px rgba(0,0,0,0.3) !important;
478
  }
479
 
480
+ /* متن دو طرف */
481
  .slider-labels {
482
  display: flex;
483
  justify-content: space-between;
484
+ margin: 5px 0 15px 0;
485
  font-family: 'B Nazanin' !important;
486
  font-size: 14px !important;
487
  color: #6A0DAD;
488
  }
489
 
490
+ /* دکمه ادامه */
491
+ .stButton > button {
492
  background-color: #6A0DAD !important;
493
  color: white !important;
 
 
 
 
494
  margin-top: 20px !important;
 
 
 
 
 
 
 
 
495
  }
496
 
497
  /* استایل تضمینی برای رادیو باتن‌ها - نسخه نهایی */
 
770
  st.markdown(f"<p class='explanation-item'>• {item}</p>", unsafe_allow_html=True)
771
 
772
  def create_likert_question(question, key, scale_type="5point"):
773
+ """نمایش سوال لیکرت با اسلایدر نقطه‌ای 7 قسمتی"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
 
775
+ # تعریف لیبل‌های دو طرف
776
+ left_label = "کاملاً مخالفم"
777
+ right_label = "کاملاً موافقم"
778
 
779
+ st.markdown(f"<p style='font-size:16px; margin-bottom:5px;'>{question}</p>", unsafe_allow_html=True)
 
780
 
781
+ # ایجاد اسلایدر با 7 نقطه
782
+ value = st.slider(
783
+ "",
784
+ min_value=1,
785
+ max_value=7,
786
+ value=4,
787
+ step=1,
788
+ key=f"slider_{key}"
789
+ )
 
790
 
791
+ # نمایش متن دو طرف اسلایدر
792
+ st.markdown(
793
+ f"""
794
+ <div class="slider-labels">
795
+ <span>{left_label}</span>
796
+ <span>{right_label}</span>
797
+ </div>
798
+ <p style='text-align:center; color:#6a0dad; font-weight:bold;'>
799
+ پاسخ شما: {value} ({'کاملاً مخالفم' if value==1 else 'کاملاً موافقم' if value==7 else 'خنثی' if value==4 else 'موافقم' if value>4 else 'مخالفم'})
800
+ </p>
801
+ """,
802
+ unsafe_allow_html=True
803
+ )
804
 
805
+ return value
806
 
807
  # ========== توابع مدیریت داده‌ها ==========
808
  def get_credentials():
 
1099
 
1100
  def random_likert_questions():
1101
  """نمایش تصادفی سوالات لیکرت با اسلایدر جدید"""
1102
+ if 'all_questions' not in st.session_state:
1103
+ # تعریف تمام سوالات
1104
+ questions = [
1105
  {"key": "informational_1", "question": "پلتفرم به صورت صادقانه دلایل تعیین قیمت را توضیح داد.", "scale": "5point"},
1106
  {"key": "informational_2", "question": "پلتفرم به طور کامل عوامل مؤثر بر تعیین قیمت را شرح داد.", "scale": "5point"},
1107
+ # بقیه سوالات...
 
 
 
 
 
 
 
 
 
1108
  ]
1109
+ st.session_state.all_questions = questions
1110
  st.session_state.current_question_index = 0
1111
+
1112
  # نمایش سوال جاری
1113
+ q = st.session_state.all_questions[st.session_state.current_question_index]
1114
+
1115
+ if q["scale"] == "attention":
1116
+ # سوال توجه
1117
+ answer = st.radio(
1118
+ q["question"],
1119
+ ["1", "13", "15", "17", "دیگر"],
1120
+ index=None
1121
+ )
1122
+ else:
1123
+ # سوالات لیکرت
1124
+ answer = create_likert_question(q["question"], q["key"], q["scale"])
1125
+
1126
+ if st.button("ادامه", key=f"btn_{st.session_state.current_question_index}"):
1127
+ if answer:
1128
+ st.session_state[q["key"]] = answer
1129
+ st.session_state.current_question_index += 1
1130
 
1131
+ if st.session_state.current_question_index >= len(st.session_state.all_questions):
1132
+ st.session_state.current_page = "explanation_questions"
1133
+ st.rerun()
 
 
 
 
1134
  else:
1135
+ st.warning("لطفاً به سوال پاسخ دهید")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1136
 
1137
  def explanation_questions():
1138
  """سوالات درباره توضیحات قیمت"""