diff options
Diffstat (limited to 'src/argaze/TobiiGlassesPro2/TobiiEntities.py')
-rw-r--r-- | src/argaze/TobiiGlassesPro2/TobiiEntities.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/argaze/TobiiGlassesPro2/TobiiEntities.py b/src/argaze/TobiiGlassesPro2/TobiiEntities.py index c5a7055..17cd29f 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiEntities.py +++ b/src/argaze/TobiiGlassesPro2/TobiiEntities.py @@ -29,8 +29,9 @@ TOBII_SEGMENT_DATA_FILENAME = "livedata.json.gz" class TobiiSegment: """Handle Tobii Glasses Pro 2 segment info.""" - def __init__(self, segment_path): - """Load segment info from segment directory.""" + def __init__(self, segment_path, start_timestamp:int = 0, end_timestamp:int = None): + """Load segment info from segment directory. + Optionnaly select a time range in microsecond.""" self.__segment_id = os.path.basename(segment_path) self.__segment_path = segment_path @@ -41,8 +42,14 @@ class TobiiSegment: except: raise RuntimeError(f'JSON fails to load {self.__segment_path}/{TOBII_SEGMENT_INFO_FILENAME}') - self.__length_us = int(item["seg_length_us"]) + self.__start_timestamp = start_timestamp + self.__end_timestamp = min(end_timestamp, int(item["seg_length_us"])) if end_timestamp != None else int(item["seg_length_us"]) + + if self.__start_timestamp >= self.__end_timestamp: + raise ValueError('start time is equal or greater than end time.') + self.__calibrated = bool(item["seg_calibrated"]) + self.__start_date = datetime.datetime.strptime(item["seg_t_start"], TOBII_DATETIME_FORMAT) self.__stop_date = datetime.datetime.strptime(item["seg_t_stop"], TOBII_DATETIME_FORMAT) @@ -52,8 +59,11 @@ class TobiiSegment: def get_id(self): return self.__segment_id - def get_length_us(self): - return self.__length_us + def get_start_timestamp(self): + return self.__start_timestamp + + def get_end_timestamp(self): + return self.__end_timestamp def get_start_date(self): return self.__start_date @@ -65,10 +75,10 @@ class TobiiSegment: return self.__calibrated def load_data(self): - return TobiiData.TobiiDataSegment(os.path.join(self.__segment_path, TOBII_SEGMENT_DATA_FILENAME)) + return TobiiData.TobiiDataSegment(os.path.join(self.__segment_path, TOBII_SEGMENT_DATA_FILENAME), self.__start_timestamp, self.__end_timestamp) def load_video(self): - return TobiiVideo.TobiiVideoSegment(os.path.join(self.__segment_path, TOBII_SEGMENT_VIDEO_FILENAME)) + return TobiiVideo.TobiiVideoSegment(os.path.join(self.__segment_path, TOBII_SEGMENT_VIDEO_FILENAME), self.__start_timestamp, self.__end_timestamp) class TobiiRecording: """Handle Tobii Glasses Pro 2 recording info and segments.""" |