Spaces:
Sleeping
Sleeping
Update modules/visuals.py
Browse files- modules/visuals.py +68 -17
modules/visuals.py
CHANGED
@@ -1,8 +1,12 @@
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
def display_dashboard(df: pd.DataFrame):
|
6 |
st.subheader("📊 System Summary")
|
7 |
col1, col2, col3, col4 = st.columns(4)
|
8 |
|
@@ -11,22 +15,69 @@ def display_dashboard(df: pd.DataFrame):
|
|
11 |
col3.metric("⚡ Power Issues", df[df["Power_Sufficient__c"] == "No"].shape[0])
|
12 |
col4.metric("📷 Offline Cameras", df[df["Camera_Status__c"] == "Offline"].shape[0])
|
13 |
|
14 |
-
import streamlit as st
|
15 |
-
import plotly.express as px
|
16 |
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
-
st.plotly_chart(fig_alerts)
|
|
|
1 |
+
import pydeck as pdk
|
2 |
+
import plotly.express as px
|
3 |
+
import streamlit as st
|
4 |
|
5 |
+
# Function to generate the dashboard summary
|
6 |
+
def display_dashboard(filtered_df):
|
7 |
+
st.title("VIEP Smart Poles Dashboard")
|
8 |
|
9 |
+
ef display_dashboard(df: pd.DataFrame):
|
|
|
|
|
10 |
st.subheader("📊 System Summary")
|
11 |
col1, col2, col3, col4 = st.columns(4)
|
12 |
|
|
|
15 |
col3.metric("⚡ Power Issues", df[df["Power_Sufficient__c"] == "No"].shape[0])
|
16 |
col4.metric("📷 Offline Cameras", df[df["Camera_Status__c"] == "Offline"].shape[0])
|
17 |
|
|
|
|
|
18 |
|
19 |
|
20 |
+
# Function to generate the alert level breakdown chart
|
21 |
+
def display_charts(filtered_df):
|
22 |
+
st.subheader("Alert Level Breakdown")
|
23 |
+
alert_level_counts = filtered_df['Alert_Level__c'].value_counts()
|
24 |
+
fig = px.pie(names=alert_level_counts.index, values=alert_level_counts.values, title="Alert Levels")
|
25 |
+
st.plotly_chart(fig)
|
26 |
+
|
27 |
+
# Function to generate heatmap for a given site
|
28 |
+
def generate_heatmap_for_site(site_name, df):
|
29 |
+
site_df = df[df['Site__c'] == site_name]
|
30 |
+
|
31 |
+
# Ensure that Alert_Level__c is treated as a string (for color mapping)
|
32 |
+
site_df['Alert_Level__c'] = site_df['Alert_Level__c'].astype(str)
|
33 |
+
|
34 |
+
# Define color mapping for alert levels
|
35 |
+
color_map = {
|
36 |
+
"Green": [0, 255, 0], # Green for "Green" alert level
|
37 |
+
"Yellow": [255, 255, 0], # Yellow for "Yellow" alert level
|
38 |
+
"Red": [255, 0, 0] # Red for "Red" alert level
|
39 |
+
}
|
40 |
+
|
41 |
+
# Create a color column based on Alert_Level__c
|
42 |
+
site_df["color"] = site_df["Alert_Level__c"].map(color_map)
|
43 |
+
|
44 |
+
# Create a Pydeck map for the site
|
45 |
+
layer = pdk.Layer(
|
46 |
+
"ScatterplotLayer",
|
47 |
+
data=site_df,
|
48 |
+
get_position='[Longitude__c, Latitude__c]',
|
49 |
+
get_color="color",
|
50 |
+
get_radius=80, # You can adjust the radius if needed
|
51 |
+
pickable=True,
|
52 |
+
auto_highlight=True
|
53 |
)
|
|
|
54 |
|
55 |
+
view_state = pdk.ViewState(
|
56 |
+
latitude=site_df["Location_Latitude__c"].mean(),
|
57 |
+
longitude=site_df["Location_Longitude__c"].mean(),
|
58 |
+
zoom=10,
|
59 |
+
pitch=40
|
60 |
+
)
|
61 |
+
|
62 |
+
tooltip = {
|
63 |
+
"html": """
|
64 |
+
<b>Pole Name:</b> {Name}<br>
|
65 |
+
<b>Site:</b> {Site__c}<br>
|
66 |
+
<b>Alert Level:</b> {Alert_Level__c}<br>
|
67 |
+
<b>RFID Tag:</b> {RFID_Tag__c}<br>
|
68 |
+
<b>Tilt:</b> {Tilt__c}<br>
|
69 |
+
<b>Vibration:</b> {Vibration__c}
|
70 |
+
""",
|
71 |
+
"style": {
|
72 |
+
"backgroundColor": "steelblue",
|
73 |
+
"color": "white"
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
# Return the heatmap
|
78 |
+
return pdk.Deck(
|
79 |
+
map_style="mapbox://styles/mapbox/dark-v10",
|
80 |
+
initial_view_state=view_state,
|
81 |
+
layers=[layer],
|
82 |
+
tooltip=tooltip
|
83 |
)
|
|