|
|
|
|
|
|
|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
st.set_page_config(page_title="Water System Analysis", layout="centered") |
|
|
st.title("Water Network Leak, Surge, and Gas Flow Analyzer") |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Upload Excel or CSV File", type=["xlsx", "csv"]) |
|
|
|
|
|
if uploaded_file: |
|
|
try: |
|
|
|
|
|
if uploaded_file.name.endswith('.xlsx'): |
|
|
df = pd.read_excel(uploaded_file) |
|
|
else: |
|
|
df = pd.read_csv(uploaded_file) |
|
|
st.success("Data loaded successfully!") |
|
|
except Exception as e: |
|
|
st.error(f"Error reading the file: {e}") |
|
|
st.stop() |
|
|
|
|
|
|
|
|
serial_col = None |
|
|
for col in df.columns: |
|
|
if col.strip().lower().startswith("serial"): |
|
|
serial_col = col |
|
|
break |
|
|
|
|
|
|
|
|
if serial_col: |
|
|
serial_list = df[serial_col].unique().tolist() |
|
|
selected_serial = st.selectbox(f"Select {serial_col}", serial_list) |
|
|
df_filtered = df[df[serial_col] == selected_serial] |
|
|
if df_filtered.empty: |
|
|
st.warning("No data found for the selected serial number.") |
|
|
st.stop() |
|
|
else: |
|
|
|
|
|
df_filtered = df |
|
|
selected_serial = None |
|
|
|
|
|
|
|
|
|
|
|
columns = [col for col in df_filtered.columns if col != serial_col] |
|
|
selected_column = st.selectbox("Select a parameter to analyze", columns) |
|
|
|
|
|
if selected_column: |
|
|
|
|
|
|
|
|
if len(df_filtered) == 1: |
|
|
value = df_filtered[selected_column].iloc[0] |
|
|
else: |
|
|
value = df_filtered[selected_column].tolist() |
|
|
rec = "" |
|
|
|
|
|
|
|
|
if "water pressure" in selected_column.lower(): |
|
|
|
|
|
if isinstance(value, list): |
|
|
mean_val = np.mean(value) |
|
|
else: |
|
|
mean_val = value |
|
|
|
|
|
if mean_val < 20: |
|
|
rec = ("π¨ **Alert:** The water pressure is significantly low. " |
|
|
"This suggests a strong likelihood of a leak or supply issue. " |
|
|
"Inspect the pipeline and valves immediately. ") |
|
|
elif mean_val < 40: |
|
|
rec = ("β οΈ The water pressure is on the lower side. " |
|
|
"There may be a leak or high demand. " |
|
|
"Monitor the system closely and check for any anomalies. ") |
|
|
elif mean_val > 80: |
|
|
rec = ("β οΈ The water pressure is very high. " |
|
|
"Ensure the pressure-regulating devices are functioning. " |
|
|
"High pressure can stress the pipes. ") |
|
|
else: |
|
|
rec = ("β
The water pressure is within normal range. " |
|
|
"No immediate issues detected for leaks based on pressure. ") |
|
|
|
|
|
|
|
|
elif "transient pressure" in selected_column.lower(): |
|
|
|
|
|
if isinstance(value, list): |
|
|
peak_val = np.max(value) |
|
|
else: |
|
|
peak_val = value |
|
|
if peak_val > 60: |
|
|
rec = ("π¨ **Alert:** Detected a high transient pressure (pressure surge). " |
|
|
"This could indicate water hammer or sudden valve closure. " |
|
|
"Check surge protection devices and ensure valves operate smoothly. ") |
|
|
else: |
|
|
rec = ("β
Transient pressure levels are within a safe range. " |
|
|
"No significant pressure surges detected. ") |
|
|
|
|
|
|
|
|
elif "gas flow" in selected_column.lower(): |
|
|
if isinstance(value, list): |
|
|
mean_flow = np.mean(value) |
|
|
else: |
|
|
mean_flow = value |
|
|
if mean_flow > 150: |
|
|
rec = ("β οΈ Gas flow rate is high. " |
|
|
"This could indicate heavy usage or a potential leak. " |
|
|
"Check the gas lines and usage patterns. ") |
|
|
elif mean_flow < 50: |
|
|
rec = ("β οΈ Gas flow rate is very low. " |
|
|
"Ensure that valves are open or that the demand is correct. " |
|
|
"No gas might indicate a supply issue. ") |
|
|
else: |
|
|
rec = ("β
Gas flow rate is within normal operating range. " |
|
|
"No obvious anomalies detected in gas flow. ") |
|
|
|
|
|
|
|
|
elif "network design" in selected_column.lower(): |
|
|
design = str(df_filtered[selected_column].iloc[0]).strip().lower() |
|
|
if "grid" in design: |
|
|
rec = ("β
A grid network provides redundancy and reliability. " |
|
|
"Ensure maintenance of all loops for continuous supply. ") |
|
|
elif "radial" in design: |
|
|
rec = ("β οΈ A radial network is simpler but has less redundancy. " |
|
|
"A failure in a main line may isolate downstream areas. " |
|
|
"Consider backup routes if possible. ") |
|
|
elif "ring" in design or "loop" in design: |
|
|
rec = ("β
A ring (loop) network allows for good circulation and redundancy. " |
|
|
"Keep valves balanced to maintain pressure. ") |
|
|
else: |
|
|
rec = ("β
The network design type is noted. " |
|
|
"Regular inspection ensures reliability. ") |
|
|
|
|
|
|
|
|
elif "population density" in selected_column.lower(): |
|
|
val = df_filtered[selected_column].iloc[0] |
|
|
if val > 1500: |
|
|
rec = ("β οΈ High population density indicates heavy demand on the water network. " |
|
|
"Ensure the infrastructure is scaled properly to serve the community. " |
|
|
"Consider capacity upgrades or demand management programs. ") |
|
|
elif val > 800: |
|
|
rec = ("β
Population density is moderate. " |
|
|
"Maintain regular monitoring to meet demand and plan for growth. ") |
|
|
else: |
|
|
rec = ("β
Low population density suggests light demand. " |
|
|
"Focus on efficient resource allocation and cost-effective maintenance. ") |
|
|
|
|
|
|
|
|
elif "water usage" in selected_column.lower(): |
|
|
val = df_filtered[selected_column].iloc[0] |
|
|
if val > 200: |
|
|
rec = ("β οΈ Very high per-capita water usage detected. " |
|
|
"Promote water conservation measures and check for leaks in consumption systems. ") |
|
|
elif val > 120: |
|
|
rec = ("β
Average water usage is within a moderate range. " |
|
|
"Continue to encourage efficient use of water. ") |
|
|
else: |
|
|
rec = ("β
Water usage per person is low. " |
|
|
"This is efficient, but ensure basic needs are met. ") |
|
|
|
|
|
|
|
|
elif "available water" in selected_column.lower(): |
|
|
val = df_filtered[selected_column].iloc[0] |
|
|
if val < 80: |
|
|
rec = ("β οΈ Limited available water resources. " |
|
|
"Implement conservation strategies and consider alternative sources. ") |
|
|
elif val > 150: |
|
|
rec = ("β
Ample water resources are available. " |
|
|
"Still practice sustainable usage to maintain supply levels. ") |
|
|
else: |
|
|
rec = ("β
Water resource levels are moderate. " |
|
|
"Monitor usage rates to avoid shortages. ") |
|
|
|
|
|
|
|
|
elif "pipe sizes" in selected_column.lower(): |
|
|
val = df_filtered[selected_column].iloc[0] |
|
|
if val < 30: |
|
|
rec = ("β οΈ Small pipe diameter detected. " |
|
|
"This may limit flow capacity. " |
|
|
"Check for potential bottlenecks in the network. ") |
|
|
elif val > 40: |
|
|
rec = ("β
Pipe size is large. " |
|
|
"Adequate flow capacity is available. " |
|
|
"Ensure regular inspections for longevity. ") |
|
|
else: |
|
|
rec = ("β
Standard pipe size. " |
|
|
"Flow capacity is adequate for normal operation. ") |
|
|
|
|
|
else: |
|
|
|
|
|
rec = ("β
No specific recommendations for the selected parameter. " |
|
|
"Data value is noted and appears within expected range. ") |
|
|
|
|
|
|
|
|
st.markdown(f"### Recommendations for **{selected_column}**") |
|
|
st.write(rec) |
|
|
|