Helpers
Ver. 0.3.1 (2025-07-18)
This module provides the ChangeObserver class to be used for observation and visualization of stream adaptation events.
- class mlpro.oa.streams.helpers.change_observer.ChangeObserver(p_related_task: OAStreamTask, p_no_per_task: int = 0, p_annotation: str = None, p_window_title: str = None, p_change_event_ids: list = [], p_logarithmic_plot: bool = True, p_visualize: bool = True, p_logging=True, **p_kwargs)
Bases:
StreamTaskHelperThis class observes adaptations of particular oa stream tasks. Its event handler method can be registered for adaptation events of a stream task.
- Parameters:
p_related_task (OAStreamTask) – The stream task to be observed.
p_no_per_task (int = 0) – Helper number of the task. This is used to distinguish between multiple helpers for the same task.
p_annotation (str = None) – Optional annotation for the helper.
p_window_title (str = None) – Optional window title for the helper. If None, a default title is generated.
p_change_event_ids (list) – List of change event ids to be observed. Each entry can be a string or a tuple of (event_id, color).
p_logarithmic_plot (bool = True) – If True, the y-axis of the plot is logarithmic.
p_visualize (bool) – If True, the plot is visualized.
p_logging (int) – Logging level for this helper. Default is Log.C_LOG_ALL.
p_kwargs (dict) – Further keyword arguments for the helper.
- C_TYPE = 'Helper'
- C_NAME = 'Event Observer'
- C_PLOT_ACTIVE: bool = True
- C_PLOT_STANDALONE: bool = True
- C_PLOT_VALID_VIEWS: list = ['ND']
- C_PLOT_DEFAULT_VIEW: str = 'ND'
- C_ANOMALY_COLORS = ['blue', 'red', 'green', 'purple', 'yellow', 'orange']
- _event_handler(p_event_id, p_event_object: Change)
Template event handler for task related events. This method is called by the task when an event is raised and can be redefined in a child class.
- Parameters:
p_event_id – ID of the event.
p_event_object (Event) – Event object that contains the raising task and further information.
- init_plot(p_figure=None, p_plot_settings: PlotSettings = None, p_window_title: str = None) bool
Initializes the plot functionalities of the class.
- Parameters:
p_figure (Matplotlib.figure.Figure, optional) – Optional MatPlotLib host figure, where the plot shall be embedded. The default is None.
p_plot_settings (PlotSettings) – Optional plot settings. If None, the default view is plotted (see attribute C_PLOT_DEFAULT_VIEW).
- _init_plot_nd(p_figure, p_settings: PlotSettings)
Custom method to initialize a nD plot. If attribute p_settings.axes is not None the initialization shall be done there. Otherwise a new MatPlotLib Axes object shall be created in the given figure and stored in p_settings.axes.
Note: Please call this method in your custom implementation to create a default subplot.
- Parameters:
p_figure (Matplotlib.figure.Figure) – Matplotlib figure object to host the subplot(s).
p_settings (PlotSettings) – Object with further plot settings.
- _update_plot_nd(p_settings: PlotSettings, p_event_object: Change, **p_kwargs) bool
Custom method to update the nd plot. The related MatPlotLib Axes object is stored in p_settings.
- Parameters:
p_settings (PlotSettings) – Object with further plot settings.
**p_kwargs – Implementation-specific data and parameters.
- Returns:
True, if changes on the plot require a refresh of the figure. False otherwise.
- Return type:
bool