Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,82 +1,267 @@
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
-
import
|
4 |
-
|
5 |
-
from folium.plugins import HeatMap
|
6 |
-
import random
|
7 |
|
8 |
-
# ----
|
9 |
-
|
10 |
-
"Hyderabad":
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
}
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
"
|
33 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
})
|
35 |
-
return
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
for
|
40 |
-
|
|
|
41 |
|
42 |
-
df = pd.DataFrame(
|
43 |
|
44 |
# ---- Streamlit UI ----
|
45 |
-
st.set_page_config(layout="wide")
|
46 |
-
st.title("π
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
# ----
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
# ----
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
st.
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
You said:
|
3 |
+
import random
|
4 |
+
import pandas as pd
|
5 |
import streamlit as st
|
6 |
+
import pydeck as pdk
|
7 |
+
|
8 |
+
# ---- Area-Specific Configuration ----
|
9 |
+
AREA_DETAILS = {
|
10 |
+
"Hyderabad": {
|
11 |
+
"coords": [17.4036, 78.5247],
|
12 |
+
"area_name": "Ramanthapur Dairy Farm",
|
13 |
+
"purpose": "Dairy Farm"
|
14 |
+
},
|
15 |
+
"Ballari": {
|
16 |
+
"coords": [15.1468, 76.9237],
|
17 |
+
"area_name": "Cowl Bazar Power Station",
|
18 |
+
"purpose": "Power Station"
|
19 |
+
},
|
20 |
+
"Gadwal": {
|
21 |
+
"coords": [16.2315, 77.7965],
|
22 |
+
"area_name": "Bheem Nagar Solar Station",
|
23 |
+
"purpose": "Solar Station"
|
24 |
+
},
|
25 |
+
"Kurnool": {
|
26 |
+
"coords": [15.8281, 78.0373],
|
27 |
+
"area_name": "Venkata Ramana Agriculture Field",
|
28 |
+
"purpose": "Agriculture Monitoring"
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
POLES_PER_SITE = 12
|
33 |
+
|
34 |
+
# ---- Generate Poles with Anomalies ----
|
35 |
+
def generate_open_area_poles(site_name, center_lat, center_lon, area, purpose):
|
36 |
+
poles = []
|
37 |
+
spacing = 0.0006
|
38 |
+
anomalies_options = ['None', 'Sensor Fault', 'Overheat', 'Power Surge']
|
39 |
+
anomaly_weights = [0.6, 0.2, 0.1, 0.1]
|
40 |
+
|
41 |
+
for i in range(POLES_PER_SITE):
|
42 |
+
lat = center_lat + random.uniform(-0.0002, 0.0002)
|
43 |
+
lon = center_lon + (i - POLES_PER_SITE // 2) * spacing
|
44 |
+
alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]
|
45 |
+
anomaly = random.choices(anomalies_options, weights=anomaly_weights)[0]
|
46 |
+
|
47 |
+
poles.append({
|
48 |
+
"Pole ID": f"{site_name[:3].upper()}-{i+1:03}",
|
49 |
+
"Site": site_name,
|
50 |
+
"Latitude": lat,
|
51 |
+
"Longitude": lon,
|
52 |
+
"Alert Level": alert_level,
|
53 |
+
"Health Score": round(random.uniform(70, 100), 2),
|
54 |
+
"Power Status": random.choice(['Sufficient', 'Insufficient']),
|
55 |
+
"Camera Status": random.choice(['Online', 'Offline']),
|
56 |
+
"Location Area": area,
|
57 |
+
"Purpose": purpose,
|
58 |
+
"Anomalies": anomaly
|
59 |
+
})
|
60 |
+
return poles
|
61 |
+
|
62 |
+
# ---- Prepare Full DataFrame ----
|
63 |
+
all_poles = []
|
64 |
+
for site, details in AREA_DETAILS.items():
|
65 |
+
poles = generate_open_area_poles(site, *details['coords'], details['area_name'], details['purpose'])
|
66 |
+
all_poles.extend(poles)
|
67 |
+
|
68 |
+
df = pd.DataFrame(all_poles)
|
69 |
+
|
70 |
+
# ---- Streamlit UI ----
|
71 |
+
st.set_page_config(page_title="Smart Pole Visual Dashboard", layout="wide")
|
72 |
+
st.title("π Smart Renewable Pole Monitoring Dashboard")
|
73 |
+
|
74 |
+
site = st.selectbox("π Select a site location:", list(AREA_DETAILS.keys()))
|
75 |
+
selected = AREA_DETAILS[site]
|
76 |
+
|
77 |
+
# ---- Filtered View ----
|
78 |
+
filtered_df = df[df["Site"] == site]
|
79 |
+
|
80 |
+
# ---- Display Site Description ----
|
81 |
+
st.markdown(f"### π Location: **{selected['area_name']}**")
|
82 |
+
st.markdown(f"π§ **Poles Purpose**: {selected['purpose']}")
|
83 |
+
|
84 |
+
# ---- KPI Metrics ----
|
85 |
+
col1, col2, col3 = st.columns(3)
|
86 |
+
col1.metric("Total Poles", POLES_PER_SITE)
|
87 |
+
col2.metric("π΄ Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
|
88 |
+
col3.metric("π· Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])
|
89 |
+
|
90 |
+
# ---- Alert Level to Color ----
|
91 |
+
def alert_color(alert):
|
92 |
+
return {
|
93 |
+
"Green": [0, 255, 0, 160],
|
94 |
+
"Yellow": [255, 255, 0, 160],
|
95 |
+
"Red": [255, 0, 0, 160]
|
96 |
+
}[alert]
|
97 |
+
|
98 |
+
filtered_df = filtered_df.copy()
|
99 |
+
filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)
|
100 |
+
|
101 |
+
# ---- Map Visualization ----
|
102 |
+
st.subheader("πΊοΈ Pole Location & Health Status")
|
103 |
+
st.pydeck_chart(pdk.Deck(
|
104 |
+
initial_view_state=pdk.ViewState(
|
105 |
+
latitude=selected['coords'][0],
|
106 |
+
longitude=selected['coords'][1],
|
107 |
+
zoom=16.5,
|
108 |
+
pitch=45
|
109 |
+
),
|
110 |
+
layers=[
|
111 |
+
pdk.Layer(
|
112 |
+
"ScatterplotLayer",
|
113 |
+
data=filtered_df,
|
114 |
+
get_position='[Longitude, Latitude]',
|
115 |
+
get_color='Color',
|
116 |
+
get_radius=30,
|
117 |
+
pickable=True
|
118 |
+
)
|
119 |
+
],
|
120 |
+
tooltip={
|
121 |
+
"html": "<b>Pole ID:</b> {Pole ID}<br/>"
|
122 |
+
"<b>Location:</b> {Location Area}<br/>"
|
123 |
+
"<b>Purpose:</b> {Purpose}<br/>"
|
124 |
+
"<b>Health Score:</b> {Health Score}<br/>"
|
125 |
+
"<b>Alert Level:</b> {Alert Level}<br/>"
|
126 |
+
"<b>Camera:</b> {Camera Status}<br/>"
|
127 |
+
"<b>Power:</b> {Power Status}<br/>"
|
128 |
+
"<b>Anomaly:</b> {Anomalies}",
|
129 |
+
"style": {"color": "white", "backgroundColor": "black"}
|
130 |
+
}
|
131 |
+
))
|
132 |
+
|
133 |
+
# ---- Data Table ----
|
134 |
+
st.subheader("π Detailed Pole Information")
|
135 |
+
st.dataframe(filtered_df, use_container_width=True) import random
|
136 |
import pandas as pd
|
137 |
+
import streamlit as st
|
138 |
+
import pydeck as pdk
|
|
|
|
|
139 |
|
140 |
+
# ---- Area-Specific Configuration ----
|
141 |
+
AREA_DETAILS = {
|
142 |
+
"Hyderabad": {
|
143 |
+
"coords": [17.4036, 78.5247],
|
144 |
+
"area_name": "Ramanthapur Dairy Farm",
|
145 |
+
"purpose": "Dairy Farm"
|
146 |
+
},
|
147 |
+
"Ballari": {
|
148 |
+
"coords": [15.1468, 76.9237],
|
149 |
+
"area_name": "Cowl Bazar Power Station",
|
150 |
+
"purpose": "Power Station"
|
151 |
+
},
|
152 |
+
"Gadwal": {
|
153 |
+
"coords": [16.2315, 77.7965],
|
154 |
+
"area_name": "Bheem Nagar Solar Station",
|
155 |
+
"purpose": "Solar Station"
|
156 |
+
},
|
157 |
+
"Kurnool": {
|
158 |
+
"coords": [15.8281, 78.0373],
|
159 |
+
"area_name": "Venkata Ramana Agriculture Field",
|
160 |
+
"purpose": "Agriculture Monitoring"
|
161 |
+
}
|
162 |
}
|
163 |
|
164 |
+
POLES_PER_SITE = 12
|
165 |
+
|
166 |
+
# ---- Generate Poles with Anomalies ----
|
167 |
+
def generate_open_area_poles(site_name, center_lat, center_lon, area, purpose):
|
168 |
+
poles = []
|
169 |
+
spacing = 0.0006
|
170 |
+
anomalies_options = ['None', 'Sensor Fault', 'Overheat', 'Power Surge']
|
171 |
+
anomaly_weights = [0.6, 0.2, 0.1, 0.1]
|
172 |
+
|
173 |
+
for i in range(POLES_PER_SITE):
|
174 |
+
lat = center_lat + random.uniform(-0.0002, 0.0002)
|
175 |
+
lon = center_lon + (i - POLES_PER_SITE // 2) * spacing
|
176 |
+
alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]
|
177 |
+
anomaly = random.choices(anomalies_options, weights=anomaly_weights)[0]
|
178 |
+
|
179 |
+
poles.append({
|
180 |
+
"Pole ID": f"{site_name[:3].upper()}-{i+1:03}",
|
181 |
+
"Site": site_name,
|
182 |
+
"Latitude": lat,
|
183 |
+
"Longitude": lon,
|
184 |
+
"Alert Level": alert_level,
|
185 |
+
"Health Score": round(random.uniform(70, 100), 2),
|
186 |
+
"Power Status": random.choice(['Sufficient', 'Insufficient']),
|
187 |
+
"Camera Status": random.choice(['Online', 'Offline']),
|
188 |
+
"Location Area": area,
|
189 |
+
"Purpose": purpose,
|
190 |
+
"Anomalies": anomaly
|
191 |
})
|
192 |
+
return poles
|
193 |
|
194 |
+
# ---- Prepare Full DataFrame ----
|
195 |
+
all_poles = []
|
196 |
+
for site, details in AREA_DETAILS.items():
|
197 |
+
poles = generate_open_area_poles(site, *details['coords'], details['area_name'], details['purpose'])
|
198 |
+
all_poles.extend(poles)
|
199 |
|
200 |
+
df = pd.DataFrame(all_poles)
|
201 |
|
202 |
# ---- Streamlit UI ----
|
203 |
+
st.set_page_config(page_title="Smart Pole Visual Dashboard", layout="wide")
|
204 |
+
st.title("π Smart Renewable Pole Monitoring Dashboard")
|
205 |
+
|
206 |
+
site = st.selectbox("π Select a site location:", list(AREA_DETAILS.keys()))
|
207 |
+
selected = AREA_DETAILS[site]
|
208 |
+
|
209 |
+
# ---- Filtered View ----
|
210 |
+
filtered_df = df[df["Site"] == site]
|
211 |
+
|
212 |
+
# ---- Display Site Description ----
|
213 |
+
st.markdown(f"### π Location: **{selected['area_name']}**")
|
214 |
+
st.markdown(f"π§ **Poles Purpose**: {selected['purpose']}")
|
215 |
+
|
216 |
+
# ---- KPI Metrics ----
|
217 |
+
col1, col2, col3 = st.columns(3)
|
218 |
+
col1.metric("Total Poles", POLES_PER_SITE)
|
219 |
+
col2.metric("π΄ Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
|
220 |
+
col3.metric("π· Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])
|
221 |
+
|
222 |
+
# ---- Alert Level to Color ----
|
223 |
+
def alert_color(alert):
|
224 |
+
return {
|
225 |
+
"Green": [0, 255, 0, 160],
|
226 |
+
"Yellow": [255, 255, 0, 160],
|
227 |
+
"Red": [255, 0, 0, 160]
|
228 |
+
}[alert]
|
229 |
+
|
230 |
+
filtered_df = filtered_df.copy()
|
231 |
+
filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)
|
232 |
+
|
233 |
+
# ---- Map Visualization ----
|
234 |
+
st.subheader("πΊοΈ Pole Location & Health Status")
|
235 |
+
st.pydeck_chart(pdk.Deck(
|
236 |
+
initial_view_state=pdk.ViewState(
|
237 |
+
latitude=selected['coords'][0],
|
238 |
+
longitude=selected['coords'][1],
|
239 |
+
zoom=16.5,
|
240 |
+
pitch=45
|
241 |
+
),
|
242 |
+
layers=[
|
243 |
+
pdk.Layer(
|
244 |
+
"ScatterplotLayer",
|
245 |
+
data=filtered_df,
|
246 |
+
get_position='[Longitude, Latitude]',
|
247 |
+
get_color='Color',
|
248 |
+
get_radius=30,
|
249 |
+
pickable=True
|
250 |
+
)
|
251 |
+
],
|
252 |
+
tooltip={
|
253 |
+
"html": "<b>Pole ID:</b> {Pole ID}<br/>"
|
254 |
+
"<b>Location:</b> {Location Area}<br/>"
|
255 |
+
"<b>Purpose:</b> {Purpose}<br/>"
|
256 |
+
"<b>Health Score:</b> {Health Score}<br/>"
|
257 |
+
"<b>Alert Level:</b> {Alert Level}<br/>"
|
258 |
+
"<b>Camera:</b> {Camera Status}<br/>"
|
259 |
+
"<b>Power:</b> {Power Status}<br/>"
|
260 |
+
"<b>Anomaly:</b> {Anomalies}",
|
261 |
+
"style": {"color": "white", "backgroundColor": "black"}
|
262 |
+
}
|
263 |
+
))
|
264 |
+
|
265 |
+
# ---- Data Table ----
|
266 |
+
st.subheader("π Detailed Pole Information")
|
267 |
+
st.dataframe(filtered_df, use_container_width=True)
|