Spaces:
Sleeping
Sleeping
Update modules/visuals.py
Browse files- modules/visuals.py +12 -7
modules/visuals.py
CHANGED
|
@@ -19,20 +19,25 @@ def display_charts(df):
|
|
| 19 |
def display_heatmap(df):
|
| 20 |
# Map AlertLevel to numeric values for heatmap intensity
|
| 21 |
alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
|
|
|
|
| 22 |
df["AlertValue"] = df["AlertLevel"].map(alert_map)
|
| 23 |
|
| 24 |
-
# Pivot table
|
| 25 |
pivot_df = df.pivot_table(index="Location", columns="PoleID", values="AlertValue", fill_value=0)
|
| 26 |
|
| 27 |
-
# Create hover text
|
| 28 |
-
|
| 29 |
-
hover_text = pivot_df.copy()
|
| 30 |
for loc in pivot_df.index:
|
| 31 |
for pole in pivot_df.columns:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 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(
|
|
|
|
| 19 |
def display_heatmap(df):
|
| 20 |
# Map AlertLevel to numeric values for heatmap intensity
|
| 21 |
alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
|
| 22 |
+
df = df.copy() # Avoid modifying the original DataFrame
|
| 23 |
df["AlertValue"] = df["AlertLevel"].map(alert_map)
|
| 24 |
|
| 25 |
+
# Pivot table for heatmap values (AlertValue)
|
| 26 |
pivot_df = df.pivot_table(index="Location", columns="PoleID", values="AlertValue", fill_value=0)
|
| 27 |
|
| 28 |
+
# Create hover text DataFrame
|
| 29 |
+
hover_data = df[["Location", "PoleID", "AlertLevel", "Anomalies"]].copy()
|
| 30 |
+
hover_text = pivot_df.copy().astype(str)
|
| 31 |
for loc in pivot_df.index:
|
| 32 |
for pole in pivot_df.columns:
|
| 33 |
+
# Find matching row in hover_data
|
| 34 |
+
match = hover_data[(hover_data["Location"] == loc) & (hover_data["PoleID"] == pole)]
|
| 35 |
+
if not match.empty:
|
| 36 |
+
alert = match["AlertLevel"].iloc[0]
|
| 37 |
+
anomalies = match["Anomalies"].iloc[0]
|
| 38 |
hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: {alert}<br>Anomalies: {anomalies}"
|
| 39 |
+
else:
|
| 40 |
+
hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: None<br>Anomalies: None"
|
| 41 |
|
| 42 |
# Create heatmap using Plotly
|
| 43 |
fig = px.imshow(
|