Skip to content

Commit 2f7fa62

Browse files
committed
Merge branch 'main' into package-manager
2 parents 6e9cd47 + 3d0fb81 commit 2f7fa62

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

app.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import streamlit as st
77
from streamlit_folium import st_folium
88

9+
910
#Page Setup
1011
st.set_page_config(
1112
page_title="MOEST Exam Center Calculator",
@@ -15,6 +16,18 @@
1516
initial_sidebar_state="expanded",
1617
)
1718

19+
# Custom CSS
20+
custom_css = """
21+
<style>
22+
.st-ag.st-e4.st-e5 {
23+
flex-direction: row !important;
24+
}
25+
</style>
26+
"""
27+
28+
# Render custom CSS
29+
st.markdown(custom_css, unsafe_allow_html=True)
30+
1831
# Session setup
1932
if 'calculate_clicked' not in st.session_state:
2033
st.session_state.calculate_clicked = False
@@ -27,7 +40,6 @@
2740
if 'filter_value' not in st.session_state:
2841
st.session_state.filter_value = None
2942

30-
3143
#Maps setup
3244
m = folium.Map(location=[27.7007, 85.3001], zoom_start=12, )
3345
fg = folium.FeatureGroup(name="Allocated Centers")
@@ -141,16 +153,35 @@ def save_file_to_temp(file_obj):
141153
# Display data from session state
142154
if 'school_center' in st.session_state.calculated_data:
143155
df_school_center = pd.read_csv(st.session_state.calculated_data['school_center'], sep="\t")
144-
allowed_filter_types = ['scode', 'school', 'cscode', 'center']
156+
allowed_filter_types = ['school', 'center']
145157
st.session_state.filter_type = tab1.radio("Choose a filter type:", allowed_filter_types)
146158

147159
# Display an input field based on the selected filter type
148160
if st.session_state.filter_type:
149-
st.session_state.filter_value = tab1.selectbox(f"Select a value for {st.session_state.filter_type}:", df_school_center[st.session_state.filter_type].unique())
150-
# Filter the DataFrame based on the selected filter type and value
161+
if st.session_state.filter_type == 'school':
162+
# Create filter options with school name and code
163+
filter_options = [f"{code} | {name}" for name, code in zip(df_school_center['school'].unique(), df_school_center['scode'].unique())]
164+
165+
elif st.session_state.filter_type == 'center':
166+
# Create filter options with center name and code
167+
filter_options = [f"{code} | {name}" for name, code in zip(df_school_center['center'].unique(), df_school_center['cscode'].unique())]
168+
169+
# Display a selectbox for selection
170+
st.session_state.filter_value = tab1.selectbox(f"Select a value for {st.session_state.filter_type}:", filter_options)
171+
172+
# Split the selected value to extract name and code
173+
code, name = st.session_state.filter_value.split(' | ')
174+
175+
# Filter the DataFrame based on the selected type and value
176+
filtered_df = filter_data(df_school_center, st.session_state.filter_type, name)
177+
151178
if st.session_state.filter_value:
152-
filtered_df = filter_data(df_school_center, st.session_state.filter_type, st.session_state.filter_value)
153-
tab1.dataframe(filtered_df)
179+
# Remove thousand separator comma in scode and cscode
180+
styled_df = filtered_df.style.format({
181+
"cscode": lambda x: '{:.0f}'.format(x),
182+
"scode": lambda x: '{:.0f}'.format(x)
183+
})
184+
tab1.dataframe(styled_df , hide_index=True)
154185
tab1.subheader('Map')
155186
tab1.divider()
156187
for index, center in filtered_df.iterrows():
@@ -175,7 +206,9 @@ def save_file_to_temp(file_obj):
175206
if 'school_center_distance' in st.session_state.calculated_data:
176207
df = pd.read_csv(st.session_state.calculated_data['school_center_distance'], sep="\t")
177208
tab2.dataframe(df)
209+
178210
else:
179211
tab2.error("School Center Distance file not found.")
212+
180213
elif st.session_state.calculate_clicked and not st.session_state.calculated_data:
181214
tab1.error("School Center data not found in session state.")

0 commit comments

Comments
 (0)