Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,25 +3,39 @@ import pandas as pd
|
|
3 |
import streamlit as st
|
4 |
import pydeck as pdk
|
5 |
|
6 |
-
# ----
|
7 |
-
|
8 |
-
"Hyderabad":
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
|
14 |
POLES_PER_SITE = 12
|
15 |
|
16 |
-
# ----
|
17 |
-
def
|
18 |
poles = []
|
19 |
-
spacing = 0.
|
20 |
-
|
21 |
for i in range(POLES_PER_SITE):
|
22 |
-
lat = center_lat
|
23 |
-
lon = center_lon + (i - POLES_PER_SITE // 2) * spacing
|
24 |
-
|
25 |
alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]
|
26 |
|
27 |
poles.append({
|
@@ -32,33 +46,41 @@ def generate_fixed_poles(site_name, center_lat, center_lon):
|
|
32 |
"Alert Level": alert_level,
|
33 |
"Health Score": round(random.uniform(70, 100), 2),
|
34 |
"Power Status": random.choice(['Sufficient', 'Insufficient']),
|
35 |
-
"Camera Status": random.choice(['Online', 'Offline'])
|
|
|
|
|
36 |
})
|
37 |
return poles
|
38 |
|
39 |
-
# ----
|
40 |
all_poles = []
|
41 |
-
for site,
|
42 |
-
|
|
|
43 |
|
44 |
df = pd.DataFrame(all_poles)
|
45 |
|
46 |
# ---- Streamlit UI ----
|
47 |
-
st.set_page_config(page_title="
|
48 |
-
st.title("
|
49 |
|
50 |
-
site = st.selectbox("Select a site
|
|
|
51 |
|
52 |
# ---- Filtered View ----
|
53 |
filtered_df = df[df["Site"] == site]
|
54 |
|
55 |
-
# ----
|
|
|
|
|
|
|
|
|
56 |
col1, col2, col3 = st.columns(3)
|
57 |
col1.metric("Total Poles", POLES_PER_SITE)
|
58 |
-
col2.metric("Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
|
59 |
-
col3.metric("Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])
|
60 |
|
61 |
-
# ----
|
62 |
def alert_color(alert):
|
63 |
return {
|
64 |
"Green": [0, 255, 0, 160],
|
@@ -69,12 +91,13 @@ def alert_color(alert):
|
|
69 |
filtered_df = filtered_df.copy()
|
70 |
filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)
|
71 |
|
72 |
-
# ---- Map ----
|
|
|
73 |
st.pydeck_chart(pdk.Deck(
|
74 |
initial_view_state=pdk.ViewState(
|
75 |
-
latitude=
|
76 |
-
longitude=
|
77 |
-
zoom=16,
|
78 |
pitch=45
|
79 |
),
|
80 |
layers=[
|
@@ -83,12 +106,14 @@ st.pydeck_chart(pdk.Deck(
|
|
83 |
data=filtered_df,
|
84 |
get_position='[Longitude, Latitude]',
|
85 |
get_color='Color',
|
86 |
-
get_radius=
|
87 |
pickable=True
|
88 |
)
|
89 |
],
|
90 |
tooltip={
|
91 |
"html": "<b>Pole ID:</b> {Pole ID}<br/>"
|
|
|
|
|
92 |
"<b>Health Score:</b> {Health Score}<br/>"
|
93 |
"<b>Alert Level:</b> {Alert Level}<br/>"
|
94 |
"<b>Camera:</b> {Camera Status}<br/>"
|
@@ -97,6 +122,6 @@ st.pydeck_chart(pdk.Deck(
|
|
97 |
}
|
98 |
))
|
99 |
|
100 |
-
# ---- Table
|
101 |
-
st.subheader(
|
102 |
st.dataframe(filtered_df, use_container_width=True)
|
|
|
3 |
import streamlit as st
|
4 |
import pydeck as pdk
|
5 |
|
6 |
+
# ---- Area-Specific Configuration ----
|
7 |
+
AREA_DETAILS = {
|
8 |
+
"Hyderabad": {
|
9 |
+
"coords": [17.4036, 78.5247], # Ramanthapur (open area)
|
10 |
+
"area_name": "Ramanthapur Dairy Farm",
|
11 |
+
"purpose": "Dairy Farm"
|
12 |
+
},
|
13 |
+
"Ballari": {
|
14 |
+
"coords": [15.1468, 76.9237], # Cowl Bazar
|
15 |
+
"area_name": "Cowl Bazar Power Station",
|
16 |
+
"purpose": "Power Station"
|
17 |
+
},
|
18 |
+
"Gadwal": {
|
19 |
+
"coords": [16.2315, 77.7965], # Bheem Nagar
|
20 |
+
"area_name": "Bheem Nagar Solar Station",
|
21 |
+
"purpose": "Solar Station"
|
22 |
+
},
|
23 |
+
"Kurnool": {
|
24 |
+
"coords": [15.8281, 78.0373], # Venkata Ramana Colony
|
25 |
+
"area_name": "Venkata Ramana Agriculture Field",
|
26 |
+
"purpose": "Agriculture Monitoring"
|
27 |
+
}
|
28 |
}
|
29 |
|
30 |
POLES_PER_SITE = 12
|
31 |
|
32 |
+
# ---- Generate Poles in Open Area Aligned Horizontally ----
|
33 |
+
def generate_open_area_poles(site_name, center_lat, center_lon, area, purpose):
|
34 |
poles = []
|
35 |
+
spacing = 0.0006 # fine-tuned horizontal spread
|
|
|
36 |
for i in range(POLES_PER_SITE):
|
37 |
+
lat = center_lat + random.uniform(-0.0002, 0.0002)
|
38 |
+
lon = center_lon + (i - POLES_PER_SITE // 2) * spacing
|
|
|
39 |
alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]
|
40 |
|
41 |
poles.append({
|
|
|
46 |
"Alert Level": alert_level,
|
47 |
"Health Score": round(random.uniform(70, 100), 2),
|
48 |
"Power Status": random.choice(['Sufficient', 'Insufficient']),
|
49 |
+
"Camera Status": random.choice(['Online', 'Offline']),
|
50 |
+
"Location Area": area,
|
51 |
+
"Purpose": purpose
|
52 |
})
|
53 |
return poles
|
54 |
|
55 |
+
# ---- Prepare Full DataFrame ----
|
56 |
all_poles = []
|
57 |
+
for site, details in AREA_DETAILS.items():
|
58 |
+
poles = generate_open_area_poles(site, *details['coords'], details['area_name'], details['purpose'])
|
59 |
+
all_poles.extend(poles)
|
60 |
|
61 |
df = pd.DataFrame(all_poles)
|
62 |
|
63 |
# ---- Streamlit UI ----
|
64 |
+
st.set_page_config(page_title="Smart Pole Visual Dashboard", layout="wide")
|
65 |
+
st.title("π Smart Renewable Pole Monitoring Dashboard")
|
66 |
|
67 |
+
site = st.selectbox("π Select a site location:", list(AREA_DETAILS.keys()))
|
68 |
+
selected = AREA_DETAILS[site]
|
69 |
|
70 |
# ---- Filtered View ----
|
71 |
filtered_df = df[df["Site"] == site]
|
72 |
|
73 |
+
# ---- Display Site Description ----
|
74 |
+
st.markdown(f"### π Location: **{selected['area_name']}**")
|
75 |
+
st.markdown(f"π§ **Poles Purpose**: {selected['purpose']}")
|
76 |
+
|
77 |
+
# ---- KPI Metrics ----
|
78 |
col1, col2, col3 = st.columns(3)
|
79 |
col1.metric("Total Poles", POLES_PER_SITE)
|
80 |
+
col2.metric("π΄ Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
|
81 |
+
col3.metric("π· Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])
|
82 |
|
83 |
+
# ---- Alert Level to Color ----
|
84 |
def alert_color(alert):
|
85 |
return {
|
86 |
"Green": [0, 255, 0, 160],
|
|
|
91 |
filtered_df = filtered_df.copy()
|
92 |
filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)
|
93 |
|
94 |
+
# ---- Map Visualization ----
|
95 |
+
st.subheader("πΊοΈ Pole Location & Health Status")
|
96 |
st.pydeck_chart(pdk.Deck(
|
97 |
initial_view_state=pdk.ViewState(
|
98 |
+
latitude=selected['coords'][0],
|
99 |
+
longitude=selected['coords'][1],
|
100 |
+
zoom=16.5,
|
101 |
pitch=45
|
102 |
),
|
103 |
layers=[
|
|
|
106 |
data=filtered_df,
|
107 |
get_position='[Longitude, Latitude]',
|
108 |
get_color='Color',
|
109 |
+
get_radius=30,
|
110 |
pickable=True
|
111 |
)
|
112 |
],
|
113 |
tooltip={
|
114 |
"html": "<b>Pole ID:</b> {Pole ID}<br/>"
|
115 |
+
"<b>Location:</b> {Location Area}<br/>"
|
116 |
+
"<b>Purpose:</b> {Purpose}<br/>"
|
117 |
"<b>Health Score:</b> {Health Score}<br/>"
|
118 |
"<b>Alert Level:</b> {Alert Level}<br/>"
|
119 |
"<b>Camera:</b> {Camera Status}<br/>"
|
|
|
122 |
}
|
123 |
))
|
124 |
|
125 |
+
# ---- Data Table ----
|
126 |
+
st.subheader("π Detailed Pole Information")
|
127 |
st.dataframe(filtered_df, use_container_width=True)
|