def doMakoLogin(self,subject=None,visit=None): self.jsonpath = os.path.join(SUBJS,subject,"%s_experiment_info.json"%subject) if os.path.exists(self.jsonpath): self.json = load_json(self.jsonpath) else: self.json = get_json(subject) #self.json['subject_id'] = subject self.json['time'] = time.ctime() ## record new login time visit = [v['active'] for v in self.json['Protocol']].index(True) # auto-get last open tab ### if no sessiondir exists, create it if not os.path.exists(os.path.join(SUBJS,subject)): self.history = createSubDir(subject) + self.history if not os.path.exists(os.path.join(SUBJS,"%s/session%s/"%(subject,visit))): history = makeSession(subject,visit) # returns history self.history = history + self.history self.setTab(visit) # activates the tab return self.renderAndSave() # saves the json, and renders the page
def doLogin(self, subject=None, visit=None): self.subject = subject self.visit = visit date = data.getDateStr()[:-5] with open(os.path.join(HOME, "index.html")) as fp: msg = fp.readlines() with open(os.path.join(HOME, "historybar.html")) as fp: hist = fp.readlines() msg += hist ## if no subject/sessiondir exists, create it - also if the mask and study ref exist lets make fakedata if not os.path.exists(os.path.join(SUBJS, subject)): self.history = createSubDir(subject) + self.history if ( os.path.exists(os.path.join(SUBJS, subject, "mask", "%s_roi.nii" % subject)) and os.path.exists(os.path.join(SUBJS, subject, "xfm", "%s_study_ref.nii" % subject)) and not os.path.exists(os.path.join(SUBJS, subject, "run1.nii")) ): pass # self.history = makeFakeData(subject) +self.history if not os.path.exists(os.path.join(SUBJS, "%s/session%s/" % (subject, visit))): history = makeSession(subject, visit) # returns history self.history = history + self.history msg += self.history msg += """</div></div>""" subject_info = """ <div style="background-color: white; text-align: left; padding: 0px 10px 10px 10px"> <p> <br><b>Subject:</b> %s <br><b>Visit #:</b> %s </p> <p> <form method="post" action="formHandler"> <p><div style="padding: 10px 10px 10px 10px">Run #: <input type="text" name="run" value=%s size="10" maxlength="40"/></div></p> <p><b>Tests:</b> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Test Display"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Test Buttons"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Test Scanner Trigger"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Test Letter Sounds"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Test Bird Sounds"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Start InfoClient Test"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Check InfoClient"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="End InfoClient"></div> </p> <p><b>Murfi:</b> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Start Murfi"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="End Murfi"></div></p> <p><b>Fake Data:</b> <br><div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Serve"></div> <div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="End Serve"></div></p> <p><b>Stimulus:</b> <br><div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Stimulus"></p> <br><div style="padding: 10px 10px 10px 10px"><input type="submit" name="button" value="Placebo Stimulus"></p> </form> </p> <div id="placeholder" style="width:600px;height:300px;"></div> <p> <input class="dataUpdate" type="button" value="Poll for data"> </p> <script type="text/javascript"> $(function () { var options = { lines: { show: true }, points: { show: true }, xaxis: { tickDecimals: 0, tickSize: 1 } }; var data = []; var placeholder = $("#placeholder"); $.plot(placeholder, data, options); // fetch one series, adding to what we got var alreadyFetched = {}; // initiate a recurring data update $("input.dataUpdate").click(function () { // reset data data = []; alreadyFetched = {}; $.plot(placeholder, data, options); var iteration = 0; function fetchData() { ++iteration; data = [] function onDataReceived(series) { // we get all the data in one go, if we only got partial // data, we could merge it with what we already got //if (!alreadyFetched[series.label]) { //alreadyFetched[series.label] = true; //data.push(series); //} data.push(series); $.plot($("#placeholder"), data, options); } $.ajax({ // usually, we'll just call the same URL, a script // connected to a database, but in this case we only // have static example files so we need to modify the // URL url: "subjects/%s/session%s/data/%s_%s_run_%03d_active.json", method: 'GET', dataType: 'json', success: onDataReceived }); $.ajax({ // usually, we'll just call the same URL, a script // connected to a database, but in this case we only // have static example files so we need to modify the // URL url: "subjects/%s/session%s/data/%s_%s_run_%03d_reference.json", method: 'GET', dataType: 'json', success: onDataReceived }); if (iteration < 63) setTimeout(fetchData, 5000); else { data = []; alreadyFetched = {}; } } setTimeout(fetchData, 1000); }); }); </script> """ % ( subject, visit, self.run, subject, visit, subject, date, int(self.run), subject, visit, subject, date, int(self.run), ) msg += subject_info with open(os.path.join(HOME, "footer.html")) as fp: foot = fp.readlines() return msg + foot ### end: def doLogin()