diff options
-rw-r--r-- | src/argaze/utils/tobii_segment_gaze_metrics_export.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/argaze/utils/tobii_segment_gaze_metrics_export.py b/src/argaze/utils/tobii_segment_gaze_metrics_export.py index 848f119..778e699 100644 --- a/src/argaze/utils/tobii_segment_gaze_metrics_export.py +++ b/src/argaze/utils/tobii_segment_gaze_metrics_export.py @@ -61,7 +61,8 @@ def main(): movements_json_filepath = f'{destination_path}/gaze_movements.json' gaze_status_json_filepath = f'{destination_path}/gaze_status.json' - gaze_metrics_filepath = f'{destination_path}/gaze_metrics.csv' + gaze_metrics_period_filepath = f'{destination_path}/gaze_metrics_{args.period}s.csv' + gaze_metrics_whole_filepath = f'{destination_path}/gaze_metrics.csv' # Load gaze movements ts_fixations = GazeFeatures.TimeStampedGazeMovements.from_json(fixations_json_filepath) @@ -72,7 +73,7 @@ def main(): print(f'\nLoaded gaze movements count:') print(f'\tFixations: {len(ts_fixations)}') print(f'\tSaccades: {len(ts_saccades)}') - print(f'\nMovements: {len(ts_movements)}') + print(f'\tMovements: {len(ts_movements)}') # Load tobii segment tobii_segment = TobiiEntities.TobiiSegment(args.segment_path, int(args.time_range[0] * 1e6), int(args.time_range[1] * 1e6) if args.time_range[1] != None else None) @@ -127,13 +128,10 @@ def main(): # Add 'end' column movements_dataframe['end'] = movements_dataframe.index + movements_dataframe.duration - # Work with period of time in microseconds instead of seconds - period_duration = args.period * 1e6 + # Define a function to export metrics for a period of time + def metrics_for_period(period_start_ts, period_end_ts): - for i in range(0, int(tobii_segment_video.duration/period_duration)): - - period_start_ts = i*period_duration - period_end_ts = (i+1)*period_duration + period_duration = period_end_ts - period_start_ts period_metrics = {} #print(f'\n*** Anaysing period n°{i} [{period_start_ts * 1e-6:.3f}s, {period_end_ts * 1e-6:.3f}s]') @@ -226,10 +224,25 @@ def main(): # Append period metrics ts_metrics[int(period_start_ts * 1e-3)] = period_metrics - # Export metrics + # Metrics for each period + for i in range(0, int(tobii_segment_video.duration/(args.period * 1e6))): + + period_start_ts = i*(args.period * 1e6) + period_end_ts = (i+1)*(args.period * 1e6) + + metrics_for_period(period_start_ts, period_end_ts) + + metrics_dataframe = ts_metrics.as_dataframe() #pandas.DataFrame(metrics, index=[participant_name]) + metrics_dataframe.to_csv(gaze_metrics_period_filepath, index=True) + print(f'\nGaze metrics per period of time saved into {gaze_metrics_period_filepath}') + + # Metrics for the whole session + ts_metrics = DataStructures.TimeStampedBuffer() + metrics_for_period(0, tobii_segment_video.duration) + metrics_dataframe = ts_metrics.as_dataframe() #pandas.DataFrame(metrics, index=[participant_name]) - metrics_dataframe.to_csv(gaze_metrics_filepath, index=True) - print(f'\nGaze metrics saved into {gaze_metrics_filepath}\n') + metrics_dataframe.to_csv(gaze_metrics_whole_filepath, index=True) + print(f'\nGaze metrics for whole segment saved into {gaze_metrics_whole_filepath}\n') if __name__ == '__main__': |