Spaces:
Sleeping
Sleeping
File size: 3,890 Bytes
82b448d 37a8d71 82b448d 37a8d71 82b448d 37a8d71 82b448d 37a8d71 82b448d 37a8d71 82b448d 37a8d71 82b448d 37a8d71 82b448d 37a8d71 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
import streamlit as st
import pandas as pd
import numpy as np
import datetime
import time
# --- Simulate Data ---
def simulate_data(n=10, faults=True):
today = datetime.date.today()
poles = [f"Pole_{i+1:03}" for i in range(n)]
data = []
for pole in poles:
solar = round(np.random.uniform(3.0, 7.5), 2)
wind = round(np.random.uniform(0.5, 2.0), 2)
required = round(np.random.uniform(1.0, 1.5), 2)
total = solar + wind
cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
tilt = round(np.random.uniform(0, 12), 1)
vib = round(np.random.uniform(0.1, 2.5), 2)
sufficient = "Yes" if total >= required else "No"
anomaly = []
if faults:
if solar < 4.0:
anomaly.append("Low Solar Output")
if wind < 0.7:
anomaly.append("Low Wind Output")
if tilt > 10:
anomaly.append("Pole Tilt Risk")
if vib > 2.0:
anomaly.append("Vibration Alert")
if cam == "Offline":
anomaly.append("Camera Offline")
if sufficient == "No":
anomaly.append("Power Insufficient")
alert = "Green"
if len(anomaly) == 1:
alert = "Yellow"
elif len(anomaly) > 1:
alert = "Red"
data.append({
"Pole ID": pole,
"Date": today,
"Solar Gen (kWh)": solar,
"Wind Gen (kWh)": wind,
"Power Required (kWh)": required,
"Power Sufficient": sufficient,
"Camera Status": cam,
"Tilt (Β°)": tilt,
"Vibration (g)": vib,
"Anomalies": "; ".join(anomaly) if anomaly else "None",
"Alert Level": alert
})
return pd.DataFrame(data)
# --- Filter Data ---
def apply_filters(df, alert_filter, cam_filter):
filtered_df = df[df["Alert Level"].isin(alert_filter)]
if cam_filter != "All":
filtered_df = filtered_df[filtered_df["Camera Status"] == cam_filter]
return filtered_df
# --- Dashboard ---
def display_dashboard(df):
st.subheader("π System Summary")
col1, col2, col3 = st.columns(3)
col1.metric("Total Poles", df.shape[0])
col2.metric("π¨ Red Alerts", df[df['Alert Level'] == "Red"].shape[0])
col3.metric("β‘ Power Issues", df[df['Power Sufficient'] == "No"].shape[0])
def display_charts(df):
st.subheader("βοΈ Energy Generation Trends")
st.bar_chart(df.set_index("Pole ID")[["Solar Gen (kWh)", "Wind Gen (kWh)"]])
st.subheader("π Tilt vs Vibration")
st.scatter_chart(df.rename(columns={"Tilt (Β°)": "Tilt", "Vibration (g)": "Vibration"}).set_index("Pole ID")[["Tilt", "Vibration"]])
# --- Streamlit App ---
st.set_page_config(page_title="Vedavathi Smart Pole Monitoring", layout="wide")
st.title("π‘ Vedavathi Smart Pole Monitoring - Dynamic Stream")
# Sidebar Controls
st.sidebar.header("π οΈ Simulation Settings")
num_poles = st.sidebar.slider("Number of Poles", 5, 50, 10)
simulate_faults = st.sidebar.checkbox("Simulate Random Faults", value=True)
refresh_rate = st.sidebar.slider("Refresh Every (seconds)", 5, 60, 10)
st.sidebar.header("π Filter Data")
alert_filter = st.sidebar.multiselect("Alert Level", ["Green", "Yellow", "Red"], default=["Green", "Yellow", "Red"])
cam_filter = st.sidebar.selectbox("Camera Status", ["All", "Online", "Offline"], index=0)
# Placeholder for Live Data
placeholder = st.empty()
while True:
df = simulate_data(num_poles, simulate_faults)
filtered_df = apply_filters(df, alert_filter, cam_filter)
with placeholder.container():
display_dashboard(df)
st.subheader("π Pole Monitoring Table")
st.dataframe(filtered_df, use_container_width=True)
display_charts(df)
time.sleep(refresh_rate)
|