utils
GONet Wizard Utility Functions.
This module provides reusable functions for plotting, filtering, statistical analysis, and layout generation within the GONet Wizard dashboard application. These functions support the construction of Dash figures, dynamic filter UI elements, and filter logic used in the callback system.
Dash components from dash and dash_daq are used to construct UI elements dynamically.
Functions
debug()
: debugging.sort_figure()
: Reorders the traces in a Plotly figure based on filtering and highlight status.get_labels()
: Extracts the axis label text from a Plotly figure layout.plot_scatter()
: Update a Plotly figure by adding scatter traces for selected and filtered data.plot_big_points()
: Highlight a selected point in the scatter plot by adding enlarged “big point” markers.get_stats()
: Compute summary statistics (mean and standard deviation) for plotted x and y values.new_empty_filter()
: Create a Dash component representing an empty primary filter block.new_empty_second_filter()
: Create a Dash component block representing a secondary (OR) filter.new_selection_filter()
: Create a Dash component for a selection-based filter using manually selected points.
Functions:
- GONet_Wizard.GONet_dashboard.src.utils.debug_print(callback_fn)[source]
Decorator that logs when a Dash callback is triggered, including the triggering component ID and source line.
This decorator is useful for debugging and tracing which callbacks are being executed during development. Logging only occurs when the
WERKZEUG_RUN_MAIN
environment variable is set to “true”, which ensures the message is printed only by the reloader’s main process.- Parameters:
callback_fn (callable) – The Dash callback function to wrap.
- Returns:
The wrapped function that logs on invocation and then calls the original function.
- Return type:
callable
- GONet_Wizard.GONet_dashboard.src.utils.gonet_callback(*args, **kwargs)[source]
Custom Dash callback decorator that extends the original callback with automatic alert handling, debug logging, and error state protection.
This decorator automatically appends three additional outputs for managing an alert container:
alert-container.children (message content)
alert-container.className (CSS class for styling)
alert-container.style (visibility/display logic)
It also adds one hidden State:
alert-container.className (used to suppress execution if an error is already active)
The wrapped callback will: - Suppress execution if the alert container is currently showing an error (“alert-box error”). - Capture and display any warnings issued during execution. - Catch exceptions and display a red alert box with the error message. - Log a message when the callback is triggered, including the triggering component (if WERKZEUG_RUN_MAIN == “true”).
- Parameters:
*args (dash.Output, dash.Input, dash.State) – Positional arguments defining the Dash callback’s outputs, inputs, and states. All initial Output(…) arguments are treated as actual user outputs.
**kwargs (dict) – Additional keyword arguments passed to Dash’s app.callback.
- Returns:
The decorated function registered as a Dash callback.
- Return type:
callable
- GONet_Wizard.GONet_dashboard.src.utils.parse_date_time(label, value)[source]
Parses and converts a date/time value based on the provided label.
This function processes a given date/time value and returns it in a standardized format. Depending on the label, it either converts an ISO datetime string to Unix time or a time string (hours:minutes:seconds) to a fraction of the day. If the label corresponds to ‘date’, the value is converted to Unix time. If the label corresponds to ‘hours’, the value is converted to a fraction of the day, accounting for potential time zone shifts.
Parameters:
Returns:
: tuple
A tuple containing the processed label and the parsed value:
If the label starts with ‘date’, the value will be the corresponding Unix time as an integer.
If the label starts with ‘hours’, the value will be a float representing the fraction of the day.
If the time is earlier than the defined ‘day start’ (UTC or local), the function will adjust the value to the following day.
Raises:
- ValueError
If the ‘value’ cannot be parsed into a valid datetime or time string, the function will print an error message and return None.
- GONet_Wizard.GONet_dashboard.src.utils.new_empty_filter(idx, labels)[source]
Create a Dash component representing an empty primary filter block.
This function generates a new UI element for a filter container, including: - A toggle switch to activate the filter - Dropdowns for selecting the data field and comparison operator - An input box for entering the comparison value - A button to optionally add a secondary (OR) filter
- GONet_Wizard.GONet_dashboard.src.utils.new_empty_second_filter(idx, labels)[source]
Create a Dash component block representing a secondary (OR) filter.
This function returns a list of Dash components corresponding to a secondary filter UI. It includes a label (“OR”), a dropdown for field selection, a dropdown for the operator, and an input field for the value.
- GONet_Wizard.GONet_dashboard.src.utils.new_selection_filter(idx, selected_indexes)[source]
Create a Dash component for a selection-based filter using manually selected points.
This function generates a filter UI tied to a lasso or box selection on the plot. It includes a toggle switch, a dropdown preset to the selection label, a hidden data store with the selected indices, and a dropdown to choose inclusion or exclusion.