- Notifications
You must be signed in to change notification settings - Fork 51
Custom Data Handler
If any of the current Data Handler (listed here) do not meet your needs (e.g. you wish to upload data to a different online service) then you can create a custom Data Handler. This would be used to handle all data operations UXF makes (e.g. saving trial results, tracker outputs, etc).
Note: If you wish to output custom data e.g. a custom text file, but are OK with the current Data Handlers, see DIY data collection.
To make a new Data Handler, you must inherit from the DataHandler
class and override the required methods. The methods required to override are:
HandleDataTable
-
HandleJSONSerializableObject
(2 methods for each of the .json types, one withList<object>
and the other withDictionary<string, object>
arguments) HandleText
HandleBytes
Then, you can attach your script to an object and reference it in the Data Handlers field of the Session
inspector.
Here is a template for a custom data handler that simply prints the data as text to the console:
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; /// This is an example custom data handler. It implements the required DataHandler methods and just prints out data to the console. /// You can copy this script, but do some other action instead of printing out the data. /// You can attach this script to a GameObject then reference it in the Data Handling tab of the UXF Session component. public class ExampleCustomDataHandler : DataHandler { public override bool CheckIfRiskOfOverwrite(string experiment, string ppid, int sessionNum, string rootPath = "") { return false; // You could write a condition to return true when a ppid already exists. } public override void SetUp() { // No setup is needed in this case. But you can add any code here that will be run when the session begins. } public override string HandleDataTable(UXFDataTable table, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0) { // get data as text string[] lines = table.GetCSVLines(); string text = string.Join("\n", lines); // here we "write" our data, you could upload to database, or do whatever. Debug.Log(text); // return a string representing the location of the data. Will be stored in the trial_results output. return "Data printed to console."; } public override string HandleJSONSerializableObject(List<object> serializableObject, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0) { // get data as text string text = MiniJSON.Json.Serialize(serializableObject); // here we "write" our data, you could upload to database, or do whatever. Debug.Log(text); // return a string representing the location of the data. Will be stored in the trial_results output. return "Data printed to console."; } public override string HandleJSONSerializableObject(Dictionary<string, object> serializableObject, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0) { // get data as text string text = MiniJSON.Json.Serialize(serializableObject); // here we "write" our data, you could upload to database, or do whatever. Debug.Log(text); // return a string representing the location of the data. Will be stored in the trial_results output. return "Data printed to console."; } public override string HandleText(string text, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0) { // here we "write" our data, you could upload to database, or do whatever. Debug.Log(text); // return a string representing the location of the data. Will be stored in the trial_results output. return "Data printed to console."; } public override string HandleBytes(byte[] bytes, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0) { // here we "write" our data, you could upload to database, or do whatever. string text = System.Text.Encoding.UTF8.GetString(bytes); Debug.Log(text); // return a string representing the location of the data. Will be stored in the trial_results output. return "Data printed to console."; } public override void CleanUp() { // No cleanup is needed in this case. But you can add any code here that will be run when the session finishes. } }
๐ง Core topics
- ๐ Background
- โจ UXF 2.0
- โ๏ธ Compatibility
- ๐ถ๏ธ Oculus Quest Setup
- ๐ญ Concepts
- ๐ ๏ธ Get started
- ๐ Examples
- ๐ฅ๏ธ Built-in UI
- ๐ Session generation
- โฐ Events
- ๐ Data collection
- โ๏ธ Collect custom data
- ๐ Custom Data Handler
- ๐ Remote Data Collection
- ๐๏ธ WebGL DynamoDB setup
- ๐ Processing DynamoDB CSVs
- ๐ซ HTTP Post Setup
- ๐ง Settings system
- ๐๐ฝ Tracker system
- ๐ Logging system
โ ๏ธ Common issues- ๐ผ๏ธ Multi-scene experiments
- ๐บ Videos
- ๐จโ๐ Full written tutorial
- ๐ฆ Asset links
- ๐จโ๐ซ Unity tutorial links
- ๐ Useful code snippets
- ๐ก Programming ideas
- ๐งฎ Example R processing