Spaces:
Sleeping
Sleeping
File size: 2,545 Bytes
ffac544 90268db ffac544 90268db ffac544 90268db ffac544 cd8f20d ffac544 cd8f20d 90268db cd8f20d 90268db cd8f20d 90268db cd8f20d ffac544 90268db ffac544 90268db ffac544 90268db ffac544 |
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 |
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("π Locations", len(df['Location'].unique()))
def display_charts(df):
st.subheader("βοΈ Energy Generation Trends")
st.bar_chart(df.groupby("Location")[["SolarGen(kWh)", "WindGen(kWh)"]].sum())
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):
# Map AlertLevel to numeric values for heatmap intensity
alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
df = df.copy() # Avoid modifying the original DataFrame
df["AlertValue"] = df["AlertLevel"].map(alert_map)
# Pivot table for heatmap values (AlertValue)
pivot_df = df.pivot_table(index="Location", columns="PoleID", values="AlertValue", fill_value=0)
# Create hover text DataFrame
hover_data = df[["Location", "PoleID", "AlertLevel", "Anomalies"]].copy()
hover_text = pivot_df.copy().astype(str)
for loc in pivot_df.index:
for pole in pivot_df.columns:
# Find matching row in hover_data
match = hover_data[(hover_data["Location"] == loc) & (hover_data["PoleID"] == pole)]
if not match.empty:
alert = match["AlertLevel"].iloc[0]
anomalies = match["Anomalies"].iloc[0]
hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: {alert}<br>Anomalies: {anomalies}"
else:
hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: None<br>Anomalies: None"
# Create heatmap using Plotly
fig = px.imshow(
pivot_df,
color_continuous_scale=["green", "yellow", "red"],
zmin=0,
zmax=2,
title="Pole Alert Heatmap by Location",
text_auto=False,
height=500
)
fig.update_traces(hovertemplate="%{customdata}<br>%{x}<br>%{y}", customdata=hover_text)
fig.update_layout(
xaxis_title="Pole ID",
yaxis_title="Location",
coloraxis_colorbar=dict(
tickvals=[0, 1, 2],
ticktext=["Green", "Yellow", "Red"]
)
)
st.plotly_chart(fig, use_container_width=True) |