Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refact: Time stamp functionality of class bf.streams.Instance #878 #879

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/mlpro/bf/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
## -- to avoid collisions)
## -- 2023-03-25 1.1.1 DA Class EventManager: correction in constructor
## -- 2023-11-17 1.2.0 DA Class Event: new time stamp functionality
## -- 2023-11-18 1.2.1 DA Class Event: time stamp is set to now() if not provided
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.2.0 (2023-11-17)
Ver. 1.2.1 (2023-11-18)

This module provides classes for event handling. To this regard, the property class Eventmanager is
provided to add event functionality to child classes by inheritence.
Expand Down Expand Up @@ -44,7 +45,12 @@ class Event (TStamp):
## -------------------------------------------------------------------------------------------------
def __init__(self, p_raising_object, p_tstamp:datetime = None, **p_kwargs):
self._raising_object = p_raising_object
TStamp.__init__(self, p_tstamp = p_tstamp)

if p_tstamp is None:
TStamp.__init__(self, p_tstamp = datetime.now())
else:
TStamp.__init__(self, p_tstamp = p_tstamp)

self._data = p_kwargs


Expand Down
26 changes: 12 additions & 14 deletions src/mlpro/bf/streams/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@
## -- - removed own method get_id()
## -- - constructor: keep value of internal attribute C_NAME if p_name = ''
## -- 2023-04-16 1.2.3 DA Method StreamTask._run(): completed parameter types
## -- 2023-11-17 1.3.0 DA Refactoring class Instance:
## -- - removed individual implementation of time stamp functionality
## -- - added parent class bf.various.TStamp
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.2.3 (2023-04-16)
Ver. 1.3.0 (2023-11-17)

This module provides classes for standardized stream processing.
"""
Expand Down Expand Up @@ -96,7 +99,7 @@ class Label (Dimension): pass

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class Instance:
class Instance (TStamp):
"""
Instance class to store the current instance and the corresponding labels of the stream

Expand All @@ -106,7 +109,7 @@ class Instance:
Feature data of the instance.
p_label_data : Element
Optional label data of the instance.
p_time_stamp : datetime
p_tstamp : datetime
Optional time stamp of the instance.
p_kwargs : dict
Further optional named parameters.
Expand All @@ -118,12 +121,12 @@ class Instance:
def __init__( self,
p_feature_data : Element,
p_label_data : Element = None,
p_time_stamp : datetime = None,
p_tstamp : datetime = None,
**p_kwargs ):

self._feature_data = p_feature_data
self._label_data = p_label_data
self._time_stamp = p_time_stamp
TStamp.__init__(self, p_tstamp=p_tstamp)
self._kwargs = p_kwargs.copy()


Expand Down Expand Up @@ -157,22 +160,17 @@ def set_label_data(self, p_label_data:Element):
self._label_data = p_label_data


## -------------------------------------------------------------------------------------------------
def get_time_stamp(self):
return self._time_stamp


## -------------------------------------------------------------------------------------------------
def get_kwargs(self):
return self._kwargs


## -------------------------------------------------------------------------------------------------
def copy(self):
duplicate = self.__class__( p_feature_data=self._feature_data.copy(),
p_label_data=self._label_data,
duplicate = self.__class__( p_feature_data=self.get_feature_data().copy(),
p_label_data=self.get_label_data(),
p_tstamp=self.get_tstamp(),
p_kwargs=self._kwargs )
duplicate._time_stamp = self._time_stamp
duplicate.set_id(self.get_id())
return duplicate

Expand Down Expand Up @@ -1440,7 +1438,7 @@ def _update_plot_nd( self,
if self._plot_nd_plots is None:

# 2.1 Check whether x label needs to be changed to time index
if ( self._plot_nd_xlabel == self.C_PLOT_ND_XLABEL_INST ) and ( inst_ref.get_time_stamp() is not None ):
if ( self._plot_nd_xlabel == self.C_PLOT_ND_XLABEL_INST ) and ( inst_ref.get_tstamp() is not None ):
p_settings.axes.set_xlabel(self.C_PLOT_ND_XLABEL_TIME)

# 2.2 Add plot for each feature
Expand Down
4 changes: 2 additions & 2 deletions src/mlpro/bf/streams/tasks/deriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _derive_data(self, p_inst:Instance):
except:
l_data_new = None

if p_inst.get_time_stamp() is not None:
t_values_old = p_inst.get_time_stamp()
if p_inst.get_tstamp() is not None:
t_values_old = p_inst.get_tstamp()
else:
t_values_old = None

Expand Down
10 changes: 2 additions & 8 deletions src/mlpro/bf/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@
## -- - logging
## -- 2023-04-12 2.1.1 MRD Safe guarding open file with "with"
## -- 2023-06-01 2.1.2 SY Scientific Referencing to bibtex format
## -- 2023-11-17 2.2.0 DA Class TStamp: if a time stamp is not handed over it will
## -- internally set to now()
## -------------------------------------------------------------------------------------------------

"""
Ver. 2.2.0 (2023-11-17)
Ver. 2.1.2 (2023-06-01)

This module provides various classes with elementry functionalities for reuse in higher level classes.
For example: logging, persistence, timer...
Expand Down Expand Up @@ -661,13 +659,9 @@ class TStamp:
This class provides elementry time stamp functionality for inherited classes.
"""


## -------------------------------------------------------------------------------------------------
def __init__(self, p_tstamp: timedelta = None):
if p_tstamp is None:
self.set_tstamp(datetime.now())
else:
self.set_tstamp(p_tstamp)
self.set_tstamp(p_tstamp)


## -------------------------------------------------------------------------------------------------
Expand Down