示例#1
0
    def get_onefile(self, table, kwargs):
        """Print the raw data (csv format) into a single file for the user to download
		table(string) - name of table to pull the vars from
		kwargs - optional query info
		"""
        u = cherrypy.user.name
        datatable = "%s_%s" % (table, u)
        dm = mt.MongoAdmin("datamaster")
        sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(datatable, sids=True)
        q = parseQuery(kwargs)

        # put the headers together
        headers = [sid, trial] + IVs + DVs
        sort = [sid, trial]
        if run:
            headers.insert(3, run)
            sort = [sid, run, trial]
        if outlier:
            headers += [outlier]

            # write that biznass out
        name = dm.write(datatable, q, headers=headers, sort=sort)
        name = os.path.basename(name)

        name += ".csv"

        up = mt.MongoAdmin("datamaster").db["user_files"].posts
        if not up.find_one({"user": u, "fname": name}):
            up.insert({"user": u, "fname": name})
        common.activity_log("download", "download single raw", table, kwargs)
        output = getAlert(
            "Your file is ready.  <a href='%s/output/%s'>Click here to download.</a>" % (domain, name), "good"
        )
        return output
示例#2
0
    def make_prts(self, table):
        """make prt interface
		"""
        datatable = "%s_%s" % (table, cherrypy.user.name)

        sid, trial, IVs, DVs, sids, run, outlier = common.getVariables(datatable, sids=False)

        output = "<p>Let's make some PRTs (files for BrainVoyager).</p>"

        form = "<label>Experiment Onset Delay (ms):</label>"
        form += '<input type="number" name="prt_onset" value=0>'
        form += "<label>Stimulus Onset:</label>" + getOptions(IVs, ID="prt_stim_onset")
        form += '<label>Stimulus Offset (ms):</label><input type="number" name="prt_offset" value=2000>'
        form += "<hr>"
        form += "<label>Condition:</label>" + getOptions(IVs, ID="prt_cond")

        form += "<label>Specify IV levels(e.g., <em>level1, level2</em> - leave blank to simply use levels present in run):</label>"
        form += "<input type ='text' name='prt_con_names'/></input><br/>"
        form += "<hr>"
        form += "<label>Check Accuracy?</label>" + getRadios(["yes", "no"], name="check_error")
        form += "<label>Accuracy listed in...</label>" + getOptions(DVs, ID="prt_ACC")
        form += "<label>Reaction time listed in...:</label>" + getOptions(DVs, ID="prt_RT")
        form += "<hr>"

        output += getForm(form, download_url)

        return output
示例#3
0
	def index(self, **kwargs):
		u = cherrypy.user.name

		output = ""

		t = common.getCookie('datamaster_table')

		#select any tables
		if kwargs.has_key('select_table'):
			t = kwargs['select_table']
			common.setCookie('datamaster_table', t)

		if t:
			table = "%s_%s" % (t, u)
			var_table = "%s_%s_vars" % (t, u)	
			sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(table, sids=True)


			posts = mt.MongoAdmin("datamaster").db[var_table].posts

			if kwargs.has_key('set_op'):
				output += self.query(table, kwargs)
			if kwargs.has_key('new_var'):
				output += self.create(table, kwargs)
			if kwargs.has_key('merge_var'):
				output += self.merge(table, kwargs)
			if kwargs.has_key('op-outlier-recurse-field'):
				output += self.outlier(table, kwargs)
	
			keys = posts.find().distinct('name')

			condition = getCondition(var_options=keys, label='If (optional)')
			setter = getSetter(var_options=keys, label='Set (required)')

			modify = getForm(condition + setter, modify_url, legend='transform a variable')

			create = getForm(template.get_def("create_column").render(var_options=keys), modify_url)

			merge = getForm(template.get_def("merge_column").render(var_options=keys), modify_url)

			preview = common.preview(table, kwargs, modify_url)

			outliers = common.outlierReport(mt.MongoAdmin("datamaster").db[table].posts) + getForm(template.get_def("mark_outliers").render(DVs=DVs), modify_url)

		else:
			modify = no_table
			create = no_table
			merge = no_table
			preview = no_table
			outliers = no_table

		items = [['select table', select_table(modify_url, t)], ['create', create], ['merge', merge], ['modify', modify], ['detect outliers', outliers], ['preview', preview]]

		output += getAccordion(items, contentID='modify-small')

		return getPage(output, "modify", "modify")
示例#4
0
    def prts(self, table, kwargs):
        """make prts function
		"""
        datatable = "%s_%s" % (table, cherrypy.user.name)
        sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(datatable, sids=False)

        # get the values
        onset_start = int(kwargs["prt_onset"])
        stim_onset = kwargs["op-prt_stim_onset"]
        stim_offset = int(kwargs["prt_offset"])
        if kwargs["check_error"] == "no":
            check_errors = False
        else:
            check_errors = True
        ACC = kwargs["op-prt_ACC"]
        RT = kwargs["op-prt_RT"]
        conditions = []
        if kwargs["prt_con_names"]:
            for con in kwargs["prt_con_names"].split(","):
                conditions.append(con.strip())
        output = ""
        myCond = kwargs["op-prt_cond"]

        settings = settings = (
            """FileVersion:       2\n\nResolutionOfTime:   msec\n\nExperiment:         %s\n\nBackgroundColor:    0 0 0\nTextColor:          255 255 255\nTimeCourseColor:    255 255 255\nTimeCourseThick:    3\nReferenceFuncColor: 0 0 80\nReferenceFuncThick: 3\n\n"""
            % (table)
        )

        prt_maker = makePRTs.prtFile(
            "datamaster", datatable, sid, run, settings, onset_start, stim_offset, check_errors
        )

        prt_maker.make(myCond, conditions, stim_onset, ACC, RT, trial, balance=False)

        files = prt_maker.fileList
        zipname = "%s_%s_prts" % (datatable, myCond)
        zippath = os.path.join("output", "%s.zip" % zipname)
        z = zipfile.ZipFile(zippath, "w")
        for f in files:
            z.write(f)
            os.system("rm %s" % f)

        z.close()

        up = mt.MongoAdmin("datamaster").db["user_files"].posts

        if not up.find_one({"user": cherrypy.user.name, "fname": zipname + ".zip"}):
            up.insert({"user": cherrypy.user.name, "fname": zipname + ".zip"})

        common.activity_log("download", "download prts", table, kwargs)

        output += getAlert(
            "Your files are ready.  <a href='%s/%s'>Click here to download.</a>" % (domain, zippath), "good"
        )

        return output
示例#5
0
    def raw(self, table):
        """Raw data interface
		table(string)
		"""
        datatable = "%s_%s" % (table, cherrypy.user.name)
        sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(datatable, sids=False)

        form = ""
        form += getCondition([trial] + IVs + DVs, "Include only data where:")

        output = "<p>You will get one file for each subject you have.</p>"
        output += getForm(form, download_url, hidden=["dl", "raw"])

        return output
示例#6
0
    def get_raw(self, table, kwargs):
        """Print the raw data (csv format) and put data in a zip file for download
		table(string) - name of table to pull the vars from
		kwargs - optional query info
		"""
        u = cherrypy.user.name
        datatable = "%s_%s" % (table, u)
        dm = mt.MongoAdmin("datamaster")
        sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(datatable, sids=True)

        q = parseQuery(kwargs)
        files = []

        for sub in sids:
            headers = [sid, trial] + IVs + DVs
            sort = trial
            if run:
                headers.insert(3, run)
                sort = [run, trial]
            if outlier:
                headers += [outlier]
            name = dm.write(datatable, dict(q, **{sid: sub}), headers=headers, sort=sort)
            files.append(name)

        zipname = datatable
        zipname = os.path.join("output", zipname + ".zip")
        z = zipfile.ZipFile(zipname, "w")

        for f in files:
            z.write(f + ".csv")
            os.system("rm %s.csv" % f)

        z.close()

        up = mt.MongoAdmin("datamaster").db["user_files"].posts

        if not up.find_one({"user": u, "fname": datatable + ".zip"}):
            up.insert({"user": u, "fname": datatable + ".zip"})

        common.activity_log("download", "download raw", table, kwargs)

        output = getAlert(
            "Your files are ready.  <a href='%s/%s'>Click here to download.</a>" % (domain, zipname), "good"
        )

        return output
示例#7
0
    def aggregate(self, table, kwargs):
        u = cherrypy.user.name
        datatable = "%s_%s" % (table, u)
        sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(datatable, sids=False)

        output = ""

        ivs = []
        dvs = []

        for k in kwargs.keys():
            if kwargs[k] == "on":
                if k in IVs:
                    ivs.append(k)
                elif k in DVs:
                    dvs.append(k)

        q = parseQuery(kwargs)

        w = mt.WriteTable(dvs, ivs, q, "datamaster", datatable, subject=sid)

        w.Compute()
        w.WriteForSPSS()
        w.WriteForR()

        spss_name = w.name + ".csv"
        r_name = w.name + ".dat"

        up = mt.MongoAdmin("datamaster").db["user_files"].posts

        if not up.find_one({"user": u, "fname": spss_name}):
            up.insert({"user": u, "fname": spss_name})

        if not up.find_one({"user": u, "fname": r_name}):
            up.insert({"user": u, "fname": r_name})

        common.activity_log("download", "aggregate", table, kwargs)

        output += (
            "<p>Your data is ready.  <a href='%s/output/%s'>Click here for SPSS format</a> or <a href='%s/output/%s'>click here  for R format.</p>"
            % (domain, spss_name, domain, r_name)
        )
        return output
示例#8
0
    def agg(self, table):
        """aggregate interface
		table(string)
		"""
        datatable = "%s_%s" % (table, cherrypy.user.name)
        sid, trial, IVs, DVs, run, outlier, sids = common.getVariables(datatable, sids=False)

        check_vars = common.checkVariables(datatable, ["subject", "trial", "IV", "DV"])

        if check_vars:
            output = check_vars
        else:
            form = ""
            form += getCheckbox(IVs)
            form += getCheckbox(DVs)
            form += getCondition(IVs + DVs + [trial], "Include only data where:")

            output = "<p>Here are the variables you have labelled.  Select the ones you want to combine into your new file.  You will get a single file with each subject's average DV(s) for each IV(s).</p>"
            output += getForm(form, download_url, hidden=["dl", "agg"])

        return output