Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.graph_objects as go
|
|
|
4 |
|
5 |
# Load the Excel file
|
6 |
file_path = 'Dhaka Metro Rail Fare 2.XLSX' # Ensure the correct file path
|
@@ -54,7 +55,7 @@ else:
|
|
54 |
1. Select your **Location station** from the dropdown menu.
|
55 |
2. Select your **destination(s)** by clicking the destination buttons.
|
56 |
3. The fare from your location to the selected destination(s) will be displayed below.
|
57 |
-
4. You can also see the stations marked on a map
|
58 |
|
59 |
**Note:** The map highlights your location in green and destinations in blue.
|
60 |
|
@@ -107,7 +108,6 @@ else:
|
|
107 |
fare_data = df[(df['Origin'] == origin) & (df['Destination'].isin(destinations))]
|
108 |
|
109 |
# Display the fare data
|
110 |
-
# Display the fare data in a creative and aesthetic format
|
111 |
if not fare_data.empty:
|
112 |
for index, row in fare_data.iterrows():
|
113 |
origin_to_dest_fare = row['Fare (৳)']
|
@@ -133,65 +133,91 @@ else:
|
|
133 |
else:
|
134 |
st.write("Please select both an origin and at least one destination.")
|
135 |
|
136 |
-
st.write("Below is the Map for Dhaka Metro Rail 💶:")
|
137 |
|
138 |
-
# Plotting the map using Plotly
|
139 |
fig = go.Figure()
|
140 |
|
141 |
# Add markers for each unique station
|
142 |
unique_stations = pd.concat([df[['Origin', 'Origin_Lat', 'Origin_Lon']].rename(columns={'Origin': 'Station', 'Origin_Lat': 'Lat', 'Origin_Lon': 'Lon'}),
|
143 |
df[['Destination', 'Destination_Lat', 'Destination_Lon']].rename(columns={'Destination': 'Station', 'Destination_Lat': 'Lat', 'Destination_Lon': 'Lon'})]).drop_duplicates()
|
144 |
|
145 |
-
#
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
182 |
))
|
183 |
|
184 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
fig.update_layout(
|
186 |
mapbox=dict(
|
187 |
style="open-street-map",
|
188 |
center=go.layout.mapbox.Center(lat=23.780, lon=90.400), # Center on Dhaka
|
189 |
zoom=11
|
190 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
margin={"r":0,"t":0,"l":0,"b":0},
|
192 |
showlegend=False,
|
193 |
-
title="Dhaka Metro Rail Location Map"
|
194 |
)
|
195 |
|
|
|
|
|
|
|
196 |
# Show plot in Streamlit
|
197 |
st.plotly_chart(fig)
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.graph_objects as go
|
4 |
+
import time
|
5 |
|
6 |
# Load the Excel file
|
7 |
file_path = 'Dhaka Metro Rail Fare 2.XLSX' # Ensure the correct file path
|
|
|
55 |
1. Select your **Location station** from the dropdown menu.
|
56 |
2. Select your **destination(s)** by clicking the destination buttons.
|
57 |
3. The fare from your location to the selected destination(s) will be displayed below.
|
58 |
+
4. You can also see the stations marked on a map with an animated train journey!
|
59 |
|
60 |
**Note:** The map highlights your location in green and destinations in blue.
|
61 |
|
|
|
108 |
fare_data = df[(df['Origin'] == origin) & (df['Destination'].isin(destinations))]
|
109 |
|
110 |
# Display the fare data
|
|
|
111 |
if not fare_data.empty:
|
112 |
for index, row in fare_data.iterrows():
|
113 |
origin_to_dest_fare = row['Fare (৳)']
|
|
|
133 |
else:
|
134 |
st.write("Please select both an origin and at least one destination.")
|
135 |
|
136 |
+
st.write("Below is the Animated Map for Dhaka Metro Rail 💶:")
|
137 |
|
138 |
+
# Plotting the map using Plotly with animation
|
139 |
fig = go.Figure()
|
140 |
|
141 |
# Add markers for each unique station
|
142 |
unique_stations = pd.concat([df[['Origin', 'Origin_Lat', 'Origin_Lon']].rename(columns={'Origin': 'Station', 'Origin_Lat': 'Lat', 'Origin_Lon': 'Lon'}),
|
143 |
df[['Destination', 'Destination_Lat', 'Destination_Lon']].rename(columns={'Destination': 'Station', 'Destination_Lat': 'Lat', 'Destination_Lon': 'Lon'})]).drop_duplicates()
|
144 |
|
145 |
+
# Store the animation frames for the train's movement
|
146 |
+
frames = []
|
147 |
+
|
148 |
+
# For each selected destination, animate the train from the origin to the destination
|
149 |
+
if origin != default_origin and destinations:
|
150 |
+
for dest in destinations:
|
151 |
+
origin_coords = (coordinates[origin][0], coordinates[origin][1])
|
152 |
+
destination_coords = (coordinates[dest][0], coordinates[dest][1])
|
153 |
+
|
154 |
+
# Create frames for animation (move from origin to destination)
|
155 |
+
num_frames = 30
|
156 |
+
lat_diff = (destination_coords[0] - origin_coords[0]) / num_frames
|
157 |
+
lon_diff = (destination_coords[1] - origin_coords[1]) / num_frames
|
158 |
+
|
159 |
+
frames = [
|
160 |
+
go.Frame(
|
161 |
+
data=[go.Scattermapbox(
|
162 |
+
mode="markers+text",
|
163 |
+
lon=[origin_coords[1] + lon_diff * i],
|
164 |
+
lat=[origin_coords[0] + lat_diff * i],
|
165 |
+
marker={'size': 15, 'color': 'orange'},
|
166 |
+
text="🚆 Train",
|
167 |
+
textposition="top center"
|
168 |
+
)],
|
169 |
+
name=f"frame_{i}"
|
170 |
+
) for i in range(num_frames)
|
171 |
+
]
|
172 |
+
|
173 |
+
# Add final frame for destination
|
174 |
+
frames.append(go.Frame(
|
175 |
+
data=[go.Scattermapbox(
|
176 |
+
mode="markers+text",
|
177 |
+
lon=[destination_coords[1]],
|
178 |
+
lat=[destination_coords[0]],
|
179 |
+
marker={'size': 15, 'color': 'orange'},
|
180 |
+
text="🚆 Train",
|
181 |
+
textposition="top center"
|
182 |
+
)],
|
183 |
+
name=f"frame_{num_frames}"
|
184 |
))
|
185 |
|
186 |
+
# Add base station markers
|
187 |
+
for i, row in unique_stations.iterrows():
|
188 |
+
fig.add_trace(go.Scattermapbox(
|
189 |
+
mode="markers+text",
|
190 |
+
lon=[row['Lon']],
|
191 |
+
lat=[row['Lat']],
|
192 |
+
marker={'size': 10, 'color': 'blue'},
|
193 |
+
text=row['Station'],
|
194 |
+
textposition="top center",
|
195 |
+
name=row['Station']
|
196 |
+
))
|
197 |
+
|
198 |
+
# Map layout with animation
|
199 |
fig.update_layout(
|
200 |
mapbox=dict(
|
201 |
style="open-street-map",
|
202 |
center=go.layout.mapbox.Center(lat=23.780, lon=90.400), # Center on Dhaka
|
203 |
zoom=11
|
204 |
),
|
205 |
+
updatemenus=[dict(
|
206 |
+
type="buttons",
|
207 |
+
showactive=False,
|
208 |
+
buttons=[dict(
|
209 |
+
label="Play",
|
210 |
+
method="animate",
|
211 |
+
args=[None, dict(frame=dict(duration=100, redraw=True), fromcurrent=True)]
|
212 |
+
)]
|
213 |
+
)],
|
214 |
margin={"r":0,"t":0,"l":0,"b":0},
|
215 |
showlegend=False,
|
216 |
+
title="Dhaka Metro Rail Location Map with Train Animation"
|
217 |
)
|
218 |
|
219 |
+
# Add frames for animation
|
220 |
+
fig.frames = frames
|
221 |
+
|
222 |
# Show plot in Streamlit
|
223 |
st.plotly_chart(fig)
|