import streamlit as st from modules.simulator import simulate_data from modules.filters import apply_filters from modules.visuals import display_dashboard, display_charts, display_map_heatmap from modules.scheduler import get_latest_data from datetime import datetime # Set page config as the first Streamlit command st.set_page_config(page_title="Vedavathi Smart Pole Monitoring", layout="wide") # Inject CSS for blinking red dots with enhanced animation st.markdown(""" """, unsafe_allow_html=True) st.title("πŸ“‘ Vedavathi Smart Pole Monitoring - PoC Simulator") st.sidebar.header("πŸ› οΈ Simulation Controls") num_poles = 50 # Fixed number of poles st.sidebar.write(f"Number of Poles: {num_poles}") simulate_faults = st.sidebar.checkbox("Simulate Random Faults", value=True) # Get latest data from scheduler df, last_update = get_latest_data(num_poles, simulate_faults) st.write(f"Last Data Update: {last_update.strftime('%Y-%m-%d %H:%M:%S')} (Updates every 6 hours)") st.sidebar.header("πŸ“‚ Filter Data") alert_filter = st.sidebar.multiselect("Alert Level", ["Green", "Yellow", "Red"], default=["Green", "Yellow", "Red"]) cam_filter = st.sidebar.selectbox("Camera Status", ["All", "Online", "Offline"], index=0) location_filter = st.sidebar.multiselect("Location", ["Hyderabad", "Gadwal", "Kurnool", "Bangalore"], default=["Hyderabad", "Gadwal", "Kurnool", "Bangalore"]) filtered_df = apply_filters(df, alert_filter, cam_filter, location_filter) # Create tabs for each location tabs = st.tabs(["Hyderabad", "Gadwal", "Kurnool", "Bangalore"]) locations = ["Hyderabad", "Gadwal", "Kurnool", "Bangalore"] for tab, location in zip(tabs, locations): with tab: location_df = filtered_df[filtered_df["Location"] == location] if not location_df.empty: display_dashboard(location_df, location) st.subheader(f"πŸ“‹ Pole Monitoring Table - {location}") st.dataframe(location_df[["PoleID", "RFID", "Timestamp", "AlertLevel", "Anomalies", "CameraStatus", "SolarGen(kWh)", "WindGen(kWh)", "Tilt(Β°)", "Vibration(g)"]], use_container_width=True) st.subheader(f"πŸ—ΊοΈ Alert Map - {location}") display_map_heatmap(location_df, location) st.subheader(f"πŸ“Š Energy and Sensor Charts - {location}") display_charts(location_df) else: st.warning(f"No poles found for {location} with the current filters.")