Variables and expressions¶
Some experimental conditions (strain, virus species etc.) may vary across individual subjects, individual sessions, runs or sweeps.
To easily express some context-dependence within experiments, you can use variables and expressions in place of concrete objects.
Use of variables¶
A variable is a placeholder for an object that is defined on-site during an experiment.
For example, the following object describes a variable that can take either pairing
or testing as its value.
{
"$variable": {
"type": { "enum": "pairing", "testing" }
},
"description": "the mode of the task."
}
Another example below describes an array of values taking any number above zero:
{
"$variable": {
"type": "array",
"items": {
"type": "number",
"minimum": 0
}
},
"description": "array of time points when the participant started examining the place."
}
-
class
variable¶ A
variableobject can be identified by the existence of the$variableproperty.For an example, refer to Use of variables.
-
$variable holds a valid schema based on JSON Schema, but it may typically be a schema for a
stringor anumber.
-
description¶ a required human-readable description about what this variable stands for.
-
Use of conditions¶
Conditions provide a way to switch the object depending on the value of a certain variable,
just like the switch statement in C, C++ and related languages.
{
"$condition": { "$ref": "/variable/task-mode" },
"switch": [
{
"case": "pairing",
"value": 2
},
{
"case": "testing",
"value": 1
}
],
"default": 0,
"description": "the task mode-dependent output value returned from Arduino."
}
In the above example, depending on the string variable being held at /variable/task-mode,
the expression evaluates to a different value.
It evaluates to 2 if the task mode is pairing, 1 if the mode is testing,
and 0 otherwise.
-
class
condition¶ the existence of the
$conditionproperty indicates that this is aconditionobject.For an example, refer to Use of conditions.
-
$condition holds a reference to the variable.
-
description¶ a required human-readable description about what this variable stands for.
-
switch¶ a required array of
case-expressionobjects.
-
Expressions and formatters¶
Expressions and formatters provide a simple way of calculations based on variables.
Below is an example of a formatter:
{
"$expression": "{{ x }}\*2 + 3",
"where": {
"x": { "$ref": "/variables/x" }
},
"description": "the amplitude depends on the value of x."
}
In the example above, if x evaluates to the number 1, for example,
the whole formatter is evaluated to 5.
Another example provides another way of expressing a condition:
{
"$expression": "{{ x }} == {{ y }}",
"where": {
"x": { "$ref": "/variable1" },
"y": { "$ref": "/variable2" }
},
"description": "the condition depends on whether or not x and y are equal."
}
In this case, the whole formatter is evaluated to either true or false,
depending on whether the two referenced variables are equal or not.
In practice, you can define the expression elsewhere as a string, and plug the values where you need:
{
"expressions": {
"output-calculation": "{{ start }} + {{ step }} * {{ index }}",
...
},
...
"pulse": {
"amplitude": {
"$expression": { "$ref": "/expressions/output-calculation" },
"where": {
"start": 0,
"step": 10,
"index": 2
}
}
}
}
-
class
formatter¶ The existence of the
$expressionproperty indicates that this is aformatterobject.For examples, see Expressions and formatters.
-
$expression the expression to be evaluated. Each appearance of variable names must be wrapped inside doubled curly braces.
-
description¶ a required human-readable description about what this variable stands for.
-
where¶ the assignment specifications for the expression. The variables used within
$expressionmust appear once in this section.
-
Use of templates¶
TODO
$templatekeyword- object representation instead of expression
$ref-based reference
whereproperty- used to plug values at the root scope of the template