File size: 5,180 Bytes
47fce4a
24c2d24
 
023cdaa
 
2b39318
023cdaa
2b39318
 
47fce4a
2b39318
 
 
47fce4a
2b39318
 
 
 
 
24c2d24
2b39318
d628901
2b39318
 
d628901
2b39318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29dca43
 
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
from datetime import date

# Set page configuration
st.set_page_config(page_title="Air Quality Monitoring Dashboard", layout="wide")

# Sidebar for navigation
st.sidebar.title("Air Quality Monitoring")
dashboard_choice = st.sidebar.radio("Select Dashboard:", ("User Dashboard", "Admin Dashboard"))

# WHO Guidelines for display in both dashboards
who_guidelines = {
    "Pollutant": ["NO2", "O3"],
    "Max Safe Concentration (µg/m³)": [25, 100]
}

# Data Simulation for Current Day and Predictions
today_data = {
    "NO2 (µg/m³)": np.random.uniform(20, 60),  # Simulated data
    "O3 (µg/m³)": np.random.uniform(50, 120)   # Simulated data
}

# Simulated predictions for the next three days
next_three_days = pd.DataFrame({
    "Day": ["Day 1", "Day 2", "Day 3"],
    "NO2 (µg/m³)": np.random.uniform(20, 60, 3),
    "O3 (µg/m³)": np.random.uniform(50, 120, 3)
})

# Simulated actual and predicted data for Admin Dashboard
y_test = pd.DataFrame({
    "NO2": np.random.uniform(20, 60, 100),
    "O3": np.random.uniform(50, 120, 100)
})
y_test_pred = pd.DataFrame({
    "NO2": np.random.uniform(20, 60, 100),
    "O3": np.random.uniform(50, 120, 100)
})

### User Dashboard ###
if dashboard_choice == "User Dashboard":
    st.title("🌍 User Dashboard: Air Quality Monitoring")

    # Current Day Pollutant Concentrations
    st.sidebar.markdown(f"Today's Date: **{date.today().strftime('%B %d, %Y')}**")
    st.sidebar.markdown("### Current Pollutant Concentrations")
    st.sidebar.write(pd.DataFrame(today_data, index=["Concentration"]))

    st.sidebar.markdown("### WHO Guidelines")
    st.sidebar.write(pd.DataFrame(who_guidelines))

    # WHO guideline alerts
    if today_data["NO2 (µg/m³)"] > 25:
        st.sidebar.error("⚠️ NO2 levels are above WHO guidelines!")
    else:
        st.sidebar.success("✅ NO2 levels are within safe limits.")

    if today_data["O3 (µg/m³)"] > 100:
        st.sidebar.error("⚠️ O3 levels are above WHO guidelines!")
    else:
        st.sidebar.success("✅ O3 levels are within safe limits.")

    # Predictions for the next three days
    st.write("### Predictions for the Next 3 Days")
    st.dataframe(next_three_days)

    # Visualization: Prediction vs WHO Guidelines
    st.write("### Visualization: Predictions vs WHO Guidelines")
    fig, ax = plt.subplots(figsize=(8, 4))
    ax.plot(next_three_days["Day"], next_three_days["NO2 (µg/m³)"], label="NO2", marker='o', color="red")
    ax.axhline(y=25, color="red", linestyle='--', label="NO2 WHO Limit (25 µg/m³)")
    ax.plot(next_three_days["Day"], next_three_days["O3 (µg/m³)"], label="O3", marker='x', color="blue")
    ax.axhline(y=100, color="blue", linestyle='--', label="O3 WHO Limit (100 µg/m³)")

    ax.set_title("Predicted Pollutant Levels vs WHO Guidelines")
    ax.set_xlabel("Days")
    ax.set_ylabel("Concentration (µg/m³)")
    ax.legend()
    st.pyplot(fig)

### Admin Dashboard ###
elif dashboard_choice == "Admin Dashboard":
    st.title("🔧 Admin Dashboard: Detailed Monitoring & Model Performance")

    # Model selection for monitoring (simulated)
    model_name = st.sidebar.selectbox(
        "Select model for monitoring:",
        ("Decision Tree", "Random Forest", "XGBoost")
    )

    # Displaying prediction and actual comparison
    st.write("### Predicted vs Actual Values")

    col1, col2 = st.columns(2)
    with col1:
        st.write("**Actual Values**")
        st.dataframe(y_test)

    with col2:
        st.write("**Predicted Values**")
        st.dataframe(y_test_pred)

    # Performance Metrics
    mse_no2 = mean_squared_error(y_test["NO2"], y_test_pred["NO2"])
    mse_o3 = mean_squared_error(y_test["O3"], y_test_pred["O3"])
    rmse_no2 = np.sqrt(mse_no2)
    rmse_o3 = np.sqrt(mse_o3)

    st.markdown("### Model Performance Metrics")
    col3, col4 = st.columns(2)
    col3.metric("NO2 - Mean Squared Error (MSE)", f"{mse_no2:.2f}")
    col4.metric("O3 - Mean Squared Error (MSE)", f"{mse_o3:.2f}")
    col3.metric("NO2 - Root Mean Squared Error (RMSE)", f"{rmse_no2:.2f}")
    col4.metric("O3 - Root Mean Squared Error (RMSE)", f"{rmse_o3:.2f}")

    # Visualization of Actual vs Predicted Values
    st.markdown("### Visualization: Actual vs Predicted Values")
    fig, ax = plt.subplots(figsize=(10, 5))
    ax.plot(y_test["NO2"], label="Actual NO2", color="blue", marker='o')
    ax.plot(y_test_pred["NO2"], label="Predicted NO2", color="red", linestyle='--')
    ax.set_title(f"NO2 Actual vs Predicted - {model_name}")
    ax.set_xlabel("Samples")
    ax.set_ylabel("Concentration (µg/m³)")
    ax.legend()

    st.pyplot(fig)

    # Feature Importance (simulated example)
    st.markdown("### Feature Importance")
    feature_importances = pd.Series([0.3, 0.2, 0.5], index=["Feature 1", "Feature 2", "Feature 3"])

    fig, ax = plt.subplots(figsize=(8, 4))
    feature_importances.plot(kind="barh", ax=ax)
    ax.set_title(f"Feature Importance - {model_name}")
    st.pyplot(fig)

# say bye
st.sidebar.write("### Thank you for using our app!")