Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,59 +739,136 @@ 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 |
-
# مقدار پیشفرض
|
| 749 |
default_value = st.session_state.get(key, (scale + 1) // 2)
|
| 750 |
|
| 751 |
-
# استایلدهی
|
| 752 |
st.markdown(f"""
|
| 753 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 754 |
.likert-btn {{
|
| 755 |
-
width:
|
| 756 |
-
height:
|
| 757 |
-
border-radius: 50%
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
}}
|
| 762 |
-
.likert-selected {{
|
| 763 |
-
|
| 764 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
}}
|
| 766 |
</style>
|
| 767 |
-
<p style="font-size:16px; font-weight:bold; text-align:center; margin-bottom:10px;">{question}</p>
|
| 768 |
-
<div style="display:flex; justify-content:space-between; margin-bottom:5px;">
|
| 769 |
-
<span>{labels[0]}</span>
|
| 770 |
-
<span>{labels[1]}</span>
|
| 771 |
-
</div>
|
| 772 |
-
""", unsafe_allow_html=True)
|
| 773 |
-
|
| 774 |
-
# ایجاد دکمههای دایرهای
|
| 775 |
-
cols = st.columns(scale)
|
| 776 |
-
selected = default_value
|
| 777 |
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 792 |
""", unsafe_allow_html=True)
|
| 793 |
|
| 794 |
-
|
|
|
|
| 795 |
|
| 796 |
def create_ride_map():
|
| 797 |
"""ایجاد نقشه سفر با 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 |
default_value = st.session_state.get(key, (scale + 1) // 2)
|
| 750 |
|
| 751 |
+
# استایلدهی پیشرفته
|
| 752 |
st.markdown(f"""
|
| 753 |
<style>
|
| 754 |
+
.likert-container {{
|
| 755 |
+
direction: rtl;
|
| 756 |
+
margin-bottom: 25px;
|
| 757 |
+
}}
|
| 758 |
+
.likert-question {{
|
| 759 |
+
font-family: 'B Nazanin';
|
| 760 |
+
font-size: 18px;
|
| 761 |
+
font-weight: bold;
|
| 762 |
+
text-align: center;
|
| 763 |
+
margin-bottom: 15px;
|
| 764 |
+
color: #333;
|
| 765 |
+
}}
|
| 766 |
+
.likert-labels {{
|
| 767 |
+
display: flex;
|
| 768 |
+
justify-content: space-between;
|
| 769 |
+
margin-bottom: 8px;
|
| 770 |
+
font-family: 'B Nazanin';
|
| 771 |
+
font-size: 14px;
|
| 772 |
+
color: #555;
|
| 773 |
+
}}
|
| 774 |
+
.likert-buttons {{
|
| 775 |
+
display: flex;
|
| 776 |
+
justify-content: center;
|
| 777 |
+
gap: 5px;
|
| 778 |
+
margin-bottom: 10px;
|
| 779 |
+
}}
|
| 780 |
.likert-btn {{
|
| 781 |
+
width: 42px;
|
| 782 |
+
height: 42px;
|
| 783 |
+
border-radius: 50%;
|
| 784 |
+
border: 2px solid #6a0dad;
|
| 785 |
+
background: white;
|
| 786 |
+
color: #6a0dad;
|
| 787 |
+
font-family: 'B Nazanin';
|
| 788 |
+
font-weight: bold;
|
| 789 |
+
font-size: 16px;
|
| 790 |
+
display: flex;
|
| 791 |
+
align-items: center;
|
| 792 |
+
justify-content: center;
|
| 793 |
+
cursor: pointer;
|
| 794 |
+
transition: all 0.3s ease;
|
| 795 |
+
margin: 0 2px;
|
| 796 |
+
}}
|
| 797 |
+
.likert-btn:hover {{
|
| 798 |
+
background: #f0e6ff;
|
| 799 |
+
transform: scale(1.05);
|
| 800 |
+
}}
|
| 801 |
+
.likert-btn.selected {{
|
| 802 |
+
background: #6a0dad;
|
| 803 |
+
color: white;
|
| 804 |
+
box-shadow: 0 0 10px rgba(106,13,173,0.5);
|
| 805 |
}}
|
| 806 |
+
.likert-selected-value {{
|
| 807 |
+
text-align: center;
|
| 808 |
+
font-family: 'B Nazanin';
|
| 809 |
+
font-size: 16px;
|
| 810 |
+
color: #6a0dad;
|
| 811 |
+
font-weight: bold;
|
| 812 |
+
margin-top: 10px;
|
| 813 |
+
padding: 8px;
|
| 814 |
+
background: #f8f0ff;
|
| 815 |
+
border-radius: 8px;
|
| 816 |
+
display: inline-block;
|
| 817 |
+
min-width: 200px;
|
| 818 |
}}
|
| 819 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 820 |
|
| 821 |
+
<div class="likert-container">
|
| 822 |
+
<div class="likert-question">{question}</div>
|
| 823 |
+
<div class="likert-labels">
|
| 824 |
+
<span>{labels[0]}</span>
|
| 825 |
+
<span>{labels[1]}</span>
|
| 826 |
+
</div>
|
| 827 |
+
<div class="likert-buttons" id="buttons_{key}">
|
| 828 |
+
{"".join([
|
| 829 |
+
f'<div class="likert-btn {"selected" if st.session_state.get(key, default_value) == i+1 else ""}" '
|
| 830 |
+
f'onclick="updateSelection({i+1}, \'{key}\')">{i+1}</div>'
|
| 831 |
+
for i in range(scale)
|
| 832 |
+
])}
|
| 833 |
+
</div>
|
| 834 |
+
<div style="text-align:center;">
|
| 835 |
+
<div class="likert-selected-value" id="selected_{key}">
|
| 836 |
+
پاسخ شما: {st.session_state.get(key, default_value)}
|
| 837 |
+
</div>
|
| 838 |
+
</div>
|
| 839 |
+
</div>
|
| 840 |
|
| 841 |
+
<script>
|
| 842 |
+
function updateSelection(value, key) {{
|
| 843 |
+
// بهروزرسانی UI
|
| 844 |
+
const buttons = document.getElementById(`buttons_${{key}}`).children;
|
| 845 |
+
for (let btn of buttons) {{
|
| 846 |
+
btn.classList.remove("selected");
|
| 847 |
+
if (parseInt(btn.innerText) === value) {{
|
| 848 |
+
btn.classList.add("selected");
|
| 849 |
+
}}
|
| 850 |
+
}}
|
| 851 |
+
document.getElementById(`selected_${{key}}`).innerHTML = "پاسخ شما: " + value;
|
| 852 |
+
|
| 853 |
+
// ارسال به Streamlit
|
| 854 |
+
window.parent.postMessage({{
|
| 855 |
+
type: 'streamlit:setComponentValue',
|
| 856 |
+
key: key,
|
| 857 |
+
value: value
|
| 858 |
+
}}, '*');
|
| 859 |
+
|
| 860 |
+
// ذخیره در session
|
| 861 |
+
window.parent.postMessage({{
|
| 862 |
+
type: 'streamlit:setSessionState',
|
| 863 |
+
key: key,
|
| 864 |
+
value: value
|
| 865 |
+
}}, '*');
|
| 866 |
+
}}
|
| 867 |
+
</script>
|
| 868 |
""", unsafe_allow_html=True)
|
| 869 |
|
| 870 |
+
# مقدار بازگشتی
|
| 871 |
+
return st.session_state.get(key, default_value)
|
| 872 |
|
| 873 |
def create_ride_map():
|
| 874 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|