import pandas as pd import streamlit as st import plotly.graph_objects as go # Sample AQI data (replace with your actual data source) data = { 'Timestamp': pd.to_datetime(['2024-07-26 10:00:00', '2024-07-26 11:00:00', '2024-07-26 12:00:00', '2024-07-26 13:00:00', '2024-07-26 14:00:00']), 'AQI': [80, 120, 150, 90, 60], 'PM2.5': [30, 50, 65, 35, 20], 'O3': [40, 60, 80, 50, 30], 'CO': [5, 8, 10, 6, 3], 'SO2': [10, 15, 20, 12, 8], 'NO2': [15, 25, 30, 20, 12] } df = pd.DataFrame(data) # AQI Categories and Health Recommendations aqi_categories = { (0, 50): {'label': 'Good', 'color': 'green', 'recommendations': { 'heart_patients': 'Enjoy your normal activities.', 'old_age': 'Enjoy your normal activities.', 'mid_age': 'Enjoy your normal activities.', 'young_age': 'Enjoy your normal activities.', 'general': 'Air quality is satisfactory.' }}, (51, 100): {'label': 'Moderate', 'color': 'yellow', 'recommendations': { 'heart_patients': 'Consider limiting prolonged or heavy exertion.', 'old_age': 'Consider limiting prolonged or heavy exertion.', 'mid_age': 'Generally acceptable for most.', 'young_age': 'Generally acceptable for most.', 'general': 'Air quality is acceptable; however, unusually sensitive people should consider limiting their outdoor exertion.' }}, (101, 150): {'label': 'Unhealthy for Sensitive Groups', 'color': 'orange', 'recommendations': { 'heart_patients': 'Avoid prolonged or heavy exertion. Consult your doctor if you experience symptoms.', 'old_age': 'Avoid prolonged or heavy exertion. Consult your doctor if you experience symptoms.', 'mid_age': 'Limit prolonged or heavy exertion.', 'young_age': 'Limit prolonged or heavy exertion.', 'general': 'Members of sensitive groups may experience health effects. The general public is not likely to be affected.' }}, (151, 200): {'label': 'Unhealthy', 'color': 'red', 'recommendations': { 'heart_patients': 'Avoid all outdoor exertion. Stay indoors as much as possible. Consult your doctor if you experience symptoms.', 'old_age': 'Avoid all outdoor exertion. Stay indoors as much as possible. Consult your doctor if you experience symptoms.', 'mid_age': 'Avoid all outdoor exertion. Stay indoors as much as possible.', 'young_age': 'Avoid all outdoor exertion. Stay indoors as much as possible.', 'general': 'Everyone may begin to experience health effects; members of sensitive groups may experience more serious health effects.' }}, (201, 300): {'label': 'Very Unhealthy', 'color': 'purple', 'recommendations': { 'heart_patients': 'Remain indoors. Avoid all exertion. Consult your doctor immediately if you experience symptoms.', 'old_age': 'Remain indoors. Avoid all exertion. Consult your doctor immediately if you experience symptoms.', 'mid_age': 'Remain indoors. Avoid all exertion.', 'young_age': 'Remain indoors. Avoid all exertion.', 'general': 'Health alert: everyone may experience more serious health effects.' }}, (301, 500): {'label': 'Hazardous', 'color': 'maroon', 'recommendations': { 'heart_patients': 'Seek immediate medical attention.', 'old_age': 'Seek immediate medical attention.', 'mid_age': 'Seek immediate medical attention.', 'young_age': 'Seek immediate medical attention.', 'general': 'Health emergency: a health alert indicates that everyone may experience more serious health effects.' }} } # Streamlit app st.title('Air Quality Dashboard') # Current AQI and Category current_aqi = df['AQI'].iloc[-1] current_category = None for aqi_range, category_data in aqi_categories.items(): if aqi_range[0] <= current_aqi <= aqi_range[1]: current_category = category_data break # Display AQI with color st.markdown( f"

Current AQI: {current_aqi} ({current_category['label']})

", unsafe_allow_html=True ) # Gauge chart for AQI fig_gauge = go.Figure(go.Indicator( mode="gauge+number", value=current_aqi, title={'text': "Air Quality Index"}, domain={'x': [0, 1], 'y': [0, 1]}, gauge={ 'axis': {'range': [None, 500]}, 'steps': [{'range': [0, 50], 'color': "green"}, {'range': [50, 100], 'color': "yellow"}, {'range': [100, 150], 'color': "orange"}, {'range': [150, 200], 'color': "red"}, {'range': [200, 300], 'color': "purple"}, {'range': [300, 500], 'color': "maroon"}], 'threshold': { 'line': {'color': "black", 'width': 4}, 'thickness': 0.75, 'value': current_aqi } } )) st.plotly_chart(fig_gauge) # Detailed Pollutant Levels st.subheader('Detailed Pollutant Levels') st.line_chart(df[['PM2.5', 'O3', 'CO', 'SO2', 'NO2']]) # Health Recommendations st.subheader('Health Recommendations') st.write(f"**General:** {current_category['recommendations']['general']}") st.write(f"**Heart Patients:** {current_category['recommendations']['heart_patients']}") st.write(f"**Old Age:** {current_category['recommendations']['old_age']}") st.write(f"**Mid Age:** {current_category['recommendations']['mid_age']}") st.write(f"**Young Age:** {current_category['recommendations']['young_age']}") # Add more visualizations (e.g., bar charts for pollutant comparison) as needed.