Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,22 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"Kurnool": {"coords": [15.8281, 78.0373], "zone": "West Industrial"},
|
| 17 |
-
"Ballari": {"coords": [12.9716, 77.5946], "zone": "Urban Grid"}
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
# ---- Custom Placement for Hyderabad ----
|
| 21 |
-
def generate_hyderabad_pole_locations(base_lat, base_lon, num_poles):
|
| 22 |
return [
|
| 23 |
-
[base_lat + i *
|
| 24 |
-
for i in range(
|
| 25 |
-
]
|
| 26 |
-
|
| 27 |
-
# ---- Helper Functions ----
|
| 28 |
-
def generate_location(base_lat, base_lon):
|
| 29 |
-
return [
|
| 30 |
-
base_lat + random.uniform(-0.02, 0.02),
|
| 31 |
-
base_lon + random.uniform(-0.02, 0.02)
|
| 32 |
-
]
|
| 33 |
-
|
| 34 |
-
def simulate_pole(pole_id, site_name, lat, lon):
|
| 35 |
-
solar_kwh = round(random.uniform(3.0, 7.5), 2)
|
| 36 |
-
wind_kwh = round(random.uniform(0.5, 2.0), 2)
|
| 37 |
-
power_required = round(random.uniform(4.0, 8.0), 2)
|
| 38 |
-
total_power = solar_kwh + wind_kwh
|
| 39 |
-
power_status = 'Sufficient' if total_power >= power_required else 'Insufficient'
|
| 40 |
-
|
| 41 |
-
vibration = round(random.uniform(0, 5), 2)
|
| 42 |
-
camera_status = random.choice(['Online', 'Offline'])
|
| 43 |
-
|
| 44 |
-
alert_level = 'Green'
|
| 45 |
-
if vibration > 3:
|
| 46 |
-
alert_level = 'Yellow'
|
| 47 |
-
if vibration > 4.5:
|
| 48 |
-
alert_level = 'Red'
|
| 49 |
-
|
| 50 |
-
health_score = max(0, 100 - (vibration * 10))
|
| 51 |
-
timestamp = datetime.now() - timedelta(hours=random.randint(0, 6))
|
| 52 |
-
|
| 53 |
-
return {
|
| 54 |
-
'Pole ID': f'{site_name[:3].upper()}-{pole_id:03}',
|
| 55 |
-
'Site': site_name,
|
| 56 |
-
'Zone': SITES[site_name]["zone"],
|
| 57 |
-
'Latitude': lat,
|
| 58 |
-
'Longitude': lon,
|
| 59 |
-
'Solar (kWh)': solar_kwh,
|
| 60 |
-
'Wind (kWh)': wind_kwh,
|
| 61 |
-
'Power Required (kWh)': power_required,
|
| 62 |
-
'Total Power (kWh)': total_power,
|
| 63 |
-
'Power Status': power_status,
|
| 64 |
-
'Vibration (g)': vibration,
|
| 65 |
-
'Camera Status': camera_status,
|
| 66 |
-
'Health Score': round(health_score, 2),
|
| 67 |
-
'Alert Level': alert_level,
|
| 68 |
-
'Last Checked': timestamp.strftime('%Y-%m-%d %H:%M:%S')
|
| 69 |
-
}
|
| 70 |
|
| 71 |
# ---- Streamlit UI ----
|
| 72 |
st.set_page_config(page_title="Smart Pole Monitoring", layout="wide")
|
|
@@ -83,12 +33,8 @@ if selected_site in SITES:
|
|
| 83 |
for site_name, site_data in SITES.items():
|
| 84 |
base_lat, base_lon = site_data["coords"]
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
locations = generate_hyderabad_pole_locations(base_lat, base_lon, POLES_PER_SITE)
|
| 89 |
-
else:
|
| 90 |
-
# Randomly scattered poles
|
| 91 |
-
locations = [generate_location(base_lat, base_lon) for _ in range(POLES_PER_SITE)]
|
| 92 |
|
| 93 |
for i, (lat, lon) in enumerate(locations):
|
| 94 |
pole_data = simulate_pole(i + 1, site_name, lat, lon)
|
|
@@ -173,7 +119,7 @@ if selected_site in SITES:
|
|
| 173 |
zoom=12,
|
| 174 |
pitch=50
|
| 175 |
),
|
| 176 |
-
layers=[
|
| 177 |
pdk.Layer(
|
| 178 |
'ScatterplotLayer',
|
| 179 |
data=fault_df,
|
|
@@ -183,7 +129,7 @@ if selected_site in SITES:
|
|
| 183 |
pickable=True,
|
| 184 |
)
|
| 185 |
],
|
| 186 |
-
tooltip={
|
| 187 |
"html": """
|
| 188 |
<b>Pole ID:</b> {Pole ID}<br/>
|
| 189 |
<b>Zone:</b> {Zone}<br/>
|
|
|
|
| 1 |
+
# ---- Fixed Placement for Each Site ----
|
| 2 |
+
def generate_fixed_pole_locations(base_lat, base_lon, num_poles):
|
| 3 |
+
# Define a fixed area for pole placement (e.g., 0.01 degrees in latitude and longitude)
|
| 4 |
+
area_width = 0.01 # 0.01 degree latitude distance (approx. 1.1 km)
|
| 5 |
+
area_height = 0.01 # 0.01 degree longitude distance (approx. 1.1 km)
|
| 6 |
+
|
| 7 |
+
# Calculate number of rows and columns for the grid
|
| 8 |
+
rows = 3 # Number of rows in the grid
|
| 9 |
+
cols = 4 # Number of columns in the grid
|
| 10 |
+
|
| 11 |
+
# Calculate the spacing in both directions
|
| 12 |
+
lat_spacing = area_height / rows
|
| 13 |
+
lon_spacing = area_width / cols
|
| 14 |
+
|
| 15 |
+
# Generate the fixed grid of pole locations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return [
|
| 17 |
+
[base_lat + i * lat_spacing, base_lon + j * lon_spacing]
|
| 18 |
+
for i in range(rows) for j in range(cols)
|
| 19 |
+
][:num_poles] # Only take num_poles (12 in this case)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# ---- Streamlit UI ----
|
| 22 |
st.set_page_config(page_title="Smart Pole Monitoring", layout="wide")
|
|
|
|
| 33 |
for site_name, site_data in SITES.items():
|
| 34 |
base_lat, base_lon = site_data["coords"]
|
| 35 |
|
| 36 |
+
# Fixed placement for all poles
|
| 37 |
+
locations = generate_fixed_pole_locations(base_lat, base_lon, POLES_PER_SITE)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
for i, (lat, lon) in enumerate(locations):
|
| 40 |
pole_data = simulate_pole(i + 1, site_name, lat, lon)
|
|
|
|
| 119 |
zoom=12,
|
| 120 |
pitch=50
|
| 121 |
),
|
| 122 |
+
layers=[
|
| 123 |
pdk.Layer(
|
| 124 |
'ScatterplotLayer',
|
| 125 |
data=fault_df,
|
|
|
|
| 129 |
pickable=True,
|
| 130 |
)
|
| 131 |
],
|
| 132 |
+
tooltip={
|
| 133 |
"html": """
|
| 134 |
<b>Pole ID:</b> {Pole ID}<br/>
|
| 135 |
<b>Zone:</b> {Zone}<br/>
|