Upload 2 files
Browse files- Dhaka Metro Rail Fare 2.XLSX +0 -0
- app.py +163 -0
Dhaka Metro Rail Fare 2.XLSX
ADDED
Binary file (13.9 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
7 |
+
df = pd.read_excel(file_path)
|
8 |
+
|
9 |
+
# Ensure necessary columns are present
|
10 |
+
required_columns = ['Origin', 'Destination', 'Fare (৳)']
|
11 |
+
if not all(col in df.columns for col in required_columns):
|
12 |
+
st.write("Please ensure the file contains 'Origin', 'Destination', and 'Fare' columns.")
|
13 |
+
else:
|
14 |
+
# Add coordinates for each station (example coordinates for illustration)
|
15 |
+
coordinates = {
|
16 |
+
"Uttara North": (23.869066, 90.367445),
|
17 |
+
"Uttara Center": (23.860118, 90.365106),
|
18 |
+
"Uttara South": (23.845934, 90.363175),
|
19 |
+
"Pallabi": (23.82619516961383, 90.36481554252525),
|
20 |
+
"Mirpur 11": (23.819438208310213, 90.36528532902963),
|
21 |
+
"Mirpur 10": (23.808582994847285, 90.36821595330717),
|
22 |
+
"Kazipara": (23.800017952100532, 90.37178261495391),
|
23 |
+
"Shewrapara": (23.79070140857881, 90.37564622631841),
|
24 |
+
"Agargaon": (23.778385546736345, 90.3800557456356),
|
25 |
+
"Bijoy Sarani": (23.766638127271825, 90.38307537134754),
|
26 |
+
"Farmgate": (23.75923604938459, 90.38694218434738),
|
27 |
+
"Kawran Bazar": (23.751392319539104, 90.39275707447003),
|
28 |
+
"Shahbagh": (23.740324209546923, 90.39600784811131),
|
29 |
+
"Dhaka University": (23.732091083122114, 90.39659408796354),
|
30 |
+
"Bangladesh Secretariat": (23.73004754106779, 90.40764881366906),
|
31 |
+
"Motijheel": (23.72816566933198, 90.41923497972823),
|
32 |
+
"Kamalapur": (23.732367758919807, 90.42547378971085)
|
33 |
+
}
|
34 |
+
|
35 |
+
# Add latitude and longitude for origin and destination based on the coordinates dictionary
|
36 |
+
df['Origin_Lat'] = df['Origin'].map(lambda x: coordinates.get(x, (None, None))[0])
|
37 |
+
df['Origin_Lon'] = df['Origin'].map(lambda x: coordinates.get(x, (None, None))[1])
|
38 |
+
df['Destination_Lat'] = df['Destination'].map(lambda x: coordinates.get(x, (None, None))[0])
|
39 |
+
df['Destination_Lon'] = df['Destination'].map(lambda x: coordinates.get(x, (None, None))[1])
|
40 |
+
|
41 |
+
# Filter rows with missing coordinates
|
42 |
+
df.dropna(subset=['Origin_Lat', 'Origin_Lon', 'Destination_Lat', 'Destination_Lon'], inplace=True)
|
43 |
+
|
44 |
+
# Streamlit UI setup
|
45 |
+
st.title("Dhaka Metro Rail Fare Checker 🚇")
|
46 |
+
st.write("Below is the fare chart for Dhaka Metro Rail 💶:")
|
47 |
+
|
48 |
+
# Instruction sidebar
|
49 |
+
st.sidebar.title("Instructions")
|
50 |
+
st.sidebar.write("""
|
51 |
+
**Welcome to the Dhaka Metro Rail Fare Checker!**
|
52 |
+
|
53 |
+
*How to use:*
|
54 |
+
1. Select your **Location station** from the dropdown menu.
|
55 |
+
2. Select your **destination(s)** from the list. You can select multiple destinations.
|
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 |
+
|
61 |
+
If you face any issues or need further assistance, feel free to [Contact Support on WhatsApp](https://wa.me/+8801719296601).
|
62 |
+
""")
|
63 |
+
|
64 |
+
# Define the default "Select Journey from" message
|
65 |
+
default_origin = "Select Journey from"
|
66 |
+
|
67 |
+
# Dropdown for selecting origin (with "Select Journey from" as a default placeholder)
|
68 |
+
origin = st.selectbox(
|
69 |
+
"Select your Location:",
|
70 |
+
[default_origin] + df['Origin'].unique().tolist(), # Add the "Select Journey from" option at the top
|
71 |
+
index=0 # Ensure the first option is selected by default
|
72 |
+
)
|
73 |
+
|
74 |
+
# Initialize session state for destination selection if not already set
|
75 |
+
if 'destination_select' not in st.session_state:
|
76 |
+
st.session_state.destination_select = []
|
77 |
+
|
78 |
+
# Multiselect for destinations (pass the default from session state)
|
79 |
+
destinations = st.multiselect(
|
80 |
+
"Select your destination(s):",
|
81 |
+
df['Destination'].unique(),
|
82 |
+
default=st.session_state.destination_select
|
83 |
+
)
|
84 |
+
|
85 |
+
# Update session state based on the selected destinations
|
86 |
+
st.session_state.destination_select = destinations
|
87 |
+
|
88 |
+
# If the user hasn't selected a valid origin yet, don't proceed
|
89 |
+
if origin == default_origin:
|
90 |
+
st.write("Please select a valid origin station to proceed.")
|
91 |
+
elif origin and destinations:
|
92 |
+
# Filter the dataframe based on user selection
|
93 |
+
fare_data = df[(df['Origin'] == origin) & (df['Destination'].isin(destinations))]
|
94 |
+
|
95 |
+
# Display the fare data
|
96 |
+
if not fare_data.empty:
|
97 |
+
for index, row in fare_data.iterrows():
|
98 |
+
st.write(f"Fare from {origin} to {row['Destination']} is: {row['Fare (৳)']}৳")
|
99 |
+
else:
|
100 |
+
st.write("No fare data available for the selected origin and destinations.")
|
101 |
+
else:
|
102 |
+
st.write("Please select both an origin and at least one destination.")
|
103 |
+
|
104 |
+
# Plotting the map using Plotly
|
105 |
+
fig = go.Figure()
|
106 |
+
|
107 |
+
# Add markers for each unique station
|
108 |
+
unique_stations = pd.concat([df[['Origin', 'Origin_Lat', 'Origin_Lon']].rename(columns={'Origin': 'Station', 'Origin_Lat': 'Lat', 'Origin_Lon': 'Lon'}),
|
109 |
+
df[['Destination', 'Destination_Lat', 'Destination_Lon']].rename(columns={'Destination': 'Station', 'Destination_Lat': 'Lat', 'Destination_Lon': 'Lon'})]).drop_duplicates()
|
110 |
+
|
111 |
+
# Add a map marker for each station
|
112 |
+
for i, row in unique_stations.iterrows():
|
113 |
+
if row['Station'] == origin:
|
114 |
+
# Mark the origin as green
|
115 |
+
fig.add_trace(go.Scattermapbox(
|
116 |
+
mode="markers+text",
|
117 |
+
lon=[row['Lon']],
|
118 |
+
lat=[row['Lat']],
|
119 |
+
marker={'size': 12, 'color': 'green'},
|
120 |
+
text=row['Station'],
|
121 |
+
textposition="top center",
|
122 |
+
name=row['Station'],
|
123 |
+
customdata=[row['Station']] # customdata is now a list
|
124 |
+
))
|
125 |
+
elif row['Station'] in destinations:
|
126 |
+
# Mark the destination as blue
|
127 |
+
fig.add_trace(go.Scattermapbox(
|
128 |
+
mode="markers+text",
|
129 |
+
lon=[row['Lon']],
|
130 |
+
lat=[row['Lat']],
|
131 |
+
marker={'size': 12, 'color': 'blue'},
|
132 |
+
text=row['Station'],
|
133 |
+
textposition="top center",
|
134 |
+
name=row['Station'],
|
135 |
+
customdata=[row['Station']] # customdata is now a list
|
136 |
+
))
|
137 |
+
else:
|
138 |
+
# Mark all other stations as red
|
139 |
+
fig.add_trace(go.Scattermapbox(
|
140 |
+
mode="markers+text",
|
141 |
+
lon=[row['Lon']],
|
142 |
+
lat=[row['Lat']],
|
143 |
+
marker={'size': 12, 'color': 'red'},
|
144 |
+
text=row['Station'],
|
145 |
+
textposition="top center",
|
146 |
+
name=row['Station'],
|
147 |
+
customdata=[row['Station']] # customdata is now a list
|
148 |
+
))
|
149 |
+
|
150 |
+
# Map layout
|
151 |
+
fig.update_layout(
|
152 |
+
mapbox=dict(
|
153 |
+
style="open-street-map",
|
154 |
+
center=go.layout.mapbox.Center(lat=23.780, lon=90.400), # Center on Dhaka
|
155 |
+
zoom=11
|
156 |
+
),
|
157 |
+
margin={"r":0,"t":0,"l":0,"b":0},
|
158 |
+
showlegend=False,
|
159 |
+
title="Dhaka Metro Rail Location Map"
|
160 |
+
)
|
161 |
+
|
162 |
+
# Show plot in Streamlit
|
163 |
+
st.plotly_chart(fig)
|