Prasanna1622 commited on
Commit
db779a2
Β·
verified Β·
1 Parent(s): 87fefa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -48
app.py CHANGED
@@ -1,69 +1,94 @@
 
1
  import streamlit as st
2
- import plotly.express as px
3
  from salesforce_integration import fetch_poles
 
 
 
4
 
5
- st.set_page_config(layout="wide")
6
  st.title("πŸ“‘ VIEP Smart Poles Dashboard")
7
 
8
- # βœ… Fetch raw data
9
- try:
10
- df = fetch_poles()
11
- except Exception as e:
12
- st.error(f"⚠️ Error connecting to Salesforce:\n\n{e}")
13
- st.stop()
14
 
15
- # βœ… Sidebar Filters
 
 
 
 
16
  st.sidebar.header("πŸ“ Filter Data")
17
 
18
- selected_alerts = st.sidebar.multiselect("Alert Level", ["Red", "Yellow", "Green"], default=["Red", "Yellow", "Green"])
19
- selected_sites = st.sidebar.multiselect("Site", df["Site__c"].unique().tolist(), default=df["Site__c"].unique().tolist())
20
- selected_camera_status = st.sidebar.selectbox("Camera Status", ["All", "Online", "Offline"])
 
 
 
 
 
 
 
 
 
21
 
22
- # βœ… Apply filters
23
  filtered_df = df[
24
- (df["Alert_Level__c"].isin(selected_alerts)) &
25
  (df["Site__c"].isin(selected_sites))
26
  ]
 
27
  if selected_camera_status != "All":
28
  filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
29
 
30
- # βœ… Dashboard Summary
31
- st.subheader("πŸ“Š System Summary")
32
- col1, col2, col3, col4 = st.columns(4)
33
- col1.metric("Total Poles", filtered_df.shape[0])
34
- col2.metric("Red Alerts", filtered_df[filtered_df["Alert_Level__c"] == "Red"].shape[0])
35
- col3.metric("Power Issues", filtered_df[filtered_df["Power_Sufficient__c"] == "No"].shape[0])
36
- col4.metric("Offline Cameras", filtered_df[filtered_df["Camera_Status__c"] == "Offline"].shape[0])
37
 
38
- # βœ… Pole Table
39
  st.subheader("πŸ“‹ Pole Table")
40
  st.dataframe(filtered_df)
41
 
42
- # βœ… Energy Chart
43
- st.subheader("βš™ Energy Generation")
44
- fig1 = px.bar(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  filtered_df,
46
- x="Name",
47
- y=["Solar_Generation__c", "Wind_Generation__c"],
48
- barmode="group"
 
 
49
  )
50
- st.plotly_chart(fig1)
51
-
52
- # βœ… Camera Status
53
- st.subheader("πŸŽ₯ Camera Status Distribution")
54
- fig2 = px.pie(filtered_df, names="Camera_Status__c", hole=0.4)
55
- st.plotly_chart(fig2)
56
-
57
- # βœ… Tilt vs Vibration
58
- if "Tilt__c" in filtered_df.columns and "Vibration__c" in filtered_df.columns:
59
- st.subheader("πŸ“ˆ Tilt vs Vibration")
60
- fig3 = px.scatter(
61
- filtered_df,
62
- x="Tilt__c",
63
- y="Vibration__c",
64
- color="Alert_Level__c",
65
- hover_name="Name"
66
- )
67
- st.plotly_chart(fig3)
68
- else:
69
- st.warning("Tilt or Vibration data not available in records.")
 
1
+ # app.py
2
  import streamlit as st
 
3
  from salesforce_integration import fetch_poles
4
+ from modules.visuals import display_dashboard, display_charts
5
+ import plotly.express as px
6
+ import pandas as pd
7
 
8
+ # Title
9
  st.title("πŸ“‘ VIEP Smart Poles Dashboard")
10
 
11
+ # Get data
12
+ df = fetch_poles()
13
+
 
 
 
14
 
15
+
16
+ # Fetch the raw data from Salesforce
17
+ df = fetch_poles()
18
+
19
+ # Sidebar Filters (your code should go here!)
20
  st.sidebar.header("πŸ“ Filter Data")
21
 
22
+ selected_alert_levels = st.sidebar.multiselect(
23
+ "Alert Level", ["Red", "Yellow", "Green"], default=["Red", "Yellow", "Green"]
24
+ )
25
+
26
+ selected_sites = st.sidebar.multiselect(
27
+ "Site", ["Hyderabad", "Gadwal", "Kurnool", "Ballari"],
28
+ default=["Hyderabad", "Gadwal", "Kurnool", "Ballari"]
29
+ )
30
+
31
+ selected_camera_status = st.sidebar.selectbox(
32
+ "Camera Status", ["All", "Online", "Offline"]
33
+ )
34
 
35
+ # Apply filters to create filtered_df
36
  filtered_df = df[
37
+ (df["Alert_Level__c"].isin(selected_alert_levels)) &
38
  (df["Site__c"].isin(selected_sites))
39
  ]
40
+
41
  if selected_camera_status != "All":
42
  filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
43
 
44
+ # Now use filtered_df everywhere
45
+
46
+ # Show system summary
47
+ display_dashboard(filtered_df)
 
 
 
48
 
49
+ # Show pole table
50
  st.subheader("πŸ“‹ Pole Table")
51
  st.dataframe(filtered_df)
52
 
53
+ # Show charts
54
+ display_charts(filtered_df)
55
+
56
+ # Tilt vs Vibration Scatter Plot
57
+ st.subheader("πŸ“ˆ Tilt vs Vibration")
58
+ fig_tv = px.scatter(
59
+ filtered_df,
60
+ x="Tilt_Angle__c",
61
+ y="Vibration_Level__c",
62
+ color="Alert_Level__c",
63
+ hover_name="Name",
64
+ title="Tilt Angle vs Vibration Level"
65
+ )
66
+ st.plotly_chart(fig_tv)
67
+
68
+ # 1. System Summary (Show first)
69
+ display_dashboard(df)
70
+
71
+ # 2. Pole Table
72
+ st.subheader("πŸ“‹ Pole Table")
73
+ st.dataframe(df, use_container_width=True)
74
+
75
+ # 3. Charts
76
+ st.subheader("βš™ Energy Generation (Solar vs Wind)")
77
+ st.plotly_chart(px.bar(df, x="Name", y=["Solar_Generation__c", "Wind_Generation__c"], barmode="group"))
78
+
79
+ # 4. Charts (Energy + Alert Breakdown)
80
+ display_charts(df)
81
+
82
+ import plotly.express as df
83
+
84
+ st.subheader("πŸ“ˆ Tilt vs Vibration")
85
+
86
+ fig_tv = px.scatter(
87
  filtered_df,
88
+ x="Tilt_Angle__c", # make sure this is your column name
89
+ y="Vibration_Level__c", # make sure this is your column name
90
+ color="Alert_Level__c",
91
+ hover_name="Name",
92
+ title="Tilt Angle vs Vibration Level"
93
  )
94
+ st.plotly_chart(fig_tv)