Spaces:
Sleeping
Sleeping
atodorov284 commited on
Commit ·
45dcae3
1
Parent(s): 13b62f3
add lack of data message
Browse files
streamlit_src/controllers/admin_controller.py
CHANGED
|
@@ -30,8 +30,11 @@ class AdminController(UserController):
|
|
| 30 |
switch = self._view.show_admin_pages()
|
| 31 |
|
| 32 |
if switch == "Display Predictions":
|
| 33 |
-
self.
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
elif switch == "Make Predictions":
|
| 37 |
self._make_custom_predictions()
|
|
|
|
| 30 |
switch = self._view.show_admin_pages()
|
| 31 |
|
| 32 |
if switch == "Display Predictions":
|
| 33 |
+
if not self._is_current_data_available():
|
| 34 |
+
self._view.data_not_available()
|
| 35 |
+
else:
|
| 36 |
+
self._show_current_data()
|
| 37 |
+
self._display_plots()
|
| 38 |
|
| 39 |
elif switch == "Make Predictions":
|
| 40 |
self._make_custom_predictions()
|
streamlit_src/controllers/user_controller.py
CHANGED
|
@@ -7,7 +7,7 @@ import os
|
|
| 7 |
import pandas as pd
|
| 8 |
import random
|
| 9 |
import json
|
| 10 |
-
from datetime import date, timedelta
|
| 11 |
import plotly.graph_objects as go
|
| 12 |
|
| 13 |
|
|
@@ -48,16 +48,37 @@ class UserController:
|
|
| 48 |
"""
|
| 49 |
Shows the main page of the user interface.
|
| 50 |
"""
|
| 51 |
-
self._show_current_data()
|
| 52 |
-
|
| 53 |
self._view.two_columns_layout(0.7, self._raise_awareness, self._quiz)
|
| 54 |
|
| 55 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
self._display_sources()
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def _display_sources(self) -> None:
|
| 62 |
"""
|
| 63 |
Displays the sources on the main page of the user interface.
|
|
@@ -86,7 +107,6 @@ class UserController:
|
|
| 86 |
Displays the plots on the main page of the user interface.
|
| 87 |
"""
|
| 88 |
plot_type = self._view.view_option_selection(["Line Plot", "Gauge Plot"])
|
| 89 |
-
|
| 90 |
if plot_type == "Line Plot":
|
| 91 |
line_fig = self._prepare_line_plot()
|
| 92 |
self._view.display_predictions_lineplot(line_fig)
|
|
|
|
| 7 |
import pandas as pd
|
| 8 |
import random
|
| 9 |
import json
|
| 10 |
+
from datetime import date, datetime, timedelta
|
| 11 |
import plotly.graph_objects as go
|
| 12 |
|
| 13 |
|
|
|
|
| 48 |
"""
|
| 49 |
Shows the main page of the user interface.
|
| 50 |
"""
|
|
|
|
|
|
|
| 51 |
self._view.two_columns_layout(0.7, self._raise_awareness, self._quiz)
|
| 52 |
|
| 53 |
+
if not self._is_current_data_available():
|
| 54 |
+
self._view.data_not_available()
|
| 55 |
+
else:
|
| 56 |
+
self._show_current_data()
|
| 57 |
+
|
| 58 |
+
self._display_plots()
|
| 59 |
|
| 60 |
+
self._display_compare_who()
|
| 61 |
|
| 62 |
self._display_sources()
|
| 63 |
|
| 64 |
+
def _is_current_data_available(self) -> bool:
|
| 65 |
+
"""
|
| 66 |
+
Checks if the current data is available.
|
| 67 |
+
|
| 68 |
+
The current data is not available from 14:00 to 15:15.
|
| 69 |
+
This is because the API is queried every 15 minutes, and the
|
| 70 |
+
data is not available for a short period of time before and after
|
| 71 |
+
the new data is fetched.
|
| 72 |
+
|
| 73 |
+
:return: True if the current data is available, False otherwise.
|
| 74 |
+
"""
|
| 75 |
+
current_time = datetime.now().time()
|
| 76 |
+
start_time = current_time.replace(hour=0, minute=0, second=0)
|
| 77 |
+
end_time = current_time.replace(hour=4, minute=15, second=0)
|
| 78 |
+
if start_time <= current_time <= end_time:
|
| 79 |
+
return False
|
| 80 |
+
return True
|
| 81 |
+
|
| 82 |
def _display_sources(self) -> None:
|
| 83 |
"""
|
| 84 |
Displays the sources on the main page of the user interface.
|
|
|
|
| 107 |
Displays the plots on the main page of the user interface.
|
| 108 |
"""
|
| 109 |
plot_type = self._view.view_option_selection(["Line Plot", "Gauge Plot"])
|
|
|
|
| 110 |
if plot_type == "Line Plot":
|
| 111 |
line_fig = self._prepare_line_plot()
|
| 112 |
self._view.display_predictions_lineplot(line_fig)
|
streamlit_src/views/user_view.py
CHANGED
|
@@ -23,6 +23,19 @@ class UserView:
|
|
| 23 |
st.sidebar.markdown("### Current Pollutant Concentrations and WHO Guidelines")
|
| 24 |
st.sidebar.dataframe(merged_data_df, hide_index=True)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def success(self, message: str) -> None:
|
| 27 |
"""
|
| 28 |
Show a success message.
|
|
|
|
| 23 |
st.sidebar.markdown("### Current Pollutant Concentrations and WHO Guidelines")
|
| 24 |
st.sidebar.dataframe(merged_data_df, hide_index=True)
|
| 25 |
|
| 26 |
+
def data_not_available(self) -> None:
|
| 27 |
+
"""
|
| 28 |
+
Show an error message indicating that data is not available.
|
| 29 |
+
|
| 30 |
+
This is shown when the current time is between 00:00 and 04:15, when the measurements aren't accurate enough to produce a prediction.
|
| 31 |
+
The data will be automatically updated at 04:15 with the prediction for the next three days.
|
| 32 |
+
"""
|
| 33 |
+
st.markdown("### Data Not Available")
|
| 34 |
+
|
| 35 |
+
error_message = "🚨 Between 00:00 and 04:15, the measurements aren't accurate enough to produce a prediction or have an informative summary for today's air pollution. The data will be automatically updated at 04:15 with the prediction for the next three days."
|
| 36 |
+
|
| 37 |
+
self.two_columns_layout(0.7, lambda: st.error(error_message), lambda: None)
|
| 38 |
+
|
| 39 |
def success(self, message: str) -> None:
|
| 40 |
"""
|
| 41 |
Show a success message.
|