Spaces:
Sleeping
Sleeping
Update modules/visuals.py
Browse files- modules/visuals.py +20 -9
modules/visuals.py
CHANGED
|
@@ -4,14 +4,15 @@ import pandas as pd
|
|
| 4 |
|
| 5 |
def display_dashboard(df):
|
| 6 |
st.subheader("π System Summary")
|
| 7 |
-
col1, col2, col3 = st.columns(
|
| 8 |
col1.metric("Total Poles", df.shape[0])
|
| 9 |
col2.metric("π¨ Red Alerts", df[df['AlertLevel'] == "Red"].shape[0])
|
| 10 |
col3.metric("β‘ Power Issues", df[df['PowerSufficient'] == "No"].shape[0])
|
|
|
|
| 11 |
|
| 12 |
def display_charts(df):
|
| 13 |
st.subheader("βοΈ Energy Generation Trends")
|
| 14 |
-
st.bar_chart(df.
|
| 15 |
st.subheader("π Tilt vs Vibration")
|
| 16 |
st.scatter_chart(df.rename(columns={"Tilt(Β°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
|
| 17 |
|
|
@@ -20,8 +21,18 @@ def display_heatmap(df):
|
|
| 20 |
alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
|
| 21 |
df["AlertValue"] = df["AlertLevel"].map(alert_map)
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
pivot_df = df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Create heatmap using Plotly
|
| 27 |
fig = px.imshow(
|
|
@@ -29,14 +40,14 @@ def display_heatmap(df):
|
|
| 29 |
color_continuous_scale=["green", "yellow", "red"],
|
| 30 |
zmin=0,
|
| 31 |
zmax=2,
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
height=
|
| 35 |
)
|
|
|
|
| 36 |
fig.update_layout(
|
| 37 |
xaxis_title="Pole ID",
|
| 38 |
-
yaxis_title="",
|
| 39 |
-
yaxis_showticklabels=False,
|
| 40 |
coloraxis_colorbar=dict(
|
| 41 |
tickvals=[0, 1, 2],
|
| 42 |
ticktext=["Green", "Yellow", "Red"]
|
|
|
|
| 4 |
|
| 5 |
def display_dashboard(df):
|
| 6 |
st.subheader("π System Summary")
|
| 7 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 8 |
col1.metric("Total Poles", df.shape[0])
|
| 9 |
col2.metric("π¨ Red Alerts", df[df['AlertLevel'] == "Red"].shape[0])
|
| 10 |
col3.metric("β‘ Power Issues", df[df['PowerSufficient'] == "No"].shape[0])
|
| 11 |
+
col4.metric("π Locations", len(df['Location'].unique()))
|
| 12 |
|
| 13 |
def display_charts(df):
|
| 14 |
st.subheader("βοΈ Energy Generation Trends")
|
| 15 |
+
st.bar_chart(df.groupby("Location")[["SolarGen(kWh)", "WindGen(kWh)"]].sum())
|
| 16 |
st.subheader("π Tilt vs Vibration")
|
| 17 |
st.scatter_chart(df.rename(columns={"Tilt(Β°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
|
| 18 |
|
|
|
|
| 21 |
alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
|
| 22 |
df["AlertValue"] = df["AlertLevel"].map(alert_map)
|
| 23 |
|
| 24 |
+
# Pivot table: Locations as rows, Poles as columns
|
| 25 |
+
pivot_df = df.pivot_table(index="Location", columns="PoleID", values="AlertValue", fill_value=0)
|
| 26 |
+
|
| 27 |
+
# Create hover text with PoleID, AlertLevel, and Anomalies
|
| 28 |
+
hover_df = df.pivot_table(index="Location", columns="PoleID", values=["PoleID", "AlertLevel", "Anomalies"], aggfunc="first")
|
| 29 |
+
hover_text = pivot_df.copy()
|
| 30 |
+
for loc in pivot_df.index:
|
| 31 |
+
for pole in pivot_df.columns:
|
| 32 |
+
if pole in hover_df.loc[loc, "PoleID"].columns:
|
| 33 |
+
alert = hover_df.loc[loc, ("AlertLevel", pole)] if pd.notna(hover_df.loc[loc, ("AlertLevel", pole)]) else "None"
|
| 34 |
+
anomalies = hover_df.loc[loc, ("Anomalies", pole)] if pd.notna(hover_df.loc[loc, ("Anomalies", pole)]) else "None"
|
| 35 |
+
hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: {alert}<br>Anomalies: {anomalies}"
|
| 36 |
|
| 37 |
# Create heatmap using Plotly
|
| 38 |
fig = px.imshow(
|
|
|
|
| 40 |
color_continuous_scale=["green", "yellow", "red"],
|
| 41 |
zmin=0,
|
| 42 |
zmax=2,
|
| 43 |
+
title="Pole Alert Heatmap by Location",
|
| 44 |
+
text_auto=False,
|
| 45 |
+
height=500
|
| 46 |
)
|
| 47 |
+
fig.update_traces(hovertemplate="%{customdata}<br>%{x}<br>%{y}", customdata=hover_text)
|
| 48 |
fig.update_layout(
|
| 49 |
xaxis_title="Pole ID",
|
| 50 |
+
yaxis_title="Location",
|
|
|
|
| 51 |
coloraxis_colorbar=dict(
|
| 52 |
tickvals=[0, 1, 2],
|
| 53 |
ticktext=["Green", "Yellow", "Red"]
|