new TrialData()
The TrialData service is responsible for collecting the responses
provided by the user over the course of an experiment session.
Members
data
The data object for this session. Originally set to a new instance of a BlankDataObject.
exportedProperties :Array.<string>
The properties beneath data that toJsonCompact should include in the JSON it outputs. This should be an array of strings, each of which represent an individual property that should be exported. The strings should be dot-delimited paths. Wildcards are not supported.
Type:
- Array.<string>
Methods
language(newLanguage) → {string}
Updates the language stored at the metadata.language
property of data
Parameters:
| Name | Type | Description |
|---|---|---|
newLanguage |
string | The language |
Returns:
The language to which the
metadata.language property of data is set after the call to this
method.
- Type
- string
reset() → {undefined}
Sets data to a new instance of a BlankDataObject.
Returns:
- Type
- undefined
setValueForPath(path, value, options) → {undefined}
Sets the value for a 'keypath' in data. Keypaths are dot-delimited
'addresses' into the data
object. For instance, the string 'foo.bar.baz' interpreted
as a keypath points to the baz property of an object, which
is the value of the bar property on the foo object:
data = {
foo: {
bar: {
baz: 13 // foo.bar.baz points to this value
}
}
}
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | The keypath (address) into data |
value |
* | The value that this keypath should hold |
options |
* | Currently only one option is supported:
|
Returns:
- Type
- undefined
setValueForPathForCurrentmedia(path, value) → {undefined}
Sets the value for a 'keypath' in data. (See setValueForPath for more infomation on 'paths'.)
When this method is used, the current media in the experiment
session is observed. value is expected to be placed into an
Array that is stored at the keypath, and the number of the
current media is used to decide the index of this array at
which value should be stored. For instance, if the second
media excerpt was just played and this method was called with
'data.answers.foo' for path and 14 for 'value', 14
would be stored in the second index of the array at
'data.answers.foo'.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | The keypath (address) into data |
value |
* | The value that this keypath should hold |
Returns:
- Type
- undefined
toCompact() → {Object}
Returns a copy of the object in data, keeping only those properties specified in exportedProperties, If exportedProperties is an empty array, this method returns data.
Returns:
- Type
- Object
toJson() → {string}
Converts the object in data to JSON and returns it.
Returns:
- Type
- string
toJsonCompact() → {string}
Converts the object in data, keeping only those properties specified in exportedProperties, to JSON and returns it. If exportedProperties is an empty array, this method delegates to toJson.
Returns:
- Type
- string
(inner) BlankDataObject() → {Object}
This function returns the object that will be populated with data as responses are provided by the user. You are free to manipulate this object to suit your needs, but take note of the properties that are configured with the demo app that are described here. In particular, take care when modifying the metadata and state properties.
Properties:
| Name | Type | Description |
|---|---|---|
answers |
Object | This object is where the actual
responses from users are stored. For example, when you create a
question in your study specification document (see the
README) with its |
date |
Date | The date and time that this session commenced |
media |
Array.<Object> | The media that were played during this session |
timestamps |
* | Timestamps for different points during the session |
metadata |
Object | Various important metadata (location, language, terminal number, session number, etc.) |
state |
Object | Important data for maintaining the state of the session |
Returns:
- Type
- Object