import streamlit as st import pandas as pd import plotly.express as px import plotly.graph_objs as go # Load the CSV file # file = "brick_kiln_lucknow_v1.csv" # Replace with the correct path to your CSV file # Dropdown to select the location location = st.selectbox("Select Location", ["Lucknow", "Delhi", "Ahmedabad"]) # Determine the file path based on selection if location == "Lucknow": file = "brick_kiln_lucknow_v1.csv" center_lat, center_lon = 26.8467, 80.9462 elif location == "Delhi": file = "brick_kiln_delhi_v1.csv" center_lat, center_lon = 28.7041, 77.1025 else: # Ahmedabad file = "brick_kiln_ahmedabad_v2.csv" # Replace with the actual path center_lat, center_lon = 23.0225, 72.5714 data = pd.read_csv(file) # Streamlit app title st.markdown("

Brick Kiln Location and Conversion Visualization

", unsafe_allow_html=True) # Slider to select the year year_selected = st.slider("Select the Year", min_value=int(data["Year made"].min()), max_value=int(data["Year made"].max()), value=int(data["Year made"].min()), step=1) filtered_data = data[data["Year made"] <= year_selected] # # Calculate the change in fcbk to zigzag by checking the 'fcb to zigzag' column filtered_data["Conversion"] = filtered_data.apply( lambda row: "Converted" if row["Year made"] != row["fcb to zigzag"] else "No Conversion", axis=1 ) # Function to determine the status of each kiln based on the selected year def get_status(row, year_selected): if row["fcb to zigzag"]==2009: return "fcbk" elif year_selected == row["fcb to zigzag"]: return "converted" else: return "zigzag" # Function to classify each kiln based on the selected year def classify_kiln(row, year_selected): if row["Year made"] > year_selected: return None # Kiln not yet made elif row["fcb to zigzag"] > year_selected: return "FCBK" # Kiln still FCBK else: return "Zigzag" # Kiln has converted to Zigzag # Apply classification to the data based on the selected year data["Status1"] = data.apply(lambda row: classify_kiln(row, year_selected), axis=1) fcbk_count = data[data["Status1"] == "FCBK"].shape[0] zigzag_count = data[data["Status1"] == "Zigzag"].shape[0] # Apply the status function to each row data["Status"] = data.apply(lambda row: get_status(row, year_selected), axis=1) filtered_data_conv = data[data["Year made"] <= year_selected] filtered_data_conv["Type"] = filtered_data_conv["Type"].map({0: "fcbk", 1: "zigzag"}) filtered_data["Type"] = filtered_data["Type"].map({0: "fcbk", 1: "Zigzag"}) # Count the total brick kilns, fcbk, zigzag, and conversions total_kilns = len(filtered_data) fcbk_count1 = filtered_data[(filtered_data["Type"] == "fcbk")].shape[0] zigzag_count1 = filtered_data_conv[(filtered_data_conv["Type"] == 'zigzag')].shape[0] converted_count = filtered_data_conv[filtered_data_conv["Status"] == "converted"].shape[0] # Display the total count and conversions if location == "Lucknow": st.subheader(f"Total Brick Kilns in Lucknow up to Year {year_selected}: {total_kilns}") st.write(f"Fcbk: {fcbk_count1}",' and ' f"Zigzag: {zigzag_count1}") st.write(f"Converted from fcbk to zigzag: {converted_count}") elif location == "Ahmedabad": st.subheader(f"Total Brick Kilns in Ahmedabad up to Year {year_selected}: {total_kilns}") st.write(f"Fcbk: {fcbk_count1}",' and ' f"Zigzag: {zigzag_count1}") st.write(f"Converted from fcbk to zigzag: {converted_count}") else: st.subheader(f"Total Brick Kilns in Delhi up to Year {year_selected}: {total_kilns}") st.write(f"Fcbk: {fcbk_count}",' and ' f"Zigzag: {zigzag_count}") st.write(f"Converted from fcbk to zigzag: {converted_count}") if location == "Lucknow": fig_filtered = px.scatter_mapbox( data, lat="Lat", lon="Lon", color="Status", color_discrete_map={"fcbk": "blue", "converted": "green", "zigzag": "red"}, # Set colors for fcbk, converted, and zigzag kilns mapbox_style="carto-positron", hover_name="Type", zoom=8.5, center={"lat": center_lat, "lon": center_lon}, title=f"Brick Kiln Locations and Status up to Year {year_selected}", height=600, width=600 ) elif location == "Delhi": fig_filtered = px.scatter_mapbox( data, lat="Lat", lon="Lon", color="Status1", color_discrete_map={"FCBK": "blue", "converted": "green", "Zigzag": "red"}, # Set colors for fcbk, converted, and zigzag kilns mapbox_style="carto-positron", hover_name="Type", zoom=8.5, center={"lat": center_lat, "lon": center_lon}, title=f"Brick Kiln Locations and Status up to Year {year_selected}", height=600, width=600 ) else: fig_filtered = px.scatter_mapbox( data, lat="Lat", lon="Lon", color="Status", color_discrete_map={"fcbk": "blue", "zigzag": "red"}, # Set colors for fcbk, converted, and zigzag kilns mapbox_style="carto-positron", hover_name="Type", zoom=8.5, center={"lat": center_lat, "lon": center_lon}, title=f"Brick Kiln Locations and Status up to Year {year_selected}", height=600, width=600 ) # # Display the map in Streamlit # st.plotly_chart(fig_filtered) # Yearly count of fcbk and zigzag kilns up to the selected year yearly_summary = filtered_data.groupby("Year made")["Type"].value_counts().unstack(fill_value=0) # Adjust the layout to display the table next to the map # col1, col2 = st.columns([3, 1.5]) # with col1: st.plotly_chart(fig_filtered) # with col2: # st.subheader("Yearly Kiln Made") # st.dataframe(yearly_summary) # # Dropdown to select the location # Define historical data for Lucknow years_lucknow = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022] brick_kilns_total_lucknow = [117, 314, 376, 396, 408, 432, 433, 454, 461, 466, 470, 477, 478] brick_kilns_fcb_lucknow = [52, 127, 159, 171, 178, 191, 192, 206, 208, 209, 209, 209, 209] brick_kilns_zigzag_lucknow = [65, 187, 217, 225, 230, 241, 241, 248, 253, 257, 261, 268, 269] # Define historical data for Delhi years_delhi = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022] brick_kilns_total_delhi = [188,502,649,701,719,751,770,770,775,783,794,795,796] brick_kilns_fcb_delhi = [184,496,643,695,712,744,742,727,620,401,146,74,37] brick_kilns_zigzag_delhi = [4,6,6,6,7,7,28,43,155,382,648,721,759] #define for Ahmedabad years_ahmedabad = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022] brick_kilns_total_ahmedabad = [74,92,115,136,140,155,155,156,156,164,165,169,172] brick_kilns_fcb_ahmedabad = [74,92,115,136,140,155,155,156,156,164,165,168,172] brick_kilns_zigzag_ahmedabad = [0,0,0,0,0,0,0,0,0,0,0,1,0] # Select the dataset based on the location if location == "Lucknow": years = years_lucknow brick_kilns_total = brick_kilns_total_lucknow brick_kilns_fcb = brick_kilns_fcb_lucknow brick_kilns_zigzag = brick_kilns_zigzag_lucknow title = "Number of Brick Kilns Over Years in Lucknow" elif location == "Ahmedabad": years = years_ahmedabad brick_kilns_total = brick_kilns_total_ahmedabad brick_kilns_fcb = brick_kilns_fcb_ahmedabad brick_kilns_zigzag = brick_kilns_zigzag_ahmedabad title = "Number of Brick Kilns Over Years in Ahmedabad" else: years = years_delhi brick_kilns_total = brick_kilns_total_delhi brick_kilns_fcb = brick_kilns_fcb_delhi brick_kilns_zigzag = brick_kilns_zigzag_delhi title = "Number of Brick Kilns Over Years in Delhi" # Creating the line plot for the number of brick kilns over the years fig_line = go.Figure() fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_total, mode='lines+markers', name='Total Brick Kilns', line=dict(color='blue'))) fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_fcb, mode='lines+markers', name='FCBTK', line=dict(color='red'))) fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_zigzag, mode='lines+markers', name='Zigzag Brick Kilns', line=dict(color='green'))) # Adding labels and title to the line chart fig_line.update_layout( title=title, xaxis_title="Years", yaxis_title="Number of Brick Kilns", yaxis=dict(tickmode='linear', tick0=0, dtick=100, showgrid=False), width=900 ) # Adding vertical line for the selected year fig_line.add_vline(x=year_selected, line_dash="dash", line_color="black", annotation_text=f"Year {year_selected}") # Displaying the line chart st.plotly_chart(fig_line)