dschandra's picture
Create visuals.py
1d4aabd verified
import streamlit as st
import plotly.express as px
import pandas as pd
def display_dashboard(df):
st.subheader("πŸ“Š System Summary")
col1, col2, col3, col4 = st.columns(4)
col1.metric("Total Poles", df.shape[0])
col2.metric("🚨 Red Alerts", df[df['AlertLevel'] == "Red"].shape[0])
col3.metric("⚑ Power Issues", df[df['PowerSufficient'] == "No"].shape[0])
col4.metric("πŸ“ Sites", len(df['Site'].unique()))
def display_charts(df):
st.subheader("βš™οΈ Energy Generation Trends")
st.bar_chart(df.groupby("Site")[["SolarGen(kWh)", "WindGen(kWh)"]].mean())
st.subheader("πŸ“‰ Tilt vs Vibration")
st.scatter_chart(df.rename(columns={"Tilt(Β°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
def display_heatmap(df):
st.subheader("🌑️ Alert Heatmap by Site")
# Map AlertLevel to numeric values for heatmap intensity
alert_map = {"Green": 1, "Yellow": 2, "Red": 3}
df["AlertValue"] = df["AlertLevel"].map(alert_map)
# Create heatmap using Plotly
fig = px.density_heatmap(
df,
x="XCoord",
y="YCoord",
z="AlertValue",
color_continuous_scale=["green", "yellow", "red"],
title="Alert Intensity Heatmap Across Sites",
labels={"XCoord": "Site Zone X", "YCoord": "Site Zone Y", "AlertValue": "Alert Intensity"},
nbinsx=20,
nbinsy=20
)
# Add site boundaries for zoning
site_boundaries = {
"Hyderabad": (0, 10),
"Ballari": (10, 20),
"Kurnool": (20, 30),
"Gadwal": (30, 40)
}
for site, (x_min, x_max) in site_boundaries.items():
fig.add_vline(x=x_min, line_dash="dash", line_color="white")
fig.add_annotation(x=(x_min + x_max) / 2, y=10, text=site, showarrow=False, font=dict(color="white"))
st.plotly_chart(fig, use_container_width=True)