/// <summary> /// Stop recording gaze data /// </summary> public void StopRecording() { if (!FileHandler.writingData) { Debug.LogError("[EyeTracking DataLogger] Can't stop recording as we currently aren't recording!"); } // Unsubscribe from new data event dataProvider.NewDataEvent -= NewDataHandler; // Update the recording information CurrentRecording.stopTime = DateTime.Now; CurrentRecording.recordingDuration = CurrentRecording.stopTime - CurrentRecording.startTime; // Write the new information file FileHandler.WriteInformation(JsonUtility.ToJson(new JSON.RecordingInfo(CurrentRecording), true), true); // Stop the current log FileHandler.StopDataLog(); Debug.Log("[EyeTracking DataLogger] Stopped recording"); }
/// <summary> /// Asynchronous Coroutine which starts the recording /// </summary> /// <returns></returns> private IEnumerator StartRecordingCoroutine() { // Start the data log and thereby initialize the file handler for this recording FileHandler.StartDataLog(ParticipantName, RecordingName); // Wait for the file to be opened yield return(new WaitUntil(() => FileHandler.writingData)); // Create recording info // Note: At this point we transfer the game objects of which we want to log the position into the recording info. // This means the list stays static during recording which is important for the data file header CurrentRecording = new RecordingInfo { participantName = ParticipantName, recordingName = RecordingName, startTime = DateTime.Now, positionLoggedGameObjectNames = dataProvider.PositionLoggedGameObjectNames }; // Write information file JSON.RecordingInfo infoJson = new JSON.RecordingInfo(CurrentRecording); string infoString = JsonUtility.ToJson(infoJson); FileHandler.WriteInformation(infoString, true); // Create the header for the data file StringBuilder dataFileHeader = new StringBuilder(); // Append the general information dataFileHeader.Append("eyeDataTimestamp,eyeDataRelativeTimestamp,frameTimestamp,isCalibrationValid,"); dataFileHeader.Append("gazeHasValue,gazeOrigin_x,gazeOrigin_y,gazeOrigin_z,gazeDirection_x,gazeDirection_y,gazeDirection_z,"); dataFileHeader.Append("gazePointHit,gazePoint_x,gazePoint_y,gazePoint_z,gazePoint_target_name,gazePoint_target_x,gazePoint_target_y,gazePoint_target_z,"); dataFileHeader.Append("gazePoint_target_pos_x,gazePoint_target_pos_y,gazePoint_target_pos_z,gazePoint_target_rot_x,gazePoint_target_rot_y,gazePoint_target_rot_z,gazePoint_target_scale_x,gazePoint_target_scale_y,gazePoint_target_scale_z,"); dataFileHeader.Append("gazePointLeftScreen_x,gazePointLeftScreen_y,gazePointLeftScreen_z,gazePointRightScreen_x,gazePointRightScreen_y,gazePointRightScreen_z,gazePointMonoScreen_x,gazePointMonoScreen_y,gazePointMonoScreen_z,"); dataFileHeader.Append("GazePointWebcam_x,GazePointWebcam_y,GazePointWebcam_z,"); dataFileHeader.Append("gazePointAOIHit,gazePointAOI_x,gazePointAOI_y,gazePointAOI_z,gazePointAOI_name,gazePointAOI_target_x,gazePointAOI_target_y,gazePointAOI_target_z,"); dataFileHeader.Append("gazePointAOI_target_pos_x,gazePointAOI_target_pos_y,gazePointAOI_target_pos_z,gazePointAOI_target_rot_x,gazePointAOI_target_rot_y,gazePointAOI_target_rot_z,gazePointAOI_target_scale_x,gazePointAOI_target_scale_y,gazePointAOI_target_scale_z,"); dataFileHeader.Append("GazePointAOIWebcam_x,GazePointAOIWebcam_y,GazePointAOIWebcam_z"); // Append the game object information if we want to log game objects for (int i = 0; i < CurrentRecording.positionLoggedGameObjectNames.Length; i++) { // We start with NA as game object name and replace it with the actual name if the game object (still) exists string gameObjectName = "NA"; if (CurrentRecording.positionLoggedGameObjectNames[i] != null) { gameObjectName = FileHandler.RemoveAllNonAlphanumeric(CurrentRecording.positionLoggedGameObjectNames[i]); } dataFileHeader.Append(",GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_xPos,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_yPos,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_zPos,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_xRot,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_yRot,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_zRot,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_xScale,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_yScale,GameObject_"); dataFileHeader.Append(gameObjectName); dataFileHeader.Append("_zScale"); } // Header for the info column dataFileHeader.Append(",info"); // Write the header for the data file FileHandler.WriteData(dataFileHeader.ToString()); // Subscribe to new data event dataProvider.NewDataEvent += NewDataHandler; Debug.Log("[EyeTracking DataLogger] Started recording"); }