Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,73 +739,166 @@ h3 {
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
-
"""لیکرت اسکیل ب
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
| 746 |
labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
|
| 747 |
|
|
|
|
| 748 |
if key not in st.session_state:
|
| 749 |
st.session_state[key] = None
|
| 750 |
-
|
| 751 |
-
# استایلدهی
|
| 752 |
-
st.markdown(
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
}}
|
| 759 |
-
.likert-
|
| 760 |
-
|
|
|
|
|
|
|
|
|
|
| 761 |
}}
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
# نمایش سوال
|
| 767 |
-
st.markdown(f"
|
| 768 |
-
|
| 769 |
-
#
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
st.markdown(
|
| 803 |
-
f"<div style='text-align: center; color: #6a0dad; font-weight: bold; margin-top: 8px;'>"
|
| 804 |
-
f"پاسخ شما: {st.session_state[key]}"
|
| 805 |
-
f"</div>",
|
| 806 |
-
unsafe_allow_html=True
|
| 807 |
-
)
|
| 808 |
-
|
| 809 |
return st.session_state.get(key)
|
| 810 |
def create_ride_map():
|
| 811 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
|
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
+
"""لیکرت اسکیل با خط فرضی، لیبلها کنار، و نقاط دایرهای تو یه ردیف"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
| 746 |
labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
|
| 747 |
|
| 748 |
+
# مقداردهی اولیه
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
+
|
| 752 |
+
# استایلدهی سفارشی
|
| 753 |
+
st.markdown(
|
| 754 |
+
f"""
|
| 755 |
+
<style>
|
| 756 |
+
/* استایل کانتینر لیکرت */
|
| 757 |
+
.likert-container {{
|
| 758 |
+
font-family: 'B Nazanin', Arial, sans-serif !important;
|
| 759 |
+
direction: rtl !important;
|
| 760 |
+
text-align: center !important;
|
| 761 |
+
margin: 0 !important;
|
| 762 |
+
position: relative !important;
|
| 763 |
}}
|
| 764 |
+
.likert-question {{
|
| 765 |
+
font-size: 18px !important;
|
| 766 |
+
font-weight: bold !important;
|
| 767 |
+
margin-bottom: 15px !important;
|
| 768 |
+
color: #333333 !important;
|
| 769 |
}}
|
| 770 |
+
/* خط فرضی و لیبلها */
|
| 771 |
+
.likert-line-container {{
|
| 772 |
+
position: relative !important;
|
| 773 |
+
width: 80% !important;
|
| 774 |
+
margin: 0 auto !important;
|
| 775 |
+
display: flex !important;
|
| 776 |
+
align-items: center !important;
|
| 777 |
+
}}
|
| 778 |
+
.likert-label-left {{
|
| 779 |
+
position: absolute !important;
|
| 780 |
+
left: -10% !important;
|
| 781 |
+
font-size: 14px !important;
|
| 782 |
+
color: #666666 !important;
|
| 783 |
+
text-align: right !important;
|
| 784 |
+
}}
|
| 785 |
+
.likert-label-right {{
|
| 786 |
+
position: absolute !important;
|
| 787 |
+
right: -10% !important;
|
| 788 |
+
font-size: 14px !important;
|
| 789 |
+
color: #666666 !important;
|
| 790 |
+
text-align: left !important;
|
| 791 |
+
}}
|
| 792 |
+
/* استایل دکمهها */
|
| 793 |
+
.likert-buttons {{
|
| 794 |
+
display: flex !important;
|
| 795 |
+
justify-content: space-between !important;
|
| 796 |
+
gap: 10px !important;
|
| 797 |
+
flex-wrap: nowrap !important;
|
| 798 |
+
margin: 0 !important;
|
| 799 |
+
padding: 0 !important;
|
| 800 |
+
align-items: center !important;
|
| 801 |
+
}}
|
| 802 |
+
div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"] {{
|
| 803 |
+
width: 20px !important;
|
| 804 |
+
height: 20px !important;
|
| 805 |
+
border-radius: 50% !important;
|
| 806 |
+
background: white !important;
|
| 807 |
+
border: none !important;
|
| 808 |
+
color: black !important;
|
| 809 |
+
font-size: 14px !important;
|
| 810 |
+
padding: 0 !important;
|
| 811 |
+
margin: 0 !important;
|
| 812 |
+
box-shadow: none !important;
|
| 813 |
+
outline: none !important;
|
| 814 |
+
line-height: 1 !important;
|
| 815 |
+
display: flex !important;
|
| 816 |
+
align-items: center !important;
|
| 817 |
+
justify-content: center !important;
|
| 818 |
+
}}
|
| 819 |
+
div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"]:hover {{
|
| 820 |
+
background: #e0e0e0 !important;
|
| 821 |
+
}}
|
| 822 |
+
div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"]:focus,
|
| 823 |
+
div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"]:active {{
|
| 824 |
+
background: black !important;
|
| 825 |
+
color: white !important;
|
| 826 |
+
}}
|
| 827 |
+
/* استایل دکمه انتخابشده */
|
| 828 |
+
div[data-testid="stButton"] > button[key="streamlit-btn-{key}-{st.session_state[key] if st.session_state[key] else 'none'}"] {{
|
| 829 |
+
background: black !important;
|
| 830 |
+
color: white !important;
|
| 831 |
+
}}
|
| 832 |
+
/* ریسپانسیو کردن */
|
| 833 |
+
@media (max-width: 600px) {{
|
| 834 |
+
.likert-line-container {{
|
| 835 |
+
width: 90% !important;
|
| 836 |
+
}}
|
| 837 |
+
.likert-label-left {{
|
| 838 |
+
left: -5% !important;
|
| 839 |
+
font-size: 12px !important;
|
| 840 |
+
}}
|
| 841 |
+
.likert-label-right {{
|
| 842 |
+
right: -5% !important;
|
| 843 |
+
font-size: 12px !important;
|
| 844 |
+
}}
|
| 845 |
+
.likert-buttons {{
|
| 846 |
+
gap: 5px !important;
|
| 847 |
+
}}
|
| 848 |
+
div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"] {{
|
| 849 |
+
width: 18px !important;
|
| 850 |
+
height: 18px !important;
|
| 851 |
+
font-size: 12px !important;
|
| 852 |
+
}}
|
| 853 |
+
}}
|
| 854 |
+
/* حذف استایلهای پیشفرض Streamlit */
|
| 855 |
+
div[data-testid="stButton"] > button {{
|
| 856 |
+
border: none !important;
|
| 857 |
+
box-shadow: none !important;
|
| 858 |
+
outline: none !important;
|
| 859 |
+
background: transparent !important;
|
| 860 |
+
}}
|
| 861 |
+
</style>
|
| 862 |
+
""",
|
| 863 |
+
unsafe_allow_html=True
|
| 864 |
+
)
|
| 865 |
+
|
| 866 |
# نمایش سوال
|
| 867 |
+
st.markdown(f'<div class="likert-container"><div class="likert-question">{question}</div>', unsafe_allow_html=True)
|
| 868 |
+
|
| 869 |
+
# خط فرضی، لیبلها، و دکمهها
|
| 870 |
+
st.markdown(
|
| 871 |
+
f'<div class="likert-line-container">'
|
| 872 |
+
f'<span class="likert-label-left">{labels[0]}</span>'
|
| 873 |
+
f'<span class="likert-label-right">{labels[1]}</span>'
|
| 874 |
+
f'<div class="likert-buttons">',
|
| 875 |
+
unsafe_allow_html=True
|
| 876 |
+
)
|
| 877 |
+
|
| 878 |
+
# دکمهها تو یه ردیف
|
| 879 |
+
cols = st.columns(scale)
|
| 880 |
+
for i in range(scale):
|
| 881 |
+
with cols[i]:
|
| 882 |
+
value = scale - i # 7 تا 1
|
| 883 |
+
symbol = "•" if st.session_state[key] == value else "○"
|
| 884 |
+
if st.button(
|
| 885 |
+
symbol,
|
| 886 |
+
key=f"streamlit-btn-{key}-{value}",
|
| 887 |
+
help=str(value)
|
| 888 |
+
):
|
| 889 |
+
st.session_state[key] = value
|
| 890 |
+
st.rerun()
|
| 891 |
+
|
| 892 |
+
st.markdown('</div></div>', unsafe_allow_html=True)
|
| 893 |
+
|
| 894 |
+
# نمایش پاسخ
|
| 895 |
+
st.markdown(
|
| 896 |
+
f'<div class="likert-response">پاسخ شما: {st.session_state[key] or "هیچکدام"}</div>',
|
| 897 |
+
unsafe_allow_html=True
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 901 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
return st.session_state.get(key)
|
| 903 |
def create_ride_map():
|
| 904 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|