diff options
author | Théo de la Hogue | 2022-04-20 23:55:31 +0200 |
---|---|---|
committer | Théo de la Hogue | 2022-04-20 23:55:31 +0200 |
commit | 1e737db6d146d83f12241a2a162c23a44f92bfa5 (patch) | |
tree | 8b4ea4091d249799d9029bd6bffe5daf74031419 /src | |
parent | 0251deb5d7117f4fa4eb0d4ecf681c924eaf63ec (diff) | |
download | argaze-1e737db6d146d83f12241a2a162c23a44f92bfa5.zip argaze-1e737db6d146d83f12241a2a162c23a44f92bfa5.tar.gz argaze-1e737db6d146d83f12241a2a162c23a44f92bfa5.tar.bz2 argaze-1e737db6d146d83f12241a2a162c23a44f92bfa5.tar.xz |
Exporting timestamped buffer as csv file.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/DataStructures.py | 32 | ||||
-rw-r--r-- | src/argaze/GazeFeatures.py | 2 | ||||
-rw-r--r-- | src/argaze/utils/export_tobii_segment_aruco_visual_scan.py | 10 |
3 files changed, 18 insertions, 26 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py index 146978e..51d245c 100644 --- a/src/argaze/DataStructures.py +++ b/src/argaze/DataStructures.py @@ -9,7 +9,6 @@ class DictObject(): """Convert dictionnary into object""" def __init__(self, object_type = str, **dictionnary): - self.__dict__.update(dictionnary) self.__type = object_type @@ -34,23 +33,17 @@ class DictObject(): class TimeStampedBuffer(collections.OrderedDict): """Ordered dictionary to handle timestamped data. ``` - { - timestamp1: data1, - timestamp2: data2, - ... - } + { + timestamp1: data1, + timestamp2: data2, + ... + } ``` """ - def __new__(cls): + def __new__(cls, args = None): return super(TimeStampedBuffer, cls).__new__(cls) - def __init__(self): - pass - - def __del__(self): - pass - def __setitem__(self, key: float, value): """Force key to be a number""" if type(key) != int and type(key) != float: @@ -114,16 +107,15 @@ class TimeStampedBuffer(collections.OrderedDict): except: raise RuntimeError(f'Can\' write {filepath}') - def export_as_csv(self, filepath): + def export_as_csv(self, filepath, exclude=[]): """Write buffer content into a csv file""" try: - #series = pandas.Series(self) - #print(series) - - df = pandas.DataFrame.from_dict(self, orient='index', columns=['data']) - + df = pandas.DataFrame.from_dict(self.values()) + df.drop(exclude, inplace=True, axis=True) + df['timestamp'] = self.keys() + df.set_index('timestamp', inplace=True) df.to_csv(filepath, index=True) - + except: raise RuntimeError(f'Can\' write {filepath}') diff --git a/src/argaze/GazeFeatures.py b/src/argaze/GazeFeatures.py index 8f16b14..6cdca71 100644 --- a/src/argaze/GazeFeatures.py +++ b/src/argaze/GazeFeatures.py @@ -196,7 +196,7 @@ class VisualScanStep(): """Define a visual scan step as a duration, the name of the area of interest and all its frames during the step.""" duration: float - aoi: str + area: str frames: DataStructures.TimeStampedBuffer class TimeStampedVisualScanSteps(DataStructures.TimeStampedBuffer): diff --git a/src/argaze/utils/export_tobii_segment_aruco_visual_scan.py b/src/argaze/utils/export_tobii_segment_aruco_visual_scan.py index c292967..295a0da 100644 --- a/src/argaze/utils/export_tobii_segment_aruco_visual_scan.py +++ b/src/argaze/utils/export_tobii_segment_aruco_visual_scan.py @@ -51,12 +51,12 @@ def main(): os.makedirs(os.path.dirname(args.output)) print(f'{os.path.dirname(args.output)} folder created') - visual_scan_filepath = f'{args.output}/visual_scan.json' + visual_scan_filepath = f'{args.output}/visual_scan.csv' video_filepath = f'{args.output}/fullstream+visu.mp4' else: - visual_scan_filepath = f'{args.segment_path}/visual_scan.json' + visual_scan_filepath = f'{args.segment_path}/visual_scan.csv' video_filepath = f'{args.segment_path}/fullstream+visu.mp4' # Load a tobii segment @@ -114,7 +114,7 @@ def main(): cv.circle(video_frame.matrix, gaze_position.as_tuple(), 4, (0, 255, 255), -1) # Store gaze position at this time in millisecond - ts_gaze_positions[video_ts] = gaze_position + ts_gaze_positions[video_ts/1000] = gaze_position # When expected values can't be found except (KeyError, AttributeError, ValueError): @@ -155,7 +155,7 @@ def main(): aoi2D_scene.draw(video_frame.matrix) # Store 2D aois scene at this time in millisecond - ts_aois_scenes[video_ts] = aoi2D_scene + ts_aois_scenes[video_ts/1000] = aoi2D_scene # Close window using 'Esc' key if cv.waitKey(1) == 27: @@ -189,7 +189,7 @@ def main(): print(f'{len(visual_scan)} visual scan steps found') # Export visual scan - visual_scan.export_as_json(visual_scan_filepath) + visual_scan.export_as_csv(visual_scan_filepath, exclude=['frames']) print(f'Visual scan saved into {visual_scan_filepath}') |