Data Logger

Using the DataLogger

The DataLogger is a versatile tool designed to facilitate the logging of experimental data in Vizard VR experiments. It can capture a variety of data points, including gaze position, head position, custom events, and more. This document outlines how to expand its functionality as needed. See also ExampleScripts- Data_Logger_Adding_Data.py or Data_Logger_Adding_Data_360.py

Adding Custom Data Points

To add custom data points to the logger:

import settings

def update_settings(setting_name, value):

    setattr(settings, setting_name, value)

update_settings('CUSTOM_TRACKING_DATA', True)

from utils_sightlab import sightlab

def sightLabExperiment(): while True: def get_additional_data(): rHandPos = sightlab.rightHand.getPosition() rHandPos = [round(x, 3) for x in rHandPos] return rHandPos yield viztask.waitKeyDown(' ') logger = sightlab.DataLogger(sightlab.participant, sightlab.trialNumber + 1,   sightlab.use_vive_pro,   additional_columns=['Rhand X', 'Rhand Y', 'Rhand Z']+['FLAG'], start_time=viz.tick()) viz.sendEvent(TRIAL_START_EVENT) logger.start_logging(additional_data_func=get_additional_data) viz.sendEvent(TRIAL_START_EVENT) logger.start_logging(additional_data_func=get_additional_data)
yield viztask.waitKeyDown(' ') viz.sendEvent(TRIAL_END_EVENT) viztask.schedule(sightlab.experiment)viztask.schedule(sightLabExperiment)
For saving conditions, see this example:def get_additional_data():                Object_Size = sceneObjectSizeString                num_obj = NUM_OBJ                return [Object_Size,num_obj]

And here's an example for multiple objects: #While true is so that it runs every trial, but can also use range of number of trials. 


global logger

while True:

def get_additional_data():

rHandPos = sightlab.rightHand.getPosition()

rHandPos = [round(x, 3) for x in rHandPos]

headOri = sightlab.objects[2].getEuler()

headOri = [round(x, 3) for x in headOri]

return rHandPos + headOri #note you may need to put brackets around data

yield viztask.waitKeyDown(' ')

logger = sightlab.DataLogger(sightlab.participant, sightlab.trialNumber + 1, sightlab.use_vive_pro,  

additional_columns=['Rhand X', 'Rhand Y', 'Rhand Z', 'HeadYaw','HeadPitch', 'HeadRoll']+['FLAG'], start_time=viz.tick())

viz.sendEvent(TRIAL_START_EVENT)

logger.start_logging(additional_data_func=get_additional_data)


Starting and Stopping the Logger

To start logging data:

logger.start_logging(additional_data_func=get_additional_data)


To stop logging data, usually at the end of a trial or when pausing the experiment:


logger.stop_logging()


Changing Directory where Data is Saved

logger = sightlab.DataLogger(sightlab.participant, sightlab.trialNumber + 1, sightlab.use_vive_pro, additional_columns=['Condition'], directory= '../DataFiles/',start_time=viz.tick())


Note: if you change the directory, you will then have to redirect the SessionReplay script to find the csv file for the heatmap: 

data_dir = 'pathToYourDataDirectory'

Logging Flags or Events

To log specific events or flags during the experiment, such as a button press or a significant event:

def set_flag(flag_text):

 logger.set_flag(flag_text)

You can call this set_flag function at any point in your experiment to log the occurrence of an event.


Starting and Stopping Logging

Here's an example where a True/ False Boolean can toggle whether a trial logs or does not log data. This can be used alongside a STIM file to set blocks of practice trials, or certain trials where data is not collected

LOG_DATA = Falsedef sightLabExperiment(): global logger, LOG_DATA entries = SR.getStimFileEntryList() yield viztask.waitKeyDown(' ') # Iterate over the entries for i in range(sightlab.sceneConfigDict["trials"]): currentEntry = entries[i] if 'logData' in currentEntry: LOG_DATA = currentEntry.get('logData', 'False') == 'True' if LOG_DATA: logger = sightlab.DataLogger(sightlab.participant, sightlab.trialNumber                         + 1, sightlab.use_vive_pro,   start_time=viz.tick()) logger.start_logging() viz.sendEvent(TRIAL_START_EVENT)

For multi -user see Data_Logger_Adding_Data_Server in the ExampleScripts folder

Adding to Existing Tracking Data.txt File

Adding to the existing tracking data file is not the recommended workflow (recommended to use the custom data_logger) as it involves modifying the sightlab module and is a bit more advanced. See this page on how that is done.