Prasanna1622 commited on
Commit
77bf633
Β·
verified Β·
1 Parent(s): b589dd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -79
app.py CHANGED
@@ -1,53 +1,50 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
- import plotly.graph_objects as go
5
  from salesforce_integration import fetch_poles
 
6
 
7
  # Title
8
  st.title("πŸ“‘ VIEP Smart Poles Dashboard")
9
 
10
- # Fetch data
11
  df = fetch_poles()
12
 
13
- # Sidebar Filters
14
  st.sidebar.header("πŸ“ Filter Data")
15
 
16
- # Dynamic values from Salesforce data
17
- alert_levels = df["Alert_Level__c"].dropna().unique().tolist()
18
- sites = df["Site__c"].dropna().unique().tolist()
19
- camera_statuses = df["Camera_Status__c"].dropna().unique().tolist()
20
 
21
- selected_alert_levels = st.sidebar.multiselect("Alert Level", alert_levels, default=alert_levels)
22
- selected_camera_status = st.sidebar.selectbox("Camera Status", ["All"] + camera_statuses)
 
 
23
 
24
- # Initial filtering by alert level and camera status
25
- filtered_df = df[
26
- (df["Alert_Level__c"].isin(selected_alert_levels))
27
- ]
 
 
28
 
29
  if selected_camera_status != "All":
30
  filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
31
 
32
- # Site filter logic (place here)
33
- site_options = ["All"] + df["Site__c"].dropna().unique().tolist()
34
- selected_site = st.sidebar.selectbox("Site", site_options, index=0)
35
  if selected_site != "All":
36
  filtered_df = filtered_df[filtered_df["Site__c"] == selected_site]
37
 
38
- # Site filter logic (place here)
39
- if selected_site != "All":
40
- filtered_df = filtered_df[filtered_df["Site__c"] == selected_site]
41
-
42
-
43
- # --- System Summary ---
44
- st.subheader("πŸ“Š System Summary")
45
 
46
- col1, col2, col3 = st.columns(3)
47
-
48
- col1.metric("Total Poles", len(filtered_df))
49
- col2.metric("Red Alerts", len(filtered_df[filtered_df["Alert_Level__c"] == "Red"]))
50
- col3.metric("Offline Cameras", len(filtered_df[filtered_df["Camera_Status__c"] == "Offline"]))
51
 
52
  # --- Pole Table ---
53
  st.subheader("πŸ“‹ Pole Table")
@@ -55,54 +52,86 @@ st.dataframe(filtered_df, use_container_width=True)
55
 
56
  # --- Energy Generation Chart ---
57
  st.subheader("βš™ Energy Generation (Solar vs Wind)")
58
- if not filtered_df.empty:
59
- energy_chart = px.bar(
60
- filtered_df,
61
- x="Name",
62
- y=["Solar_Generation__c", "Wind_Generation__c"],
63
- barmode="group",
64
- title="Solar vs Wind Energy Generation"
65
- )
66
- st.plotly_chart(energy_chart, use_container_width=True)
67
- else:
68
- st.info("No data available for the selected filters.")
69
-
70
- # --- Alert Level Breakdown ---
71
- st.subheader("🚨 Alert Level Breakdown")
72
- if not filtered_df.empty:
73
- alert_counts = filtered_df["Alert_Level__c"].value_counts().reset_index()
74
- alert_counts.columns = ["Alert Level", "Count"]
75
- alert_pie = px.pie(alert_counts, values="Count", names="Alert Level", title="Alert Distribution")
76
- st.plotly_chart(alert_pie, use_container_width=True)
77
- else:
78
- st.info("No alerts to display.")
79
-
80
- # 5. Tilt vs Vibration Chart
81
- st.subheader("πŸ“‰ Tilt vs Vibration")
82
-
83
- # Extract Tilt and Vibration from RFID_Tag__c
84
- filtered_df["Tilt"] = filtered_df["RFID_Tag__c"].str.extract(r'Tilt:(\d+\.?\d*)').astype(float)
85
- filtered_df["Vibration"] = filtered_df["RFID_Tag__c"].str.extract(r'Vib:(\d+\.?\d*)').astype(float)
86
-
87
- # Drop rows with no tilt or vibration data
88
- tilt_vib_df = filtered_df.dropna(subset=["Tilt", "Vibration"])
89
-
90
- if not tilt_vib_df.empty:
91
- fig_tilt_vib = go.Figure()
92
- fig_tilt_vib.add_trace(go.Scatter(
93
- x=tilt_vib_df["Name"],
94
- y=tilt_vib_df["Tilt"],
95
- mode='lines+markers',
96
- name='Tilt'
97
- ))
98
- fig_tilt_vib.add_trace(go.Scatter(
99
- x=tilt_vib_df["Name"],
100
- y=tilt_vib_df["Vibration"],
101
- mode='lines+markers',
102
- name='Vibration'
103
- ))
104
- fig_tilt_vib.update_layout(title="Tilt vs Vibration by Pole", xaxis_title="Pole Name", yaxis_title="Value")
105
- st.plotly_chart(fig_tilt_vib, use_container_width=True)
106
- else:
107
- st.info("No Tilt or Vibration data available.")
108
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
+ import pydeck as pdk
5
  from salesforce_integration import fetch_poles
6
+ from modules.visuals import display_dashboard, display_charts
7
 
8
  # Title
9
  st.title("πŸ“‘ VIEP Smart Poles Dashboard")
10
 
11
+ # Fetch the raw data from Salesforce
12
  df = fetch_poles()
13
 
14
+ # --- Sidebar Filters ---
15
  st.sidebar.header("πŸ“ Filter Data")
16
 
17
+ # Alert Level Filter
18
+ selected_alert_levels = st.sidebar.multiselect(
19
+ "Alert Level", ["Red", "Yellow", "Green"], default=["Red", "Yellow", "Green"]
20
+ )
21
 
22
+ # Camera Status Filter
23
+ selected_camera_status = st.sidebar.selectbox(
24
+ "Camera Status", ["All", "Online", "Offline"]
25
+ )
26
 
27
+ # Site Filter with "All" option
28
+ site_options = ["All"] + df["Site__c"].dropna().unique().tolist()
29
+ selected_site = st.sidebar.selectbox("Site", site_options, index=0)
30
+
31
+ # --- Filtering Logic ---
32
+ filtered_df = df[df["Alert_Level__c"].isin(selected_alert_levels)]
33
 
34
  if selected_camera_status != "All":
35
  filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
36
 
 
 
 
37
  if selected_site != "All":
38
  filtered_df = filtered_df[filtered_df["Site__c"] == selected_site]
39
 
40
+ # --- Count Faults Based on Alert Level ---
41
+ # Assuming default 0 fault count or based on Alert Level:
42
+ filtered_df["Fault_Count__c"] = filtered_df["Alert_Level__c"].apply(
43
+ lambda x: 3 if x == "Red" else (2 if x == "Yellow" else 1)
44
+ )
 
 
45
 
46
+ # --- Display System Summary ---
47
+ display_dashboard(filtered_df)
 
 
 
48
 
49
  # --- Pole Table ---
50
  st.subheader("πŸ“‹ Pole Table")
 
52
 
53
  # --- Energy Generation Chart ---
54
  st.subheader("βš™ Energy Generation (Solar vs Wind)")
55
+ st.plotly_chart(px.bar(
56
+ filtered_df,
57
+ x="Name",
58
+ y=["Solar_Generation__c", "Wind_Generation__c"],
59
+ barmode="group"
60
+ ))
61
+
62
+ # --- Tilt vs Vibration Chart ---
63
+ st.subheader("🧭 Tilt vs Vibration Comparison")
64
+
65
+ fig_tilt_vibration = px.line(
66
+ filtered_df,
67
+ x="Name",
68
+ y=["Tilt__c", "Vibration__c"],
69
+ markers=True,
70
+ title="Tilt vs Vibration per Pole"
71
+ )
72
+ st.plotly_chart(fig_tilt_vibration)
73
+
74
+ # --- Alert Level Breakdown Chart ---
75
+ display_charts(filtered_df)
76
+
77
+ # --- Heatmap Section ---
78
+ st.subheader("🌑 Pole Fault Heatmap")
79
+
80
+ # Map Color based on Faults
81
+ def get_fault_level(fault_count):
82
+ if fault_count <= 1:
83
+ return "Green"
84
+ elif 2 <= fault_count <= 3:
85
+ return "Yellow"
86
+ else:
87
+ return "Red"
88
+
89
+ filtered_df["Fault_Level"] = filtered_df["Fault_Count__c"].apply(get_fault_level)
90
+
91
+ color_map = {
92
+ "Green": [0, 255, 0],
93
+ "Yellow": [255, 255, 0],
94
+ "Red": [255, 0, 0]
95
+ }
96
+ filtered_df["color"] = filtered_df["Fault_Level"].map(color_map)
97
+
98
+ # Pydeck Map
99
+ layer = pdk.Layer(
100
+ "ScatterplotLayer",
101
+ data=filtered_df,
102
+ get_position='[Longitude__c, Latitude__c]',
103
+ get_color="color",
104
+ get_radius=80,
105
+ pickable=True,
106
+ auto_highlight=True
107
+ )
108
+
109
+ view_state = pdk.ViewState(
110
+ latitude=filtered_df["Latitude__c"].mean(),
111
+ longitude=filtered_df["Longitude__c"].mean(),
112
+ zoom=10,
113
+ pitch=40
114
+ )
115
+
116
+ tooltip = {
117
+ "html": """
118
+ <b>Pole Name:</b> {Name}<br/>
119
+ <b>Site:</b> {Site__c}<br/>
120
+ <b>Fault Count:</b> {Fault_Count__c}<br/>
121
+ <b>Alert Level:</b> {Alert_Level__c}<br/>
122
+ <b>RFID Tag:</b> {RFID_Tag__c}<br/>
123
+ <b>Tilt:</b> {Tilt__c}<br/>
124
+ <b>Vibration:</b> {Vibration__c}
125
+ """,
126
+ "style": {
127
+ "backgroundColor": "steelblue",
128
+ "color": "white"
129
+ }
130
+ }
131
+
132
+ st.pydeck_chart(pdk.Deck(
133
+ map_style="mapbox://styles/mapbox/dark-v10",
134
+ initial_view_state=view_state,
135
+ layers=[layer],
136
+ tooltip=tooltip
137
+ ))