|
import streamlit as st |
|
import pandas as pd |
|
import plotly.express as px |
|
import plotly.graph_objs as go |
|
|
|
|
|
file = "brick_kiln_lucknow_v1.csv" |
|
data = pd.read_csv(file) |
|
|
|
|
|
st.markdown("<h2 style='text-align: center;'>Brick Kiln Location and Conversion Visualization</h2>", unsafe_allow_html=True) |
|
|
|
|
|
year_selected = st.slider("Select the Year", min_value=int(data["Year made"].min()), max_value=int(data["fcb to zigzag"].max()), value=int(data["Year made"].min()), step=1) |
|
filtered_data = data[data["Year made"] <= year_selected] |
|
|
|
|
|
filtered_data["Conversion"] = filtered_data.apply( |
|
lambda row: "Converted" if row["Year made"] != row["fcb to zigzag"] else "No Conversion", axis=1 |
|
) |
|
|
|
|
|
|
|
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" |
|
|
|
|
|
|
|
|
|
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"}) |
|
|
|
total_kilns = len(filtered_data) |
|
fcbk_count = filtered_data[(filtered_data["Type"] == "fcbk")].shape[0] |
|
zigzag_count = filtered_data_conv[(filtered_data_conv["Type"] == 'zigzag')].shape[0] |
|
converted_count = filtered_data_conv[filtered_data_conv["Status"] == "converted"].shape[0] |
|
|
|
|
|
|
|
st.subheader(f"Total Brick Kilns 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}") |
|
|
|
|
|
|
|
fig_filtered = px.scatter_mapbox( |
|
data, |
|
lat="Lat", |
|
lon="Lon", |
|
color="Status", |
|
color_discrete_map={"fcbk": "blue", "converted": "green", "zigzag": "red"}, |
|
mapbox_style="carto-positron", |
|
hover_name="Type", |
|
zoom=8.5, |
|
center={"lat": 26.8467, "lon": 80.9462}, |
|
title=f"Brick Kiln Locations and Status up to Year {year_selected}", |
|
height=600, |
|
width=600 |
|
) |
|
|
|
|
|
|
|
|
|
|
|
yearly_summary = filtered_data.groupby("Year made")["Type"].value_counts().unstack(fill_value=0) |
|
|
|
|
|
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) |
|
|
|
|
|
years = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022] |
|
brick_kilns_total = [117, 314, 376, 396, 408, 432, 433, 454, 461, 466, 470, 477, 478] |
|
brick_kilns_fcb = [52, 127, 159, 171, 178, 191, 192, 206, 208, 209, 209, 209, 209] |
|
brick_kilns_zigzag = [65, 187, 217, 225, 230, 241, 241, 248, 253, 257, 261, 268, 269] |
|
|
|
|
|
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='red'))) |
|
fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_fcb, mode='lines+markers', name='FCBTK', line=dict(color='blue'))) |
|
fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_zigzag, mode='lines+markers', name='Zigzag Brick Kilns', line=dict(color='green'))) |
|
|
|
|
|
fig_line.update_layout( |
|
title="Number of Brick Kilns Over Years in Lucknow", |
|
xaxis_title="Years", |
|
yaxis_title="Number of Brick Kilns", |
|
yaxis=dict(tickmode='linear', tick0=0, dtick=25,showgrid=False), |
|
width=900 |
|
) |
|
|
|
|
|
fig_line.add_vline(x=year_selected, line_dash="dash", line_color="black", annotation_text=f"Year {year_selected}") |
|
|
|
st.plotly_chart(fig_line) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|