Spaces:
Sleeping
Sleeping
| import random | |
| import pandas as pd | |
| import streamlit as st | |
| # ---- Constants ---- | |
| TOTAL_POLES = 1000 # Simulating a subset (e.g., 1000) for demo purposes | |
| # ---- Helper Functions ---- | |
| def simulate_pole(pole_id): | |
| solar_kwh = round(random.uniform(3.0, 7.5), 2) | |
| wind_kwh = round(random.uniform(0.5, 2.0), 2) | |
| power_required = round(random.uniform(4.0, 8.0), 2) | |
| total_power = solar_kwh + wind_kwh | |
| power_status = 'Sufficient' if total_power >= power_required else 'Insufficient' | |
| tilt_angle = round(random.uniform(0, 45), 2) # degrees | |
| vibration = round(random.uniform(0, 5), 2) # g-force | |
| camera_status = random.choice(['Online', 'Offline']) | |
| # Alert classification logic | |
| alert_level = 'Green' | |
| if tilt_angle > 30 or vibration > 3: | |
| alert_level = 'Yellow' | |
| if tilt_angle > 40 or vibration > 4.5: | |
| alert_level = 'Red' | |
| health_score = max(0, 100 - (tilt_angle + vibration * 10)) | |
| return { | |
| 'Pole ID': f'P{pole_id:05}', | |
| 'RFID': f'RFID{pole_id:05}', | |
| 'Solar (kWh)': solar_kwh, | |
| 'Wind (kWh)': wind_kwh, | |
| 'Power Required (kWh)': power_required, | |
| 'Total Power (kWh)': total_power, | |
| 'Power Status': power_status, | |
| 'Tilt Angle (Β°)': tilt_angle, | |
| 'Vibration (g)': vibration, | |
| 'Camera Status': camera_status, | |
| 'Health Score': round(health_score, 2), | |
| 'Alert Level': alert_level | |
| } | |
| # ---- App Logic ---- | |
| st.set_page_config(page_title="Smart Pole Monitoring", layout="wide") | |
| st.title("π AI-Enabled Smart Pole Monitoring System") | |
| # Sidebar controls | |
| num_poles = st.sidebar.slider("Number of Poles to Simulate", 100, 2000, 1000, step=100) | |
| # Simulate Data | |
| with st.spinner("Simulating poles..."): | |
| poles_data = [simulate_pole(i) for i in range(1, num_poles + 1)] | |
| df = pd.DataFrame(poles_data) | |
| # ---- Dashboard ---- | |
| col1, col2, col3 = st.columns(3) | |
| col1.metric("Total Poles", num_poles) | |
| col2.metric("Red Alerts", df[df['Alert Level'] == 'Red'].shape[0]) | |
| col3.metric("Power Insufficiencies", df[df['Power Status'] == 'Insufficient'].shape[0]) | |
| # ---- Data Table ---- | |
| st.subheader("π Pole-wise Table View") | |
| with st.expander("Filter Options"): | |
| alert_filter = st.multiselect("Alert Level", options=df['Alert Level'].unique(), default=df['Alert Level'].unique()) | |
| camera_filter = st.multiselect("Camera Status", options=df['Camera Status'].unique(), default=df['Camera Status'].unique()) | |
| filtered_df = df[(df['Alert Level'].isin(alert_filter)) & (df['Camera Status'].isin(camera_filter))] | |
| st.dataframe(filtered_df, use_container_width=True) | |
| # ---- Charts ---- | |
| st.subheader("π Energy Generation Comparison") | |
| st.bar_chart(df[['Solar (kWh)', 'Wind (kWh)']].mean()) | |
| st.subheader("π Tilt vs. Vibration") | |
| st.scatter_chart(df[['Tilt Angle (Β°)', 'Vibration (g)']]) | |
| st.success("Simulation Complete. Ready for AI + Salesforce integration π") | |