NEMO Scripting
The NEMO framework executes every experiment according to the script that defines it.
Scripts handle every detail, from creating devices to logging data. Scripts are
written in a language called Jython.
The Task Object
When writing a NEMO script, one variable, called task, will be predefined
by the framework. task is a Java object that is created when an experiment
is created (that is, when a user decides to run the experiment). task
serves as an intermediary between the script and the NEMO framework. It provides
functions for setting up the environment for an experiment and communicating with
clients during an experiment.
The following functions are made available to script writers through task:
setExperimentSize(numClients)
Tells the task how many clients will be connecting to the
server for this experiment. The experiment cannot start until
exactly numClients clients are connected.This function must be called in the Pre-Start Phase. |
setStartFunction(aFunctionName)
When the required number of clients have connected to the experiment and
entered start mode, NEMO will make a call to the script function
aFunctionName. This function might set the initial display,
setup data handling, or prompt the subjects for input.This function must be called in the Pre-Start Phase. |
setExperimentName(aName)
|
Every experiment has a unique name. When uploading a script to NEMO for
future use, a name is supplied to identify the experiment. The name used
when uploading must match the name passed to the function. This function must be called in the Pre-Start Phase. |
getDataType(aDataTypeName)
Returns the DataType with the name aDataTypeName.
The returned DataType is used later in the script by
startDataSet to create a DataSet, which is
used to log behavioral data.
This function must be called in the Pre-Start Phase. |
addDevice(aDeviceName, aDeviceClassName, aHandlerFunction)
Creates a device with the unique name aDeviceName using the
class aDeviceClassName. Any communication from clients
travels through the function given by aHandlerFunction. See
more about devices here.
This function must be called in the Pre-Start Phase. |
addDeviceProperty(aDeviceName, aPropertyName, aPropertyValue)
|
This function allows a script writer to designate required configuration
parameters for devices. See more about devices
here.
This function must be called in the Pre-Start Phase. |
startRun(aRunName)
Runs are divisions in an experiment. A singe experiment may have any
number of runs. Each run will be stored separately by NEMO while still
being linked to the particular experiment. The run will be labeled with
aRunName. The time at which this function is called will be
stored with the run by NEMO.
|
startDataSet(aDataTypeName, aClientID)
A DataSet is a collection of data of the same
DataType. A DataSet should be created for each
client in the experiment. The call to this function requires the name of
the DataType and the ID of a client. The name of the
DataType can be found using the DataType
returned by the call to getDatatType. This function will
return a DataSet object, which will be used for logging and
to end the DataSet.
|
endDataSet(aDataSet)
Ends the DataSet given by the parameter
aDataSet. Once the DataSet has ended, no more
data can be logged to it.
|
endRun()
| Ends the current run. This method will fail if a run has not yet been started. |
endExperiment()
| Ends the entire experiment. No more data can be logged, and no more runs can be started. This method must be called to tell NEMO to store all logged data to the database! |
The Pre-Start Phase
After a user chooses to run an experiment, NEMO pulls the script from the database and
processes it. It is the responsibility of the script (and the script writer) to ensure
that certain actions are taken to properly set up the experiment. Before the experiment
starts, NEMO requires that a script specify the number of clients to expect, the name of
the experiment, the start function, and the devices to be used.
The Pre-Start Phase is also a good time to set up any variables that may need to be used
later in the script. This will cut down on time once the experiment starts. For example,
this phase is a good time to get the necessary DataTypes from
task.
Any part of the script that is not inside a class or function will be run in the
Pre-Start Phase. Calls can be made to functions and classes, but only those
that are explicitly called will be executed. As shown in the sample code on lines
481-514, calls are made to
task.setExptSize, task.setExperimentName,
task.setStartFunction, and others in the Pre-Start Phase. Note that a
call is made on line 514 to
construct an instance of a custom class (called
ExampleClass).
Coordinating Clients
NEMO assigns a unique ID to each client that connects to the experiment. The IDs fall in
the range 0 to numClients - 1. Client IDs are used when
sending commands to clients, receiving communication from a particular client, and
creating DataSets for logging data. When writing a script for a
single-client experiment, client coordination is very straightforward (it will always be
0!); however, writing an experiment for 12 subjects can be cumbersome. It
will be very important to ensure that commands go to the correct client and that events
are attributed to the correct client.