Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
You said:
|
| 3 |
import random
|
| 4 |
import pandas as pd
|
| 5 |
import streamlit as st
|
|
@@ -130,138 +128,6 @@ st.pydeck_chart(pdk.Deck(
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
| 1 |
import random
|
| 2 |
import pandas as pd
|
| 3 |
import streamlit as st
|
|
|
|
| 128 |
}
|
| 129 |
))
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
# ---- Data Table ----
|
| 132 |
st.subheader("📋 Detailed Pole Information")
|
| 133 |
st.dataframe(filtered_df, use_container_width=True)
|