DSatishchandra's picture
Create visuals.py
5d0388c verified
raw
history blame contribute delete
1.73 kB
import streamlit as st
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import time
# Display the dashboard with metrics and visualizations
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])
# Heatmap with Faults Visualization
st.subheader("πŸ“ˆ Pole Signal Heatmap with Fault Zones")
# Create random data for the heatmap (replace with your simulation data)
data = np.random.rand(10, 10)
fault_x, fault_y = np.random.randint(0, 10), np.random.randint(0, 10)
# Show initial heatmap
fig, ax = plt.subplots(figsize=(8, 6))
sns.heatmap(data, annot=True, cmap="coolwarm", ax=ax)
# Show a red dot if there's a fault
ax.plot(fault_y, fault_x, 'ro', markersize=10) # Red dot for fault location
st.pyplot(fig)
# Function to simulate blinking red dot and alert
def display_fault_alert(fault_x, fault_y):
st.error(f"Fault detected at Zone ({fault_x}, {fault_y}). Red alert triggered!")
# Simulate blinking red dot effect
for _ in range(5):
fig, ax = plt.subplots(figsize=(8, 6))
sns.heatmap(np.random.rand(10, 10), annot=True, cmap="coolwarm", ax=ax) # Draw heatmap
# Plot blinking red dot at fault location
ax.plot(fault_y, fault_x, 'ro', markersize=10)
# Display updated plot
st.pyplot(fig)
time.sleep(0.5) # Wait for 0.5 seconds to simulate blinking
ax.clear() # Clear previous plot