DSatishchandra commited on
Commit
ffac544
·
verified ·
1 Parent(s): a5b89b6

Create visuals.py

Browse files
Files changed (1) hide show
  1. modules/visuals.py +45 -0
modules/visuals.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import plotly.express as px
3
+ import pandas as pd
4
+
5
+ def display_dashboard(df):
6
+ st.subheader("📊 System Summary")
7
+ col1, col2, col3 = st.columns(3)
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.set_index("PoleID")[["SolarGen(kWh)", "WindGen(kWh)"]])
15
+ st.subheader("📉 Tilt vs Vibration")
16
+ st.scatter_chart(df.rename(columns={"Tilt(°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
17
+
18
+ def display_heatmap(df):
19
+ # Map AlertLevel to numeric values for heatmap intensity
20
+ alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
21
+ df["AlertValue"] = df["AlertLevel"].map(alert_map)
22
+
23
+ # Create a pivot table for heatmap (single row for all poles)
24
+ pivot_df = df[["PoleID", "AlertValue"]].set_index("PoleID").T
25
+
26
+ # Create heatmap using Plotly
27
+ fig = px.imshow(
28
+ pivot_df,
29
+ color_continuous_scale=["green", "yellow", "red"],
30
+ zmin=0,
31
+ zmax=2,
32
+ labels=dict(color="Alert Level"),
33
+ title="Pole Alert Heatmap",
34
+ height=300
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"]
43
+ )
44
+ )
45
+ st.plotly_chart(fig, use_container_width=True)