Skip to content

Collect Custom Data

Jack Brookes edited this page Sep 2, 2021 · 9 revisions

DIY data collection

In general this is not necessary, most of the time the data you need to output should be stored in the trial.result object, or captured with a tracker component. However, in some cases you may need to save data associated with a session or a trial. For example, data from a survey, or any other form of data collection.

You can use the the Save* methods for your Session or Trial. These methods automatically handle the data, and store it in an appropriate location. In the case of trial-level data, using trial.Save* methods, a reference to the output data location will also be saved in the trial_results data output.

For example, storing the text abcdefg to a file called my_text for the current trial:

session.CurrentTrial.SaveText("abcdefg", "my_text");

And for the current session:

session.SaveText("abcdefg", "my_text");

The methods you can use on Session or Trial are:

  • trial/session.SaveText(string, "my_text")
  • trial/session.SaveDataTable(UXFDataTable, "my_data_table") (To do this you will need to construct your own UXFDataTable object - see here.
  • trial/session.HandleJSONSerializableObject(List<object>, "my_json_like_object") (Saves a list of dictionaries, string, float, int, or bool)
  • trial/session.HandleJSONSerializableObject(Dictionary<string, object>, "my_json_like_object") (Saves a list of dictionaries with string keys, and string, float, int, or bool values)
  • trial/session.SaveDataTable(byte[], "my_bytes.wav") (Saves some raw bytes, I use this for recording microphone data as a WAV file).

Questionnaires/Surveys

UXF has no direct support for surveys, since it would be difficult to create a solution that allows for Desktop + VR use, also supporting a range of VR systems (OpenXR, SteamVR, Oculus, etc).

You should be able to use VRQuestionnaireToolkit with no compatibility issues, but it will not save data directly within UXF's data handler system.

If you want to create your own data survey system, and have them saves as CSVs or in Databases etc from within UXF's Data Handler system, you can do something like this:

// have this method run after the final trial, but before the session ends
public void SaveSurvey()
{
    // ~ example show questions and get responses via the UI ~

    string exampleQuestion1 = "How difficult was the task";
    string exampleResponse1 = "Easy!";

    string exampleQuestion2 = "How are you feeling today on a scale of 1-7";
    int exampleResponse2 = 6;

    // ~ example show questions and get responses via the UI ~
    

    // questions are headers
    var headers = new string[]{ exampleQuestion1,  exampleQuestion2 };
    var surveyData = new UXF.UXFDataTable(headers); 

    // one row for the response (only 1 participant here!)
    var surveyResponse = new UXF.UXFDataRow();
    surveyResponse.Add((exampleQuestion1, exampleResponse1));
    surveyResponse.Add((exampleQuestion2, exampleResponse2));

    surveyData.AddCompleteRow(surveyResponse);

    // save output
    UXF.Session.instance.SaveDataTable(surveyData, "survey");
}

This will save a data file survey.csv in the session/othersessiondata directory

๐Ÿง  Core topics

โ“ More help


๐Ÿ‘ฉโ€๐Ÿ’ป Programming reference

Unit tests

Clone this wiki locally