streamlit_src.controllers package

Submodules

streamlit_src.controllers.admin_controller module

class streamlit_src.controllers.admin_controller.AdminController[source]

Bases: UserController

A class to handle the admin interface. Inherits from UserController

_check_data_out_of_distribution(input_data: DataFrame, threshold: float = 3) bool[source]

Checks if the input data is out of distribution compared to the training data. Displays which features exceed the threshold.

Parameters:
  • data (pd.DataFrame) – The new input data to validate.

  • threshold (float) – The Z-score threshold to determine out of distribution.

Returns:

True if the input data is out of distribution, False otherwise.

Return type:

bool

_compute_distribution_statistics() Tuple[DataFrame, DataFrame][source]

Computes the means and standard deviations of the features in the dataset.

Returns:

A tuple of two DataFrames. The first DataFrame contains the means of the features

and the second DataFrame contains the standard deviations of the features.

_data_is_valid(data: DataFrame) bool[source]

Performs data validation on the uploaded user data.

Parameters:

data (pd.DataFrame) – The user data.

Returns:

True if the data is valid, otherwise False.

Return type:

bool

_feature_importance() Tuple[list, list][source]

Retrieves the feature importance values and their corresponding feature names.

Returns:

A tuple containing the feature names and their importance values.

Return type:

Tuple[list, list]

_make_custom_predictions() None[source]

Makes a custom prediction for the admin interface.

_make_prediction(data: DataFrame) DataFrame[source]

Makes a prediction using an XGBoost model.

Parameters:

data (pd.DataFrame) – The data to make the prediction on.

Returns:

The prediction.

Return type:

pd.DataFrame

_model_metrics() None[source]

Computes the metrics for the admin interface.

_show_current_data() None[source]

Shows the current data on the main page of the user interface.

show_dashboard() None[source]

Shows the main page of the admin interface.

streamlit_src.controllers.home_controller module

class streamlit_src.controllers.home_controller.HomeController[source]

Bases: object

Handles the logic for the home page, including switching between user and admin views.

The home page is the main entry point for the Streamlit application. It contains a text input for the admin password, which is hashed and compared to the stored hash. If the password is correct, the user is logged in as an admin and the admin view is displayed. Otherwise, the user view is displayed.

__ADMIN_PASSWORD_HASH = '240be518fabd2724ddb6f04eeb1da5967448d7e831c08c8fa822809f74c720a9'
_hash_password(password: str) str[source]

Hash the input password using SHA-256.

_run() None[source]

Runs the application logic for the home page.

This method is responsible for rendering the home page and handling the user’s choice of whether to view the user dashboard or admin dashboard. If the user chooses to view the admin dashboard, the user is prompted to enter the admin password. If the password is valid, the user is logged in as an admin and the admin dashboard is displayed. If the password is invalid, the user is logged out and the user dashboard is displayed.

streamlit_src.controllers.user_controller module

class streamlit_src.controllers.user_controller.UserController[source]

Bases: object

A class to handle the user interface.

_compare_to_who() list[source]

Compare the current pollutant levels to WHO guidelines.

Returns:

A list of tuples containing the pollutant name, comparison message, and message type.

Return type:

list

_create_gauge_plot(value: float, guideline: float, title: str) Figure[source]

Create a gauge plot for a given pollutant value and guideline.

Parameters:
  • value (float) – The pollutant concentration value.

  • guideline (float) – The WHO guideline value for the pollutant.

  • title (str) – The title of the gauge plot.

Returns:

A Plotly figure representing the gauge plot.

Return type:

go.Figure

_display_compare_who() None[source]

Displays the WHO comparison on the main page of the user interface.

_display_plots() None[source]

Displays the plots on the main page of the user interface.

_display_sources() None[source]

Displays the sources on the main page of the user interface.

_get_color(value: float, who_limit: float) str[source]

Calculate a color based on a given pollutant value and WHO guideline.

Parameters:
  • value (float) – The pollutant concentration value.

  • who_limit (float) – The WHO guideline value for the pollutant.

Returns:

A hex color code representing the calculated color.

Return type:

str

_get_next_three_days_dates() tuple[source]

Get the next three days’ dates.

Returns:

A tuple of three date objects.

Return type:

tuple

_is_current_data_available() bool[source]

Checks if the current data is available.

The current data is not available from 00:00 to 04:15. This is because the API is queried every 15 minutes, and the data is not available for a short period of time before and after the new data is fetched.

Returns:

True if the current data is available, False otherwise.

_prepare_awareness_content() Tuple[str, List[Tuple[str, str]], Dict[str, str]][source]

Prepare awareness content including a random fact, expanders, and health message based on air quality data.

Returns:

A tuple containing the random fact, awareness expanders, and health message.

Return type:

Tuple[str, List[Tuple[str, str]], Dict[str, str]]

_prepare_data_for_view() DataFrame[source]

Prepares the current data for the view.

Returns:

The current data in a pandas DataFrame.

Return type:

pd.DataFrame

_prepare_gauge_plots() list[source]

Prepare gauge plots for the next three days’ NO2 and O3 levels.

Returns:

A list of tuples containing the day index, formatted date, and two plotly figures (for NO2 and O3).

Return type:

list

_prepare_line_plot() Figure[source]

Prepare a line plot for the next three days’ NO2 and O3 levels.

Returns:

A plotly figure object.

Return type:

go.Figure

_quiz() None[source]

Show a _quiz question and return the answer and whether the answer was correct.

Returns:

A tuple containing the answer and a boolean indicating whether the answer was correct.

Return type:

tuple

_raise_awareness() None[source]

Shows the awareness content on the main page of the user interface.

_show_current_data() None[source]

Shows the current data on the main page of the user interface.

show_dashboard() None[source]

Shows the main page of the user interface.

Module contents