Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from folium.plugins import MarkerCluster
|
|
5 |
import time
|
6 |
import math
|
7 |
|
8 |
-
#
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
11 |
# Define California medical centers data
|
@@ -45,6 +45,8 @@ if 'start_time' not in st.session_state:
|
|
45 |
st.session_state.start_time = None
|
46 |
if 'elapsed_time' not in st.session_state:
|
47 |
st.session_state.elapsed_time = 0
|
|
|
|
|
48 |
|
49 |
# Distance calculation (Haversine in miles)
|
50 |
def calculate_distance(lat1, lon1, lat2, lon2):
|
@@ -74,21 +76,39 @@ def create_map():
|
|
74 |
).add_to(m)
|
75 |
return m
|
76 |
|
77 |
-
# Move hovercar
|
78 |
-
def move_car():
|
79 |
target = [st.session_state.destination[1], st.session_state.destination[2]]
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
# Calculate speed and ETA
|
86 |
total_distance = calculate_distance(st.session_state.start[1], st.session_state.start[2],
|
87 |
st.session_state.destination[1], st.session_state.destination[2])
|
88 |
-
steps = 50
|
89 |
step_time = 0.5
|
90 |
-
total_time =
|
91 |
-
speed = total_distance / (total_time / 3600)
|
92 |
|
93 |
# Layout: 75% left, 25% right
|
94 |
left_col, right_col = st.columns([3, 1])
|
@@ -97,7 +117,7 @@ left_col, right_col = st.columns([3, 1])
|
|
97 |
with left_col:
|
98 |
st.markdown("### π Hovercar Command Center πΈ")
|
99 |
m = create_map()
|
100 |
-
folium_static(m, width=1280, height=720)
|
101 |
|
102 |
# Controls
|
103 |
col1, col2, col3 = st.columns(3)
|
@@ -105,6 +125,7 @@ with left_col:
|
|
105 |
if st.button("π Launch Hovercar"):
|
106 |
st.session_state.is_moving = True
|
107 |
st.session_state.start_time = time.time()
|
|
|
108 |
with col2:
|
109 |
if st.button("π Halt Hovercar"):
|
110 |
st.session_state.is_moving = False
|
@@ -115,8 +136,38 @@ with left_col:
|
|
115 |
st.session_state.is_moving = False
|
116 |
st.session_state.start_time = None
|
117 |
st.session_state.elapsed_time = 0
|
|
|
118 |
st.rerun()
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
# Right column: Stats and two sub-columns for buttons
|
121 |
with right_col:
|
122 |
st.markdown("### π‘ Mission Status")
|
@@ -146,6 +197,7 @@ with right_col:
|
|
146 |
st.session_state.is_moving = False
|
147 |
st.session_state.start_time = None
|
148 |
st.session_state.elapsed_time = 0
|
|
|
149 |
st.rerun()
|
150 |
|
151 |
with dest_col:
|
@@ -156,12 +208,13 @@ with right_col:
|
|
156 |
st.session_state.is_moving = False
|
157 |
st.session_state.start_time = None
|
158 |
st.session_state.elapsed_time = 0
|
|
|
159 |
st.rerun()
|
160 |
|
161 |
# Movement logic
|
162 |
if st.session_state.is_moving:
|
163 |
-
move_car()
|
164 |
if st.session_state.start_time:
|
165 |
st.session_state.elapsed_time = time.time() - st.session_state.start_time
|
166 |
-
time.sleep(
|
167 |
st.rerun()
|
|
|
5 |
import time
|
6 |
import math
|
7 |
|
8 |
+
# Wide mode
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
11 |
# Define California medical centers data
|
|
|
45 |
st.session_state.start_time = None
|
46 |
if 'elapsed_time' not in st.session_state:
|
47 |
st.session_state.elapsed_time = 0
|
48 |
+
if 'arrived' not in st.session_state:
|
49 |
+
st.session_state.arrived = False
|
50 |
|
51 |
# Distance calculation (Haversine in miles)
|
52 |
def calculate_distance(lat1, lon1, lat2, lon2):
|
|
|
76 |
).add_to(m)
|
77 |
return m
|
78 |
|
79 |
+
# Move hovercar with constant speed
|
80 |
+
def move_car(total_distance, step_time):
|
81 |
target = [st.session_state.destination[1], st.session_state.destination[2]]
|
82 |
+
current = st.session_state.car_position
|
83 |
+
remaining_distance = calculate_distance(current[0], current[1], target[0], target[1])
|
84 |
+
|
85 |
+
# Speed in miles per second
|
86 |
+
total_time = 25.0 # Total trip time in seconds
|
87 |
+
speed = total_distance / total_time # miles per second
|
88 |
+
step_distance = speed * step_time # Distance per step
|
89 |
+
|
90 |
+
# Calculate direction and move
|
91 |
+
total_lat_diff = target[0] - current[0]
|
92 |
+
total_lon_diff = target[1] - current[1]
|
93 |
+
total_hyp = math.sqrt(total_lat_diff**2 + total_lon_diff**2)
|
94 |
+
if total_hyp > 0:
|
95 |
+
lat_step = (total_lat_diff / total_hyp) * step_distance / (calculate_distance(current[0], current[1], current[0] + 0.01, current[1]) / 0.01)
|
96 |
+
lon_step = (total_lon_diff / total_hyp) * step_distance / (calculate_distance(current[0], current[1], current[0], current[1] + 0.01) / 0.01)
|
97 |
+
st.session_state.car_position[0] += lat_step
|
98 |
+
st.session_state.car_position[1] += lon_step
|
99 |
+
|
100 |
+
# Check arrival
|
101 |
+
if remaining_distance < 0.1: # Within 0.1 miles
|
102 |
+
st.session_state.car_position = target
|
103 |
+
st.session_state.is_moving = False
|
104 |
+
st.session_state.arrived = True
|
105 |
|
106 |
# Calculate speed and ETA
|
107 |
total_distance = calculate_distance(st.session_state.start[1], st.session_state.start[2],
|
108 |
st.session_state.destination[1], st.session_state.destination[2])
|
|
|
109 |
step_time = 0.5
|
110 |
+
total_time = 25.0 # Fixed total trip time
|
111 |
+
speed = total_distance / (total_time / 3600) # mph
|
112 |
|
113 |
# Layout: 75% left, 25% right
|
114 |
left_col, right_col = st.columns([3, 1])
|
|
|
117 |
with left_col:
|
118 |
st.markdown("### π Hovercar Command Center πΈ")
|
119 |
m = create_map()
|
120 |
+
folium_static(m, width=1280, height=720)
|
121 |
|
122 |
# Controls
|
123 |
col1, col2, col3 = st.columns(3)
|
|
|
125 |
if st.button("π Launch Hovercar"):
|
126 |
st.session_state.is_moving = True
|
127 |
st.session_state.start_time = time.time()
|
128 |
+
st.session_state.arrived = False
|
129 |
with col2:
|
130 |
if st.button("π Halt Hovercar"):
|
131 |
st.session_state.is_moving = False
|
|
|
136 |
st.session_state.is_moving = False
|
137 |
st.session_state.start_time = None
|
138 |
st.session_state.elapsed_time = 0
|
139 |
+
st.session_state.arrived = False
|
140 |
st.rerun()
|
141 |
|
142 |
+
# Celebration on arrival
|
143 |
+
if st.session_state.arrived:
|
144 |
+
st.markdown("""
|
145 |
+
<style>
|
146 |
+
.confetti {
|
147 |
+
position: absolute;
|
148 |
+
width: 10px;
|
149 |
+
height: 10px;
|
150 |
+
background-color: #f00;
|
151 |
+
animation: fall 3s infinite;
|
152 |
+
}
|
153 |
+
@keyframes fall {
|
154 |
+
0% { transform: translateY(-100vh); }
|
155 |
+
100% { transform: translateY(100vh); }
|
156 |
+
}
|
157 |
+
</style>
|
158 |
+
<div class="confetti" style="left: 10%; background-color: #f00;"></div>
|
159 |
+
<div class="confetti" style="left: 20%; background-color: #0f0;"></div>
|
160 |
+
<div class="confetti" style="left: 30%; background-color: #00f;"></div>
|
161 |
+
<div class="confetti" style="left: 40%; background-color: #ff0;"></div>
|
162 |
+
<div class="confetti" style="left: 50%; background-color: #f0f;"></div>
|
163 |
+
<div class="confetti" style="left: 60%; background-color: #0ff;"></div>
|
164 |
+
""", unsafe_allow_html=True)
|
165 |
+
st.success("π Touchdown! Hovercar has landed!")
|
166 |
+
|
167 |
+
# Easter egg: Secret message
|
168 |
+
if st.session_state.destination[0] == "Stanford Health Care":
|
169 |
+
st.warning("π¦ Easter Egg Unlocked: Hovercar found the secret unicorn base at Stanford!")
|
170 |
+
|
171 |
# Right column: Stats and two sub-columns for buttons
|
172 |
with right_col:
|
173 |
st.markdown("### π‘ Mission Status")
|
|
|
197 |
st.session_state.is_moving = False
|
198 |
st.session_state.start_time = None
|
199 |
st.session_state.elapsed_time = 0
|
200 |
+
st.session_state.arrived = False
|
201 |
st.rerun()
|
202 |
|
203 |
with dest_col:
|
|
|
208 |
st.session_state.is_moving = False
|
209 |
st.session_state.start_time = None
|
210 |
st.session_state.elapsed_time = 0
|
211 |
+
st.session_state.arrived = False
|
212 |
st.rerun()
|
213 |
|
214 |
# Movement logic
|
215 |
if st.session_state.is_moving:
|
216 |
+
move_car(total_distance, step_time)
|
217 |
if st.session_state.start_time:
|
218 |
st.session_state.elapsed_time = time.time() - st.session_state.start_time
|
219 |
+
time.sleep(step_time)
|
220 |
st.rerun()
|