File size: 3,237 Bytes
5095fe6
 
 
 
 
09497f1
 
 
 
 
 
9156c8e
 
09497f1
9156c8e
09497f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9156c8e
 
09497f1
 
9156c8e
09497f1
9156c8e
09497f1
 
9156c8e
09497f1
 
 
 
 
9156c8e
09497f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9156c8e
09497f1
 
 
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
42
43
44
45
46
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import random
import pandas as pd
import streamlit as st
import pydeck as pdk

# ---- Fixed Coordinates for Specific Local Areas ----
AREA_COORDINATES = {
    "Hyderabad": [17.4036, 78.5247],          # Ramanthapur
    "Ballari": [15.1468, 76.9237],            # Cowl Bazar
    "Gadwal": [16.2315, 77.7965],             # Bheem Nagar
    "Kurnool": [15.8281, 78.0373]             # Venkata Ramana Colony
}

POLES_PER_SITE = 12

# ---- Helper Function to Simulate Poles in a Tight Area ----
def generate_fixed_poles(site_name, center_lat, center_lon):
    poles = []
    for i in range(POLES_PER_SITE):
        lat = center_lat + random.uniform(-0.001, 0.001)
        lon = center_lon + random.uniform(-0.001, 0.001)
        alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]

        poles.append({
            "Pole ID": f"{site_name[:3].upper()}-{i+1:03}",
            "Site": site_name,
            "Latitude": lat,
            "Longitude": lon,
            "Alert Level": alert_level,
            "Health Score": round(random.uniform(70, 100), 2),
            "Power Status": random.choice(['Sufficient', 'Insufficient']),
            "Camera Status": random.choice(['Online', 'Offline'])
        })
    return poles

# ---- Data Preparation ----
all_poles = []
for site, coords in AREA_COORDINATES.items():
    all_poles.extend(generate_fixed_poles(site, *coords))

df = pd.DataFrame(all_poles)

# ---- Streamlit UI ----
st.set_page_config(page_title="Localized Smart Pole View", layout="wide")
st.title("📍 Smart Pole Monitoring - Specific Neighborhood Areas")

site = st.selectbox("Select a site to view", list(AREA_COORDINATES.keys()))

# ---- Filtered View ----
filtered_df = df[df["Site"] == site]

# ---- Metrics ----
col1, col2, col3 = st.columns(3)
col1.metric("Total Poles", POLES_PER_SITE)
col2.metric("Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
col3.metric("Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])

# ---- Map Color Mapping ----
def alert_color(alert):
    return {
        "Green": [0, 255, 0, 160],
        "Yellow": [255, 255, 0, 160],
        "Red": [255, 0, 0, 160]
    }[alert]

filtered_df = filtered_df.copy()
filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)

# ---- Map ----
st.pydeck_chart(pdk.Deck(
    initial_view_state=pdk.ViewState(
        latitude=AREA_COORDINATES[site][0],
        longitude=AREA_COORDINATES[site][1],
        zoom=15,
        pitch=45
    ),
    layers=[
        pdk.Layer(
            "ScatterplotLayer",
            data=filtered_df,
            get_position='[Longitude, Latitude]',
            get_color='Color',
            get_radius=100,
            pickable=True
        )
    ],
    tooltip={
        "html": "<b>Pole ID:</b> {Pole ID}<br/>"
                "<b>Health Score:</b> {Health Score}<br/>"
                "<b>Alert Level:</b> {Alert Level}<br/>"
                "<b>Camera:</b> {Camera Status}<br/>"
                "<b>Power:</b> {Power Status}",
        "style": {"color": "white", "backgroundColor": "black"}
    }
))

# ---- Table View ----
st.subheader(f"📋 Pole Details in {site}")
st.dataframe(filtered_df, use_container_width=True)