Skip to content

Commit

Permalink
#84 Fixes of Schools are not plotted in map in streamlit app (#90)
Browse files Browse the repository at this point in the history
* Fixes of Schools are not plotted in map in streamlit app

* Fetch Schools Latitude,Logitude from session rather than fetching data from given school's sample_data

* Use School List instead of fetching lat,long,scode from school-center-distance and use dataframe in tab3 instead of re-reading from tsv file

---------

Co-authored-by: nirmala.sharma <nirmala.sharma@imark.com.np>
  • Loading branch information
nirmala-sharma and nirmala.sharma committed May 15, 2024
1 parent 4701ccf commit 6dc5e32
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

calculate = st.sidebar.button("Calculate Centers", type="primary", use_container_width=True)

school_df = None
# Tabs
tab1, tab2, tab3, tab4, tab5 = st.tabs([
"School Center",
Expand All @@ -73,7 +74,9 @@
# Show data in Tabs as soon as the files are uploaded
if schools_file:
df = pd.read_csv(schools_file, sep="\t")
school_df = df
tab3.dataframe(df)

else:
tab3.info("Upload data to view it.", icon="ℹ️")

Expand Down Expand Up @@ -193,9 +196,37 @@ def save_file_to_temp(file_obj):
icon=folium.Icon(color="red")
)
)

# Initialize an empty dictionary to store school coordinates
filtered_schools = {}

if school_df is not None:

for index, row in school_df.iterrows():
scode = row['scode']
school_lat = row['lat']
school_long = row['long']

if scode in filtered_df['scode'].values:
filtered_schools.setdefault(scode, []).append((school_lat, school_long))

for index, school in filtered_df.iterrows():
lat_long_list = filtered_schools.get(school['scode'], [])

for school_lat, school_long in lat_long_list:
if school_lat is not None and school_long is not None:
fg.add_child(
folium.Marker(
location=[school_lat, school_long],
popup=f"{school['school'].title()}\nAllocation: {school['allocation']}",
tooltip=f"{school['school']}",
icon=folium.Icon(color="blue")
)
)

m.add_child(fg)
with tab1:
st_folium( m, width=1200, height=400 )
st_folium( m, width=1200, height=400)

tab1.divider()
tab1.subheader('All Data')
Expand Down

0 comments on commit 6dc5e32

Please sign in to comment.