def processLogin(self): subject = self.subject print 'SUBJECT['+ subject+']' self.mySubjectDir = j.checkSubjDir(subject) j.dirStructure(subject) # verify/create subject's directory structure (visits, etc.) self.jsonpath = os.path.join(self.mySubjectDir, "%s_experiment_info.json" % subject) if os.path.exists(self.jsonpath): self.json = lib.load_json(self.jsonpath) self.json['flotscript'] = '' if 'flotscript_header' in self.json: del self.json['flotscript_header'] else: lib.set_node(self.json, subject, j.SUBJID) ## get a fresh json_template ## find the next incomplete visit (if study complete, display final visit) for v in range(j.NUM_VISITS): self.setTab(v) if not lib.get_node(self.json, self.vNodePath + j.VCOMPLETE): break visit = v # handle subject's group assignment and create visit/session dir based on group, if needed. group = lib.get_node(self.json, j.GROUP) if not group == "": ### create & populate session dir self.visitDir, correctVisit = j.checkVisitDir(subject, visit, group, self.json) if not correctVisit == visit: self.subjectMoved("<b>Cannot move on to next visit without ROI masks!</b>", "false") self.setTab(correctVisit) return self.renderAndSave() # saves the json, and renders the page else: return self.modalthing() # render modal to assign group -> call setgroup() -> save json & render normally
def doMakoLogin(self,subject=None,visit=None): self.subject = subject ## keep this accessible to other methods self.mySubjectDir = j.checkSubjDir(subject) self.jsonpath = os.path.join(self.mySubjectDir, "%s_experiment_info.json"%subject) if os.path.exists(self.jsonpath): self.json = lib.load_json(self.jsonpath) else: lib.set_node(self.json,subject,j.SUBJID) ## get a fresh json_template visit = lib.get_node(self.json,j.TAB) self.setTab(visit) # activates the tab # handle subject's group assignment and create visit/session dir based on group, if needed. group = lib.get_node(self.json, j.GROUP) if not group == "": self.visitDir = j.checkVisitDir(subject,visit,group, self.json) ### create & populate session dir return self.renderAndSave() # saves the json, and renders the page else: return self.modalthing() # render modal to assign group -> call setgroup() -> save json & render normally
def makoMurfiHandler(self, btn_value, node): ## Handle "Start" & "End" differently if ('Start' in btn_value): murfLog = bt.nameLogfile(node, self.subject) try: self.murfProc, self.murfOUT, h = lib.doMurfi(self.subject, self.TabID, self.run, murfLog) except: self.murfProc.kill() self.murfOUT.close() raise lib.set_here(node,'text','End Murfi') ## could do this better lib.set_here(bt.sib_node(node['id'], self.json, 1), "disabled", False) ## activate psychopy lib.set_here(bt.sib_node(node['id'], self.json, 2), "disabled", False) ## activate servenii lib.writeFlots(self.subject, self.TabID, node['run']) ## update jquery for murfi plots print "attempting to change flotmurfi.js to use " + str(node['run']) +"!\n\n" elif "End" in btn_value: ## End must also clean up after servenii & rt psychopy, if needed. lib.set_here(bt.sib_node(node['id'], self.json, 1), "disabled", True) ## disable psychopy lib.set_here(bt.sib_node(node['id'], self.json, 2), "disabled", True) ## disable servenii ## close errant process handles if hasattr(self, 'murfProc'): lib.endMurfi(self.murfProc, self.subject, self.TabID, self.run, self.murfOUT) if hasattr(self, 'stimProc'): self.stimProc.kill() if hasattr(self, 'servProc'): lib.endServ(self.servProc, self.subject, self.TabID, self.run, self.servOUT) lib.set_here(node,'text','Start Murfi') ## check if RT run is done yet: ## -- 150ish TRs collected in results JSON? ==> done; update progress. ## -- otherwise, allow Murfi restart for this run. activeFile = os.path.join(self.visitDir,'data','run00%d_active.json'%self.run) if os.path.exists(activeFile): activeData = lib.load_json(activeFile) print "activeData's length is:", len(activeData['data']) if len(activeData['data']) > 150: bt.rtDone(self.json, node['id']) ## bt.updateProgress gets called in here. else: lib.set_here(node, "disabled", False) ## ensure murfi can be restarted else: print "mako_cherry: Can't handle this murfi button value:",btn_value return