aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2024-04-03 15:00:57 +0200
committerThéo de la Hogue2024-04-03 15:00:57 +0200
commit3370c067bac219c5310ba15cf2f6d98a8a8259b9 (patch)
tree5dddbbaac4b23019aadb9af4f4e910500fe8cfbc
parentcb3883ccdae38609517bdac3b01947f6200b91ab (diff)
downloadargaze-3370c067bac219c5310ba15cf2f6d98a8a8259b9.zip
argaze-3370c067bac219c5310ba15cf2f6d98a8a8259b9.tar.gz
argaze-3370c067bac219c5310ba15cf2f6d98a8a8259b9.tar.bz2
argaze-3370c067bac219c5310ba15cf2f6d98a8a8259b9.tar.xz
Logging class path. Initializing PipelineStepObject once.
-rw-r--r--src/argaze/ArFeatures.py4
-rw-r--r--src/argaze/DataFeatures.py53
-rw-r--r--src/argaze/utils/UtilsFeatures.py10
-rw-r--r--src/argaze/utils/contexts/TobiiProGlasses2.py20
-rw-r--r--src/argaze/utils/demo/recorders.py8
5 files changed, 50 insertions, 45 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py
index b29136b..3b05482 100644
--- a/src/argaze/ArFeatures.py
+++ b/src/argaze/ArFeatures.py
@@ -1457,7 +1457,7 @@ class ArContext(DataFeatures.PipelineStepObject):
# Compare image size with ArCamera frame size
if list(image.shape[0:2][::-1]) != self.__pipeline.size:
- logging.warning('%s._process_camera_image: image size (%i x %i) is different of ArCamera frame size (%i x %i)', type(self).__name__ , width, height, self.__pipeline.size[0], self.__pipeline.size[1])
+ logging.warning('%s._process_camera_image: image size (%i x %i) is different of ArCamera frame size (%i x %i)', DataFeatures.get_class_path(self) , width, height, self.__pipeline.size[0], self.__pipeline.size[1])
return
try:
@@ -1471,7 +1471,7 @@ class ArContext(DataFeatures.PipelineStepObject):
except DataFeatures.TimestampedException as e:
- logging.warning('%s._process_camera_image: %s', type(self).__name__, e)
+ logging.warning('%s._process_camera_image: %s', DataFeatures.get_class_path(self), e)
self.__exceptions.append(e)
diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py
index e70c1b5..5e5ac08 100644
--- a/src/argaze/DataFeatures.py
+++ b/src/argaze/DataFeatures.py
@@ -664,7 +664,7 @@ def PipelineStepEnter(method):
def wrapper(self):
"""Wrap pipeline step __enter__ method to call super, observers and children __enter__ method."""
- logging.debug('%s.__enter__', type(self).__name__)
+ logging.debug('%s.__enter__', get_class_path(self))
method(self)
@@ -678,7 +678,7 @@ def PipelineStepExit(method):
def wrapper(self, *args):
"""Wrap pipeline step __exit__ method to call super, observers and children __exit__ method."""
- logging.debug('%s.__exit__', type(self).__name__)
+ logging.debug('%s.__exit__', get_class_path(self))
PipelineStepObject.__exit__(self, *args)
@@ -712,7 +712,7 @@ def PipelineStepAttributeSetter(method):
raise(PipelineStepLoadingFailed(f'Annotations are missing for {method.__name__}: {method.__annotations__}'))
- logging.debug('%s@%s.setter', type(self).__name__, method.__name__)
+ logging.debug('%s@%s.setter', get_class_path(self), method.__name__)
logging.debug('\t> set %s with %s', expected_value_type.__name__, new_value_type.__name__)
# String not expected: load value from file
@@ -811,23 +811,28 @@ class PipelineStepObject():
Define class to assess pipeline step methods execution time and observe them.
"""
+ __initialized = False
+
def __init__(self):
"""Initialize PipelineStepObject."""
- logging.debug('%s.__init__', type(self).__name__)
+ if not self.__initialized:
- # Init private attributes
- self.__name = None
- self.__observers = []
- self.__execution_times = {}
- self.__image_parameters = {}
+ logging.debug('%s.__init__', get_class_path(self))
- # Init protected attributes
- self._image_parameters = {}
- self._draw_parameters = {}
-
- # Parent attribute will be setup later by parent it self
- self.__parent = None
+ # Init private attributes
+ self.__initialized = True
+ self.__name = None
+ self.__observers = []
+ self.__execution_times = {}
+ self.__image_parameters = {}
+
+ # Init protected attributes
+ self._image_parameters = {}
+ self._draw_parameters = {}
+
+ # Parent attribute will be setup later by parent it self
+ self.__parent = None
def __enter__(self):
"""Define default method to enter into pipeline step object context."""
@@ -854,13 +859,13 @@ class PipelineStepObject():
if hasattr(self, key):
- logging.debug('%s.update_attributes > update %s with %s value', type(self).__name__, key, type(value).__name__)
+ logging.debug('%s.update_attributes > update %s with %s value', get_class_path(self), key, type(value).__name__)
setattr(self, key, value)
else:
- raise(AttributeError(f'{type(self).__name__} has not {key} attribute.'))
+ raise(AttributeError(f'{get_class_path(self)} has not {key} attribute.'))
@property
def name(self) -> str:
@@ -956,7 +961,7 @@ class PipelineStepObject():
String representation
"""
- logging.debug('%s.__str__ %s', type(self).__name__, self.name if self.name is not None else '')
+ logging.debug('%s.__str__ %s', get_class_path(self), self.name if self.name is not None else '')
tabs = self.tabulation
output = f'{Fore.GREEN}{Style.BRIGHT}{self.__class__.__module__}.{self.__class__.__name__}{Style.RESET_ALL}\n'
@@ -974,7 +979,7 @@ class PipelineStepObject():
for name, value in self.properties:
- logging.debug('%s.__str__ @property %s (%s)', type(self).__name__, name, type(value).__name__)
+ logging.debug('%s.__str__ @property %s (%s)', get_class_path(self), name, type(value).__name__)
output += f'{tabs}\t{Style.BRIGHT}{name}{Style.RESET_ALL}: '
@@ -1010,9 +1015,9 @@ class PipelineStepObject():
except TypeError as e:
- logging.error('%s.__str__ @property %s (%s)', type(self).__name__, name, type(value).__name__)
+ logging.error('%s.__str__ @property %s (%s)', get_class_path(self), name, type(value).__name__)
- output += f'{Fore.RED}{Style.BRIGHT}!!! {type(self).__name__}.{name}: {e}{Style.RESET_ALL}\n\n'
+ output += f'{Fore.RED}{Style.BRIGHT}!!! {get_class_path(self)}.{name}: {e}{Style.RESET_ALL}\n\n'
if output[-1] != '\n':
@@ -1065,7 +1070,7 @@ class PipelineStepObject():
attr = getattr(self, name)
# Pipeline step object attribute
- if isinstance(attr, PipelineStepObject) and attr != self.parent:
+ if issubclass(type(attr), PipelineStepObject) and attr != self.parent:
yield attr
@@ -1074,7 +1079,7 @@ class PipelineStepObject():
for p in attr:
- if isinstance(p, PipelineStepObject):
+ if issubclass(type(p), PipelineStepObject):
yield p
@@ -1102,7 +1107,7 @@ def PipelineStepMethod(method):
else:
- logging.error('%s.%s: %s is not a TimestampedObject subclass. You must pass a timestamp argument.', type(self).__name__, method.__name__, type(args[0]).__name__)
+ logging.error('%s.%s: %s is not a TimestampedObject subclass. You must pass a timestamp argument.', get_class_path(self), method.__name__, type(args[0]).__name__)
if unwrap:
diff --git a/src/argaze/utils/UtilsFeatures.py b/src/argaze/utils/UtilsFeatures.py
index f24c562..f38d041 100644
--- a/src/argaze/utils/UtilsFeatures.py
+++ b/src/argaze/utils/UtilsFeatures.py
@@ -252,20 +252,20 @@ class FileWriter(DataFeatures.PipelineStepObject):
"""Close file."""
self.__file.close()
- def write(self, log: str|tuple):
- """Write log as a new line into file.
+ def write(self, data: str|tuple):
+ """Write data as a new line into file.
!!! note
Tuple elements are converted into quoted strings separated by separator string.
"""
# Format list or tuple element into quoted strings
- if not isinstance(log, str):
+ if not isinstance(data, str):
- log = tuple_to_string(log, self.__separator)
+ data = tuple_to_string(data, self.__separator)
# Write into file
- print(log, file=self.__file, flush=True)
+ print(data, file=self.__file, flush=True)
class VideoWriter(DataFeatures.PipelineStepObject, DataFeatures.SharedObject):
"""Open ffmpeg application as sub-process.
diff --git a/src/argaze/utils/contexts/TobiiProGlasses2.py b/src/argaze/utils/contexts/TobiiProGlasses2.py
index a51d325..c051f7f 100644
--- a/src/argaze/utils/contexts/TobiiProGlasses2.py
+++ b/src/argaze/utils/contexts/TobiiProGlasses2.py
@@ -569,7 +569,7 @@ class LiveStream(ArFeatures.ArContext):
@DataFeatures.PipelineStepExit
def __exit__(self, exception_type, exception_value, exception_traceback):
- logging.debug('%s.__exit__', type(self).__name__)
+ logging.debug('%s.__exit__', DataFeatures.get_class_path(self))
# Close data stream
self.__stop_event.set()
@@ -636,7 +636,7 @@ class LiveStream(ArFeatures.ArContext):
def __stream_data(self):
"""Stream data from dedicated socket."""
- logging.debug('%s.__stream_data', type(self).__name__)
+ logging.debug('%s.__stream_data', DataFeatures.get_class_path(self))
# First timestamp to offset all timestamps
first_ts = 0
@@ -688,7 +688,7 @@ class LiveStream(ArFeatures.ArContext):
def __stream_video(self):
"""Stream video from dedicated socket."""
- logging.debug('%s.__stream_video', type(self).__name__)
+ logging.debug('%s.__stream_video', DataFeatures.get_class_path(self))
# Open video stream
container = av.open(f'rtsp://{self.__address}:8554/live/scene', options={'rtsp_transport': 'tcp'})
@@ -743,7 +743,7 @@ class LiveStream(ArFeatures.ArContext):
def __video_buffer_read(self):
"""Read incoming buffered video images."""
- logging.debug('%s.__video_buffer_read', type(self).__name__)
+ logging.debug('%s.__video_buffer_read', DataFeatures.get_class_path(self))
while not self.__stop_event.is_set():
@@ -782,7 +782,7 @@ class LiveStream(ArFeatures.ArContext):
except Exception as e:
- logging.warning('%s.__video_buffer_read: %s', type(self).__name__, e)
+ logging.warning('%s.__video_buffer_read: %s', DataFeatures.get_class_path(self), e)
# Unlock buffer access
self.__video_buffer_lock.release()
@@ -790,7 +790,7 @@ class LiveStream(ArFeatures.ArContext):
def __keep_alive(self):
"""Maintain network connection."""
- logging.debug('%s.__keep_alive', type(self).__name__)
+ logging.debug('%s.__keep_alive', DataFeatures.get_class_path(self))
while not self.__stop_event.is_set():
@@ -804,7 +804,7 @@ class LiveStream(ArFeatures.ArContext):
url = self.__base_url + api_action
- logging.debug('%s.__get_request %s', type(self).__name__, url)
+ logging.debug('%s.__get_request %s', DataFeatures.get_class_path(self), url)
res = urlopen(url).read()
@@ -816,7 +816,7 @@ class LiveStream(ArFeatures.ArContext):
data = None
- logging.debug('%s.__get_request received %s', type(self).__name__, data)
+ logging.debug('%s.__get_request received %s', DataFeatures.get_class_path(self), data)
return data
@@ -825,7 +825,7 @@ class LiveStream(ArFeatures.ArContext):
url = self.__base_url + api_action
- logging.debug('%s.__post_request %s', type(self).__name__, url)
+ logging.debug('%s.__post_request %s', DataFeatures.get_class_path(self), url)
req = Request(url)
req.add_header('Content-Type', 'application/json')
@@ -1283,7 +1283,7 @@ class PostProcessing(ArFeatures.ArContext):
@DataFeatures.PipelineStepExit
def __exit__(self, exception_type, exception_value, exception_traceback):
- logging.debug('%s.__exit__', type(self).__name__)
+ logging.debug('%s.__exit__', DataFeatures.get_class_path(self))
# Close data stream
self.__stop_event.set()
diff --git a/src/argaze/utils/demo/recorders.py b/src/argaze/utils/demo/recorders.py
index 75bca70..ec3baa3 100644
--- a/src/argaze/utils/demo/recorders.py
+++ b/src/argaze/utils/demo/recorders.py
@@ -29,7 +29,7 @@ class FixationRecorder(UtilsFeatures.FileWriter):
self.header = "Timestamp (ms)", "Focus (px)", "Duration (ms)", "AOI"
- logging.info('%s writes into %s', type(self).__name__, self.path)
+ logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path)
def on_look(self, timestamp, frame, exception):
"""Log frame fixations."""
@@ -54,7 +54,7 @@ class ScanPathAnalysisRecorder(UtilsFeatures.FileWriter):
self.header = "Timestamp (ms)", "Duration (ms)", "Step", "K", "NNI", "XXR"
- logging.info('%s writes into %s', type(self).__name__, self.path)
+ logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path)
def on_look(self, timestamp, frame, exception):
"""Log frame scan path metrics."""
@@ -80,7 +80,7 @@ class VideoRecorder(UtilsFeatures.VideoWriter):
super().__init__(**kwargs)
- logging.info('%s writes into %s', type(self).__name__, self.path)
+ logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path)
def on_look(self, timestamp, frame, exception):
"""Write frame image."""
@@ -95,7 +95,7 @@ class AOIScanPathAnalysisRecorder(UtilsFeatures.FileWriter):
self.header = "Timestamp (ms)", "Duration (ms)", "Step", "K", "LZC"
- logging.info('%s writes into %s', type(self).__name__, self.path)
+ logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path)
def on_look(self, timestamp, layer, exception):
"""Log layer aoi scan path metrics"""