Vizard 8 » Tutorials & Examples » Designing an experimental study » Tutorial: Testing phase of experiment
8.1

Tutorial: Testing phase of experiment

The testing phase of the experiment consists of 5 trials. For each trial, the participant is asked to walk to one of the spheres given its true color. Since all trials follow the same general pattern a for loop is used to cycle through them. For each iteration of the for loop the following occurs:

  1. The program waits until the participant is in the center of the room.
  2. Instructions are given to the participant about which sphere to find.
  3. The start time of the trial is stored.
  4. The program waits until the correct sphere sensor is activated.
  5. The time taken to complete the trial is calculated using the current and start times of the trial and saved to a list.

After the for loop has cycled through all the trials the participant is notified that the experiment is complete and the trial data is returned to the main task function. Replace the testPhase() function with the following code:

def testPhase():

    results = []
    trials = [3,2,0,4,1]

    for i in trials:

        #Check to see if participant is already in room center. If not
        #wait until the centerSensor is activated
        if centerSensor not in manager.getActiveSensors():
            yield vizproximity.waitEnter(centerSensor)

        #Get sensor for this trial
        sensor = sphereSensors[i]

        #Instruct participant where to go
        instruction = 'Walk to the {} sphere'.format(sensor.name)
        info.setText(instruction)

        #store the time at which this trial started
        startTime = viz.tick()

        #The yielded command returns a viz.Data object with information
        #about the proximity event such as the sensor, target involved
        yield vizproximity.waitEnter(sensor)
        info.setText('Please return to the center of the room')

        #calculate the time it took for the subject to find the correct object
        elapsedTime = viz.tick() - startTime

        #save results
        results.append((sensor.name, elapsedTime))

    info.setText('Thank You. You have completed the experiment')

    #return results
    viztask.returnValue(results)

In the main task function the participant and trial data are written to a text file. Replace the experiment function with the code below:

def experiment():

    #Wait for spacebar to begin experiment
    yield viztask.waitKeyDown(' ')

    #Proceed through experiment phases
    participant = yield participantInfo()
    yield learnPhase()
    results = yield testPhase()

    #Log results to file
    try:
        with open(participant.id + '_experiment_data.txt','w') as f:

            #write participant data to file
            data = "Participant ID: {p.id}\nLast Name: {p.lastName}\nFirst Name: {p.firstName}\nGender: {p.gender}\nAge: {p.ageGroup}\n\n".format(p=participant)
            f.write(data)

            #write result of each trial
            for name,time in results:
                data = "The {} trial took {:.2f} seconds\n".format(name,time)
                f.write(data)
    except IOError:
        viz.logWarn('Could not log results to file. Make sure you have permission to write to folder')

Run the program and complete the testing phase of the experiment. If you take a look at the text file that was created you should see the participant information followed by data for each trial.

Loading the virtual environment

Creating the experiment framework

Entering participant data

Learning phase of experiment

Testing phase of experiment