|
import streamlit as st |
|
import pandas as pd |
|
import plotly.graph_objects as go |
|
import time |
|
|
|
|
|
file_path = 'Dhaka Metro Rail Fare 2.XLSX' |
|
df = pd.read_excel(file_path) |
|
|
|
|
|
coordinates = { |
|
"Uttara North": (23.869066, 90.367445), |
|
"Uttara Center": (23.860118, 90.365106), |
|
"Uttara South": (23.845934, 90.363175), |
|
"Pallabi": (23.82619516961383, 90.36481554252525), |
|
"Mirpur 11": (23.819438208310213, 90.36528532902963), |
|
"Mirpur 10": (23.808582994847285, 90.36821595330717), |
|
"Kazipara": (23.800017952100532, 90.37178261495391), |
|
"Shewrapara": (23.79070140857881, 90.37564622631841), |
|
"Agargaon": (23.778385546736345, 90.3800557456356), |
|
"Bijoy Sarani": (23.766638127271825, 90.38307537134754), |
|
"Farmgate": (23.75923604938459, 90.38694218434738), |
|
"Kawran Bazar": (23.751392319539104, 90.39275707447003), |
|
"Shahbagh": (23.740324209546923, 90.39600784811131), |
|
"Dhaka University": (23.732091083122114, 90.39659408796354), |
|
"Bangladesh Secretariat": (23.73004754106779, 90.40764881366906), |
|
"Motijheel": (23.72816566933198, 90.41923497972823), |
|
"Kamalapur": (23.732367758919807, 90.42547378971085) |
|
} |
|
|
|
|
|
df['Origin_Lat'] = df['Origin'].map(lambda x: coordinates.get(x, (None, None))[0]) |
|
df['Origin_Lon'] = df['Origin'].map(lambda x: coordinates.get(x, (None, None))[1]) |
|
df['Destination_Lat'] = df['Destination'].map(lambda x: coordinates.get(x, (None, None))[0]) |
|
df['Destination_Lon'] = df['Destination'].map(lambda x: coordinates.get(x, (None, None))[1]) |
|
|
|
|
|
df.dropna(subset=['Origin_Lat', 'Origin_Lon', 'Destination_Lat', 'Destination_Lon'], inplace=True) |
|
|
|
|
|
st.title("Dhaka Metro Rail Fare Checker 🚇") |
|
st.write("Below is the fare chart for Dhaka Metro Rail 💶:") |
|
|
|
|
|
origin = st.selectbox( |
|
"Select your Location:", |
|
['Select Journey from'] + df['Origin'].unique().tolist() |
|
) |
|
|
|
|
|
if origin != 'Select Journey from': |
|
st.write(f"Select your destination(s) from {origin}:") |
|
destinations = st.multiselect("Choose Destinations", df[df['Origin'] == origin]['Destination'].unique().tolist()) |
|
|
|
if destinations: |
|
|
|
fare_data = df[(df['Origin'] == origin) & (df['Destination'].isin(destinations))] |
|
if not fare_data.empty: |
|
for index, row in fare_data.iterrows(): |
|
origin_to_dest_fare = row['Fare (৳)'] |
|
destination = row['Destination'] |
|
st.write(f"Fare from {origin} to {destination}: {origin_to_dest_fare}৳") |
|
|
|
|
|
fig = go.Figure() |
|
|
|
|
|
train_icon = "train" |
|
|
|
|
|
unique_stations = pd.concat([df[['Origin', 'Origin_Lat', 'Origin_Lon']].rename(columns={'Origin': 'Station', 'Origin_Lat': 'Lat', 'Origin_Lon': 'Lon'}), |
|
df[['Destination', 'Destination_Lat', 'Destination_Lon']].rename(columns={'Destination': 'Station', 'Destination_Lat': 'Lat', 'Destination_Lon': 'Lon'})]).drop_duplicates() |
|
|
|
|
|
for i, row in unique_stations.iterrows(): |
|
if row['Station'] == origin: |
|
fig.add_trace(go.Scattermapbox( |
|
mode="markers+text", |
|
lon=[row['Lon']], |
|
lat=[row['Lat']], |
|
marker={'size': 12, 'color': 'green'}, |
|
text=row['Station'], |
|
textposition="top center", |
|
name=row['Station'] |
|
)) |
|
elif row['Station'] in destinations: |
|
fig.add_trace(go.Scattermapbox( |
|
mode="markers+text", |
|
lon=[row['Lon']], |
|
lat=[row['Lat']], |
|
marker={'size': 12, 'color': 'blue'}, |
|
text=row['Station'], |
|
textposition="top center", |
|
name=row['Station'] |
|
)) |
|
|
|
|
|
train_path = [] |
|
for destination in destinations: |
|
destination_row = df[(df['Origin'] == origin) & (df['Destination'] == destination)].iloc[0] |
|
path = [coordinates[origin], (destination_row['Destination_Lat'], destination_row['Destination_Lon'])] |
|
train_path.extend(path) |
|
|
|
|
|
for i in range(len(train_path)): |
|
fig.add_trace(go.Scattermapbox( |
|
mode="markers", |
|
lon=[train_path[i][1]], |
|
lat=[train_path[i][0]], |
|
marker={'size': 20, 'symbol': train_icon, 'color': 'red'}, |
|
name="Train", |
|
showlegend=False |
|
)) |
|
|
|
|
|
fig.update_layout( |
|
mapbox=dict( |
|
style="open-street-map", |
|
center=go.layout.mapbox.Center(lat=23.780, lon=90.400), |
|
zoom=11 |
|
), |
|
margin={"r":0,"t":0,"l":0,"b":0}, |
|
showlegend=False |
|
) |
|
|
|
|
|
frames = [] |
|
for i in range(1, len(train_path)): |
|
frame = go.Frame( |
|
data=[go.Scattermapbox( |
|
mode="markers", |
|
lon=[train_path[i][1]], |
|
lat=[train_path[i][0]], |
|
marker={'size': 20, 'symbol': train_icon, 'color': 'red'}, |
|
name="Train" |
|
)], |
|
name=f"Frame_{i}" |
|
) |
|
frames.append(frame) |
|
|
|
fig.frames = frames |
|
|
|
|
|
fig.update_layout( |
|
updatemenus=[dict( |
|
type="buttons", |
|
showactive=False, |
|
buttons=[dict( |
|
label="Play", |
|
method="animate", |
|
args=[None, dict(frame=dict(duration=2000, redraw=True), fromcurrent=True)] |
|
)] |
|
)] |
|
) |
|
|
|
|
|
st.plotly_chart(fig) |
|
|