Spaces:
Paused
Paused
Maryam Ilka commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import folium
|
| 3 |
from streamlit_folium import folium_static
|
| 4 |
-
import random
|
| 5 |
from datetime import datetime
|
| 6 |
import gspread
|
| 7 |
from google.oauth2.service_account import Credentials
|
|
@@ -18,6 +17,17 @@ SHEET_NAME = "Condition1"
|
|
| 18 |
# ========== استایلهای سفارشی ==========
|
| 19 |
st.markdown("""
|
| 20 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
.ride-header {
|
| 22 |
background-color: #3d5a80;
|
| 23 |
padding: 15px;
|
|
@@ -25,6 +35,7 @@ st.markdown("""
|
|
| 25 |
color: white;
|
| 26 |
margin-bottom: 20px;
|
| 27 |
}
|
|
|
|
| 28 |
.price-box {
|
| 29 |
border: 2px solid #3d5a80;
|
| 30 |
border-radius: 10px;
|
|
@@ -34,13 +45,19 @@ st.markdown("""
|
|
| 34 |
font-size: 24px;
|
| 35 |
font-weight: bold;
|
| 36 |
}
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
margin:
|
| 42 |
-
border-right: 5px solid #3d5a80;
|
| 43 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
.survey-section {
|
| 45 |
background-color: #f0f2f6;
|
| 46 |
border-radius: 10px;
|
|
@@ -53,28 +70,44 @@ st.markdown("""
|
|
| 53 |
# ========== توابع اصلی ==========
|
| 54 |
def create_ride_map():
|
| 55 |
"""ایجاد نقشه سفر با Folium"""
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
m = folium.Map(location=[35.7, 51.3], zoom_start=11)
|
| 60 |
-
folium.Marker(start_point, popup="<b>مبدأ:</b> میدان انقلاب", icon=folium.Icon(color="green")).add_to(m)
|
| 61 |
-
folium.Marker(end_point, popup="<b>مقصد:</b> میدان امام خمینی", icon=folium.Icon(color="red")).add_to(m)
|
| 62 |
-
folium.PolyLine([start_point, end_point], color="blue", weight=2.5).add_to(m)
|
| 63 |
return m
|
| 64 |
|
| 65 |
-
def generate_random_price():
|
| 66 |
-
"""تولید قیمت تصادفی"""
|
| 67 |
-
return random.randint(80, 200) * 1000 # قیمت به تومان
|
| 68 |
-
|
| 69 |
def show_explanation(exp_type):
|
| 70 |
"""نمایش توضیحات قیمت"""
|
| 71 |
explanations = {
|
| 72 |
"control": [],
|
| 73 |
"input": [
|
| 74 |
-
"
|
| 75 |
-
"
|
| 76 |
-
"
|
| 77 |
-
"
|
| 78 |
],
|
| 79 |
"counterfactual": [
|
| 80 |
"اگر این سفر را ۳۰ دقیقه زودتر یا دیرتر درخواست میکردید، قیمت ۱۵٪ کمتر میشد",
|
|
@@ -83,12 +116,9 @@ def show_explanation(exp_type):
|
|
| 83 |
}
|
| 84 |
|
| 85 |
if exp_type != "control":
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
st.markdown(f"<p>{item}</p>", unsafe_allow_html=True)
|
| 90 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 91 |
-
return exp_type
|
| 92 |
|
| 93 |
# ========== توابع مدیریت دادهها ==========
|
| 94 |
def get_credentials():
|
|
@@ -184,7 +214,7 @@ def main():
|
|
| 184 |
if 'scenario_type' not in st.session_state:
|
| 185 |
st.session_state.scenario_type = random.choice(["control", "input", "counterfactual"])
|
| 186 |
if 'price' not in st.session_state:
|
| 187 |
-
st.session_state.price =
|
| 188 |
if 'demographic_data' not in st.session_state:
|
| 189 |
st.session_state.demographic_data = None
|
| 190 |
if 'survey_completed' not in st.session_state:
|
|
@@ -209,10 +239,10 @@ def main():
|
|
| 209 |
# اگر پرسشنامه تکمیل نشده
|
| 210 |
if not st.session_state.survey_completed:
|
| 211 |
# نمایش سناریو
|
| 212 |
-
st.markdown("### 🗺️ مسیر سفر شما")
|
| 213 |
folium_static(create_ride_map(), width=800, height=400)
|
| 214 |
|
| 215 |
-
# نمایش قیمت
|
| 216 |
st.markdown(f"""
|
| 217 |
<div class="price-box">
|
| 218 |
قیمت پیشنهادی: {st.session_state.price:,} تومان
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import folium
|
| 3 |
from streamlit_folium import folium_static
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
import gspread
|
| 6 |
from google.oauth2.service_account import Credentials
|
|
|
|
| 17 |
# ========== استایلهای سفارشی ==========
|
| 18 |
st.markdown("""
|
| 19 |
<style>
|
| 20 |
+
@font-face {
|
| 21 |
+
font-family: 'Vazir';
|
| 22 |
+
src: url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font@v30.1.0/dist/Vazir.woff') format('woff');
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
* {
|
| 26 |
+
font-family: 'Vazir', sans-serif !important;
|
| 27 |
+
text-align: right !important;
|
| 28 |
+
direction: rtl !important;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
.ride-header {
|
| 32 |
background-color: #3d5a80;
|
| 33 |
padding: 15px;
|
|
|
|
| 35 |
color: white;
|
| 36 |
margin-bottom: 20px;
|
| 37 |
}
|
| 38 |
+
|
| 39 |
.price-box {
|
| 40 |
border: 2px solid #3d5a80;
|
| 41 |
border-radius: 10px;
|
|
|
|
| 45 |
font-size: 24px;
|
| 46 |
font-weight: bold;
|
| 47 |
}
|
| 48 |
+
|
| 49 |
+
.explanation-title {
|
| 50 |
+
color: #3d5a80;
|
| 51 |
+
font-weight: bold;
|
| 52 |
+
margin-top: 20px;
|
|
|
|
| 53 |
}
|
| 54 |
+
|
| 55 |
+
.explanation-item {
|
| 56 |
+
margin: 10px 0;
|
| 57 |
+
padding-right: 15px;
|
| 58 |
+
border-right: 3px solid #3d5a80;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
.survey-section {
|
| 62 |
background-color: #f0f2f6;
|
| 63 |
border-radius: 10px;
|
|
|
|
| 70 |
# ========== توابع اصلی ==========
|
| 71 |
def create_ride_map():
|
| 72 |
"""ایجاد نقشه سفر با Folium"""
|
| 73 |
+
# مختصات تهران (میدان ونک تا میدان ولیعصر)
|
| 74 |
+
start_point = [35.7698, 51.4116] # میدان ونک
|
| 75 |
+
end_point = [35.7368, 51.4036] # میدان ولیعصر
|
| 76 |
+
|
| 77 |
+
m = folium.Map(location=[35.75, 51.41], zoom_start=14)
|
| 78 |
+
|
| 79 |
+
# اضافه کردن مبدأ و مقصد
|
| 80 |
+
folium.Marker(
|
| 81 |
+
start_point,
|
| 82 |
+
popup="<b>مبدأ:</b> میدان ونک",
|
| 83 |
+
icon=folium.Icon(color="green", icon="flag", prefix="fa")
|
| 84 |
+
).add_to(m)
|
| 85 |
+
|
| 86 |
+
folium.Marker(
|
| 87 |
+
end_point,
|
| 88 |
+
popup="<b>مقصد:</b> میدان ولیعصر",
|
| 89 |
+
icon=folium.Icon(color="red", icon="flag", prefix="fa")
|
| 90 |
+
).add_to(m)
|
| 91 |
+
|
| 92 |
+
# خط مسیر
|
| 93 |
+
folium.PolyLine(
|
| 94 |
+
[start_point, end_point],
|
| 95 |
+
color="blue",
|
| 96 |
+
weight=2.5,
|
| 97 |
+
opacity=1
|
| 98 |
+
).add_to(m)
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
return m
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
def show_explanation(exp_type):
|
| 103 |
"""نمایش توضیحات قیمت"""
|
| 104 |
explanations = {
|
| 105 |
"control": [],
|
| 106 |
"input": [
|
| 107 |
+
"سطح تقاضا در منطقه: زیاد",
|
| 108 |
+
"تعداد رانندگان فعال: کم",
|
| 109 |
+
"زمان روز: ساعت اوج ترافیک",
|
| 110 |
+
"شرایط جوی: هوای بارانی"
|
| 111 |
],
|
| 112 |
"counterfactual": [
|
| 113 |
"اگر این سفر را ۳۰ دقیقه زودتر یا دیرتر درخواست میکردید، قیمت ۱۵٪ کمتر میشد",
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
if exp_type != "control":
|
| 119 |
+
st.markdown("<p class='explanation-title'>علت قیمت گذاری:</p>", unsafe_allow_html=True)
|
| 120 |
+
for item in explanations.get(exp_type, []):
|
| 121 |
+
st.markdown(f"<p class='explanation-item'>{item}</p>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# ========== توابع مدیریت دادهها ==========
|
| 124 |
def get_credentials():
|
|
|
|
| 214 |
if 'scenario_type' not in st.session_state:
|
| 215 |
st.session_state.scenario_type = random.choice(["control", "input", "counterfactual"])
|
| 216 |
if 'price' not in st.session_state:
|
| 217 |
+
st.session_state.price = 200000 # قیمت ثابت 200 هزار تومان
|
| 218 |
if 'demographic_data' not in st.session_state:
|
| 219 |
st.session_state.demographic_data = None
|
| 220 |
if 'survey_completed' not in st.session_state:
|
|
|
|
| 239 |
# اگر پرسشنامه تکمیل نشده
|
| 240 |
if not st.session_state.survey_completed:
|
| 241 |
# نمایش سناریو
|
| 242 |
+
st.markdown("### 🗺️ مسیر سفر شما (ونک تا ولیعصر)")
|
| 243 |
folium_static(create_ride_map(), width=800, height=400)
|
| 244 |
|
| 245 |
+
# نمایش قیمت ثابت
|
| 246 |
st.markdown(f"""
|
| 247 |
<div class="price-box">
|
| 248 |
قیمت پیشنهادی: {st.session_state.price:,} تومان
|