ssb_dash_framework.utils package

ssb_dash_framework.utils.alert_handler module

class AlertHandler

Bases: object

Manages alerts for the application.

This class provides functionality for: - Displaying a modal with all alerts, which can be filtered and dismissed. - Showing ephemeral alerts at the top-middle of the screen for 4 seconds without removing them from the store.

callbacks()

Registers Dash callbacks for the AlertHandler functionality.

This method defines callbacks for: - Toggling the alert modal. - Setting the alert filter based on user input. - Displaying alerts in the modal, filtered by type. - Removing dismissed alerts from the store. - Displaying ephemeral alerts.

Return type:

None

Notes

  • Alerts must be added to each callback to ensure proper functionality.

layout()

Creates the layout for the AlertHandler.

The layout includes: - dcc.Store components for storing all alerts and the current filter. - A fixed container for displaying ephemeral alerts. - An interval component to drive ephemeral updates. - A modal with filter buttons and a dismissable alert container. - A button to open the modal.

Returns:

A Dash HTML Div component containing the layout for the AlertHandler.

Return type:

html.Div

create_alert(message, color='info', ephemeral=False)

Creates a standardized alert record.

Parameters:
  • message (str) – The alert message to display.

  • color (str, optional) – The color of the alert, typically ‘info’, ‘warning’, or ‘danger’. Defaults to ‘info’.

  • ephemeral (bool, optional) – If True, the alert appears at the top-center for 4 seconds but remains in the store for the modal. Defaults to False.

Returns:

A dictionary containing the alert details, including timestamp, message, color, and ephemeral status.

Return type:

dict[str, Any]

ssb_dash_framework.utils.debugger_modal module

class DebugInspector(inputs, states, func=<function DebugInspector.default_func>)

Bases: object

DebugInspector is a class that creates a modal for debugging purposes.

It displays the inputs and states passed to the class, as well as the arguments passed to the function. It also provides a toggle button to open and close the modal.

Parameters:
  • inputs (list[str])

  • states (list[str])

  • func (Callable[[...], Any])

callbacks()

Set up the callbacks for the DebugInspector modal.

It includes a toggle button to open and close the modal, and a function to display the inputs and states passed to the class.

Return type:

None

default_func()

Default function to be called when the debugger is triggered.

It simply returns the arguments passed to it as a Plaintext object.

Return type:

Plaintext

Parameters:

args (Any)

layout()

Create the layout for the DebugInspector modal.

Returns:

The layout for the DebugInspector modal.

Return type:

html.Div

ssb_dash_framework.utils.functions module

format_timespan(start, end)

Formats the elapsed time between two time points into a human-readable string.

Parameters:
  • start (int | float) – Start time in seconds, typically as a timestamp or relative value.

  • end (int | float) – End time in seconds, typically as a timestamp or relative value.

Returns:

A formatted string representing the elapsed time between start and end. The format is “MM:SS.sss (sss ms)”, where: - MM is minutes, zero-padded to 2 digits. - SS.sss is seconds with 2 decimal places. - sss ms represents milliseconds.

Return type:

str

Raises:

ValueError – If start is greater than end.

hb_method(data, p_c, p_u, p_a, id_field_name='id', x_1_field_name='x1', x_2_field_name='x2')

Runs the Hb method from the R package Kostra.

Parameters:
  • data (DataFrame) – The data to run the method on

  • p_c (int) – The value of pC

  • p_u (float) – The value of pU

  • p_a (float) – The value of pA

  • id_field_name (str) – The name of the id field

  • x_1_field_name (str) – The name of the first x field

  • x_2_field_name (str) – The name of the second x field

Return type:

DataFrame

Returns:

The result of the method

sidebar_button(icon, text, component_id, additional_styling=None)

Generate a sidebar button with an icon and label.

Parameters:
  • icon (str) – The icon displayed at the top of the button.

  • text (str) – The label text displayed below the icon.

  • component_id (str) – The ID assigned to the button component.

  • additional_styling (dict, optional) – Additional styling applied to the button. Defaults to an empty dictionary.

Returns:

A Div containing the styled button.

Return type:

html.Div

th_error(data, id_field_name, x_1_field_name, x_2_field_name)

Runs the ThError method from the R package Kostra.

Parameters:
  • data (DataFrame) – The data to run the method on

  • id_field_name (str) – The name of the id field

  • x_1_field_name (str) – The name of the first x field

  • x_2_field_name (str) – The name of the second x field

Return type:

DataFrame

Returns:

The result of the method

ssb_dash_framework.utils.implementations module

class TabImplementation

Bases: object

A mixin class to implement a module inside a tab.

Dependencies:
  • self.label (str): The label for the tab.

  • self.module_name (str): The name of the module, used for generating unique IDs.

  • self.module_layout (html.Div): The layout to display inside the tab.

Note

  • This class should be used as a mixin in a module class.

  • If necessary, you can override the get_module_layout method to further customize the layout inside the tab.

get_module_layout()

Get the layout of the module.

Works as is, but can be overridden if needed.

Return type:

Div

label: str
layout()

Generate the layout for the module as a tab.

Returns:

The layout containing the module layout.

Return type:

html.Div

module_layout: Div
module_name: str
class TabModule(*args, **kwargs)

Bases: Protocol

A protocol that defines the expected interface for a module to be used in a tab.

label

The label for the tab.

Type:

str

module_name

The name of the module, used for generating unique IDs.

Type:

str

module_layout

The layout to display inside the tab.

Type:

html.Div

layout() dbc.Tab

Returns the layout of the module inside a tab.

Return type:

Tab

label: str
layout()

This method should return the layout of the module inside a tab.

Return type:

Tab

module_layout: Div
module_name: str
class WindowImplementation

Bases: object

A mixin class to implement a module inside a modal.

Dependencies:
  • self.label (str): The label for the modal and sidebar button.

  • self.module_name (str): The name of the module, used for generating unique IDs.

  • self.module_layout (html.Div): The layout to display inside the modal.

Note

  • This class should be used as a mixin in a module class.

  • If necessary, you can override the get_module_layout method to further customize the layout inside the modal.

get_module_layout()

Get the layout of the module.

Works as is, but can be overridden if needed.

Return type:

Div

label: str
layout()

Generate the layout for the modal window.

This method creates a modal window with a header and a body containing the module layout. It also creates a sidebar button to toggle the modal.

Returns:

The layout containing the modal and the sidebar button.

Return type:

html.Div

module_layout: Div
module_name: str
window_callbacks()

Define the callbacks for the module window.

This includes a callback to toggle the visibility of the modal window.

Return type:

None

class WindowModule(*args, **kwargs)

Bases: Protocol

A protocol that defines the expected interface for a module to be used in a window.

label

The label for the window.

Type:

str

module_name

The name of the module, used for generating unique IDs.

Type:

str

module_layout

The layout to display inside the window.

Type:

html.Div

layout() html.Div

Returns the layout of the module inside a window.

Return type:

Div

label: str
layout()

This method should return the layout of the module inside a window.

Return type:

Div

module_layout: Div
module_name: str