Spaces:
Sleeping
Sleeping
Update modules/visuals.py
Browse files- modules/visuals.py +34 -42
modules/visuals.py
CHANGED
@@ -2,60 +2,52 @@ 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
|
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 |
-
col4.metric("π Locations", len(df['Location'].unique()))
|
12 |
|
13 |
def display_charts(df):
|
14 |
st.subheader("βοΈ Energy Generation Trends")
|
15 |
-
st.bar_chart(df.groupby("
|
16 |
st.subheader("π Tilt vs Vibration")
|
17 |
st.scatter_chart(df.rename(columns={"Tilt(Β°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
|
18 |
|
19 |
-
def
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
df["AlertValue"] = df["AlertLevel"].map(alert_map)
|
24 |
|
25 |
-
#
|
26 |
-
|
|
|
27 |
|
28 |
-
# Create
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
title="Pole Alert Heatmap by Location",
|
49 |
-
text_auto=False,
|
50 |
-
height=500
|
51 |
)
|
52 |
-
fig.update_traces(hovertemplate="%{customdata}<br>%{x}<br>%{y}", customdata=hover_text)
|
53 |
fig.update_layout(
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
tickvals=[0, 1, 2],
|
58 |
-
ticktext=["Green", "Yellow", "Red"]
|
59 |
-
)
|
60 |
)
|
61 |
st.plotly_chart(fig, use_container_width=True)
|
|
|
2 |
import plotly.express as px
|
3 |
import pandas as pd
|
4 |
|
5 |
+
def display_dashboard(df, location):
|
6 |
+
st.subheader(f"π System Summary - {location}")
|
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.groupby("Zone")[["SolarGen(kWh)", "WindGen(kWh)"]].sum())
|
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_map_heatmap(df, location):
|
19 |
+
if df.empty:
|
20 |
+
st.warning("No data available for this location.")
|
21 |
+
return
|
|
|
22 |
|
23 |
+
# Map AlertLevel to colors
|
24 |
+
df = df.copy()
|
25 |
+
df["AlertColor"] = df["AlertLevel"].map({"Green": "green", "Yellow": "yellow", "Red": "red"})
|
26 |
|
27 |
+
# Create scatter map
|
28 |
+
fig = px.scatter_mapbox(
|
29 |
+
df,
|
30 |
+
lat="Latitude",
|
31 |
+
lon="Longitude",
|
32 |
+
color="AlertLevel",
|
33 |
+
color_discrete_map={"Green": "green", "Yellow": "yellow", "Red": "red"},
|
34 |
+
size_max=15,
|
35 |
+
zoom=10,
|
36 |
+
hover_data={
|
37 |
+
"PoleID": True,
|
38 |
+
"RFID": True,
|
39 |
+
"AlertLevel": True,
|
40 |
+
"Anomalies": True,
|
41 |
+
"Zone": True,
|
42 |
+
"Latitude": False,
|
43 |
+
"Longitude": False
|
44 |
+
},
|
45 |
+
title=f"Pole Alert Map - {location}",
|
46 |
+
height=600
|
|
|
|
|
|
|
47 |
)
|
|
|
48 |
fig.update_layout(
|
49 |
+
mapbox_style="open-street-map",
|
50 |
+
margin={"r":0,"t":50,"l":0,"b":0},
|
51 |
+
showlegend=True
|
|
|
|
|
|
|
52 |
)
|
53 |
st.plotly_chart(fig, use_container_width=True)
|