Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
nReps and sequential/random/fullRandom
add psychoJS support for nReps and
sequential/random/fullRandom trial sequences.
Add columns from conditions files to data output.
Make loops marked as “isTrials” cause a data line
to be written each iteration. Add an “eventName”
column to the data file to identify whether a data
line was caused by a keyboard event or a loop iteration.
write out experiment data when quitPsychoJS() is called.

This commit goes with the one with the same name in the
psychojs project
  • Loading branch information
jonathanoroberts authored and peircej committed Jun 15, 2017
1 parent 69e3ec8 commit ad9a931
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion psychopy/app/builder/components/keyboard/__init__.py
Expand Up @@ -523,4 +523,5 @@ def writeRoutineEndCodeJS(self, buff):
buff.writeIndentedLines(code)

if currLoop.params['name'].val == self.exp._expHandler.name:
buff.writeIndented("%s.nextEntry()\n" % self.exp._expHandler.name)
buff.writeIndented("%s.addData('eventName','keyboard');\n" % self.exp._expHandler.name)
buff.writeIndented("%s.nextEntry();\n" % self.exp._expHandler.name)
10 changes: 10 additions & 0 deletions psychopy/app/builder/components/settings/__init__.py
Expand Up @@ -631,7 +631,17 @@ def writeEndCodeJS(self, buff):
"}\n"
)
buff.writeIndentedLines(abbrevFunc)
recordLoopIterationFunc = ("\nfunction recordLoopIteration(name) {\n"
" return function () {\n"
" thisExp.addData('eventName',name+'.loopEnd');\n"
" thisExp.nextEntry();\n"
" return psychoJS.NEXT;\n"
" }\n"
"}\n"
)
buff.writeIndentedLines(recordLoopIterationFunc)
quitFunc = ("\nfunction quitPsychoJS() {\n"
" thisExp.save();\n"
" win.close()\n"
" psychoJS.core.quit();\n"
" return psychoJS.QUIT;\n"
Expand Down
17 changes: 13 additions & 4 deletions psychopy/app/builder/experiment.py
Expand Up @@ -1054,15 +1054,15 @@ def writeLoopStartCodeJS(self, buff):
" trialList:psychoJS.data.importConditions({params[conditionsFile]}),\n"
" seed:{seed}, name:'{params[name]}'}});\n"
" thisExp.addLoop({params[name]}); // add the loop to the experiment\n"
" {thisName} = {params[name]}.trialList[0]; // so we can initialise stimuli with some values\n"
" {thisName} = {params[name]}.trialList[{params[name]}.trialSequence[0]]; // so we can initialise stimuli with some values\n"
" // abbreviate parameter names if possible (e.g. rgb={thisName}.rgb)\n"
" abbrevNames({thisName});\n"
.format(params=self.params, thisName=self.thisName, seed=seed))
buff.writeIndentedLines(code)
# for the scheduler
code = (" // Schedule each of the trials in the list to occur\n"
" for (var i = 0; i < {params[name]}.trialList.length; ++i) {{\n"
" {thisName} = {params[name]}.trialList[i];\n"
" for (var i = 0; i < {params[name]}.trialSequence.length; ++i) {{\n"
" {thisName} = {params[name]}.trialList[{params[name]}.trialSequence[i]];\n"
" thisScheduler.add(abbrevNames({thisName}));\n"
.format(params=self.params, thisName=self.thisName, seed=seed))
buff.writeIndentedLines(code)
Expand All @@ -1087,6 +1087,11 @@ def writeLoopStartCodeJS(self, buff):
" thisScheduler.add({name}LoopEnd);\n"
.format(params=self.params, name=thisChild.params['name'])
)
if self.params['isTrials'].val == True:
code += (
" thisScheduler.add(recordLoopIteration('{name}'));\n"
.format(params=self.params, name=thisChild.params['name'])
)
buff.writeIndentedLines(code)
code = (" }}\n"
" }} catch (exception) {{\n"
Expand Down Expand Up @@ -1147,7 +1152,7 @@ def writeLoopEndCodeJS(self, buff):
" params = Object.keys({params[name]}.trialList[0]);\n"
" }}\n\n"
" // save data for this loop\n"
" thisExp.save({{stimOut: params, dataOut: ['n','all_mean','all_std', 'all_raw']}});\n"
" thisExp.loopEnded({params[name]});\n"
" return psychoJS.NEXT;\n"
" }}\n"
.format(params=self.params))
Expand Down Expand Up @@ -2079,6 +2084,10 @@ def writeRoutineBeginCodeJS(self, buff):
" thisComponent.status = psychoJS.NOT_STARTED;\n"
" }}\n"
"}}\n"
"for (var l = 0; l < thisExp._unfinishedLoops.length; l++) {{\n"
" var loop = thisExp._unfinishedLoops[l];\n"
" loop.updateAttributesAtBegin();\n"
"}}\n"
"\nreturn psychoJS.NEXT;\n"
"}}\n"
.format(name=self.name))
Expand Down

0 comments on commit ad9a931

Please sign in to comment.