kpi_dashboard / app.py
Shivraj8615's picture
Create app.py
d9c521a verified
import streamlit as st
import pandas as pd
def calculate_metrics(data):
data["CRF"] = round((data["Condensate Return Quantity"] / data["Steam Consumption Quantity"]) * 100, 2)
data["SSC"] = round(data["Steam Consumption Quantity"] / data["Production Quantity"], 2)
data["SWC"] = round(data["Steam Consumption Quantity"] / data["Production Quantity"], 2)
return data
def calculate_feed_water_temp(cond_temp, cond_qty, tank_size):
ambient_temp = 30
make_up = tank_size - cond_qty
feed_water_temp = round(((cond_qty * cond_temp) + (make_up * ambient_temp)) / tank_size, 2)
return feed_water_temp
def main():
st.title("Industrial Utility Dashboard")
if "report_data" not in st.session_state:
st.session_state.report_data = None
num_sections = st.number_input("Enter number of sections:", min_value=1, step=1)
section_data = []
for i in range(1, num_sections + 1):
st.subheader(f"Section {i}")
steam_consumption = round(st.number_input(f"Steam Consumption Quantity (Section {i})", min_value=0.0, step=0.1), 2)
condensate_return = round(st.number_input(f"Condensate Return Quantity (Section {i})", min_value=0.0, step=0.1), 2)
production_quantity = round(st.number_input(f"Production Quantity (Section {i})", min_value=0.0, step=0.1), 2)
water_consumption = round(st.number_input(f"Water Consumption Quantity (Section {i})", min_value=0.0, step=0.1), 2)
section_data.append([f"Section {i}", production_quantity, water_consumption, condensate_return, steam_consumption])
if st.button("Generate Report"):
columns = ["Section", "Production Quantity", "Water Consumption Quantity", "Condensate Return Quantity", "Steam Consumption Quantity"]
df = pd.DataFrame(section_data, columns=columns)
df = calculate_metrics(df)
total_row = df.sum(numeric_only=True).round(2)
total_row["Section"] = "Total"
total_df = pd.DataFrame([total_row])
total_df["CRF"] = round((total_df["Condensate Return Quantity"] / total_df["Steam Consumption Quantity"]) * 100, 2)
total_df["SSC"] = round(total_df["Steam Consumption Quantity"] / total_df["Production Quantity"], 2)
total_df["SWC"] = round(total_df["Steam Consumption Quantity"] / total_df["Production Quantity"], 2)
df = pd.concat([df, total_df], ignore_index=True)
st.session_state.report_data = df
if st.session_state.report_data is not None:
st.dataframe(st.session_state.report_data)
st.subheader("Calculate Feed Water Temperature")
cond_temp = st.number_input("Enter Condensate Returning Temperature:", min_value=0.0, step=0.1)
cond_qty = st.number_input("Enter Condensate Returning Quantity:", min_value=0.0, step=0.1)
tank_size = st.number_input("Enter Feed Water Tank Size:", min_value=0.0, step=0.1)
if st.button("Calculate Feed Water Temperature"):
result = calculate_feed_water_temp(cond_temp, cond_qty, tank_size)
st.success(f"Feed Water Temperature: {result:.2f} °C")
if __name__ == "__main__":
main()