dschandra commited on
Commit
1b1a976
Β·
verified Β·
1 Parent(s): 21bfd3b

Update modules/visuals.py

Browse files
Files changed (1) hide show
  1. modules/visuals.py +22 -10
modules/visuals.py CHANGED
@@ -1,26 +1,31 @@
1
  import pandas as pd
 
 
 
2
 
 
3
  def display_dashboard(df: pd.DataFrame):
4
  st.subheader("πŸ“Š System Summary")
5
  col1, col2, col3, col4 = st.columns(4)
6
 
 
7
  col1.metric("Total Poles", df.shape[0])
8
  col2.metric("🚨 Red Alerts", df[df["Alert_Level__c"] == "Red"].shape[0])
9
  col3.metric("⚑ Power Issues", df[df["Power_Sufficient__c"] == "No"].shape[0])
10
  col4.metric("πŸ“· Offline Cameras", df[df["Camera_Status__c"] == "Offline"].shape[0])
11
 
12
- import streamlit as st
13
- import plotly.express as px
14
-
15
-
16
  def display_charts(df: pd.DataFrame):
 
17
  fig_energy = px.bar(
18
  df,
19
  x="Name",
20
  y=["Solar_Generation__c", "Wind_Generation__c"],
 
21
  )
22
-
23
 
 
24
  st.subheader("🚨 Alert Level Breakdown")
25
  fig_alerts = px.histogram(
26
  df,
@@ -29,7 +34,6 @@ def display_charts(df: pd.DataFrame):
29
  )
30
  st.plotly_chart(fig_alerts)
31
 
32
- import pydeck as pdk
33
  # Function to generate heatmap for a given site
34
  def generate_heatmap_for_site(site_name, df):
35
  site_df = df[df['Site__c'] == site_name]
@@ -47,6 +51,9 @@ def generate_heatmap_for_site(site_name, df):
47
  # Create a color column based on Alert_Level__c
48
  site_df["color"] = site_df["Alert_Level__c"].map(color_map)
49
 
 
 
 
50
  # Create a Pydeck map for the site
51
  layer = pdk.Layer(
52
  "ScatterplotLayer",
@@ -58,13 +65,18 @@ def generate_heatmap_for_site(site_name, df):
58
  auto_highlight=True
59
  )
60
 
 
 
 
 
61
  view_state = pdk.ViewState(
62
- latitude=site_df["Location_Latitude__c"].mean(),
63
- longitude=site_df["Location_Longitude__c"].mean(),
64
  zoom=10,
65
  pitch=40
66
  )
67
 
 
68
  tooltip = {
69
  "html": """
70
  <b>Pole Name:</b> {Name}<br>
@@ -80,10 +92,10 @@ def generate_heatmap_for_site(site_name, df):
80
  }
81
  }
82
 
83
- # Return the heatmap
84
  return pdk.Deck(
85
  map_style="mapbox://styles/mapbox/dark-v10",
86
  initial_view_state=view_state,
87
  layers=[layer],
88
  tooltip=tooltip
89
- )
 
1
  import pandas as pd
2
+ import streamlit as st
3
+ import plotly.express as px
4
+ import pydeck as pdk
5
 
6
+ # Function to display system summary metrics
7
  def display_dashboard(df: pd.DataFrame):
8
  st.subheader("πŸ“Š System Summary")
9
  col1, col2, col3, col4 = st.columns(4)
10
 
11
+ # Metrics for Total Poles, Red Alerts, Power Issues, Offline Cameras
12
  col1.metric("Total Poles", df.shape[0])
13
  col2.metric("🚨 Red Alerts", df[df["Alert_Level__c"] == "Red"].shape[0])
14
  col3.metric("⚑ Power Issues", df[df["Power_Sufficient__c"] == "No"].shape[0])
15
  col4.metric("πŸ“· Offline Cameras", df[df["Camera_Status__c"] == "Offline"].shape[0])
16
 
17
+ # Function to display charts related to energy generation and alert levels
 
 
 
18
  def display_charts(df: pd.DataFrame):
19
+ # Energy Generation Bar Chart
20
  fig_energy = px.bar(
21
  df,
22
  x="Name",
23
  y=["Solar_Generation__c", "Wind_Generation__c"],
24
+ title="Energy Generation (Solar vs Wind)"
25
  )
26
+ st.plotly_chart(fig_energy)
27
 
28
+ # Alert Level Breakdown Histogram
29
  st.subheader("🚨 Alert Level Breakdown")
30
  fig_alerts = px.histogram(
31
  df,
 
34
  )
35
  st.plotly_chart(fig_alerts)
36
 
 
37
  # Function to generate heatmap for a given site
38
  def generate_heatmap_for_site(site_name, df):
39
  site_df = df[df['Site__c'] == site_name]
 
51
  # Create a color column based on Alert_Level__c
52
  site_df["color"] = site_df["Alert_Level__c"].map(color_map)
53
 
54
+ # Drop rows with missing Longitude or Latitude to avoid errors in the map
55
+ site_df = site_df.dropna(subset=["Longitude__c", "Latitude__c"])
56
+
57
  # Create a Pydeck map for the site
58
  layer = pdk.Layer(
59
  "ScatterplotLayer",
 
65
  auto_highlight=True
66
  )
67
 
68
+ # Set the view state to center the map on the site
69
+ latitude = site_df["Latitude__c"].mean() if not site_df["Latitude__c"].isnull().all() else 0
70
+ longitude = site_df["Longitude__c"].mean() if not site_df["Longitude__c"].isnull().all() else 0
71
+
72
  view_state = pdk.ViewState(
73
+ latitude=latitude,
74
+ longitude=longitude,
75
  zoom=10,
76
  pitch=40
77
  )
78
 
79
+ # Tooltip for when you hover over a pole
80
  tooltip = {
81
  "html": """
82
  <b>Pole Name:</b> {Name}<br>
 
92
  }
93
  }
94
 
95
+ # Return the heatmap as a Pydeck map
96
  return pdk.Deck(
97
  map_style="mapbox://styles/mapbox/dark-v10",
98
  initial_view_state=view_state,
99
  layers=[layer],
100
  tooltip=tooltip
101
+ )