示例#1
0
def transform_data():
    sessionid = session["id"]
    user_sess = UserSession.query.filter(UserSession.id == sessionid).first()
    pid = user_sess.pid
    aid = user_sess.aid
    p = Project.query.filter(Project.id == pid).first()
    inputs = Input.query.filter(Input.analysis == aid).all()
    controls = Control.query.filter(Control.analysis == aid).all()
    outputs = Output.query.filter(Output.analysis == aid).all()
    ovars = [o.varname for o in outputs if o.varname != None and o.varname != ""]
    ivars = [i.varname for i in inputs if i.varname != None and i.varname != ""]
    cvars = [c.varname for c in controls if c.varname != None and c.varname != ""]
    filename = p.file_name
    file_loc = p.file_location
    csvf = convert.transform(file_loc)
    indices = []
    var_out_info = []
    for i in ivars:
        # Replace missing data
        try:
            csvf[i] = csvf[i].fillna(0)
            # Removing outliers
            outinfo = remOutliers(csvf[i])
            indices = outinfo[0]
            # csvf=csvf.drop(indices)
            var_out_info.append((i, outinfo[1], outinfo[2], outinfo[3]))
        except TypeError as e:
            app.logger.exception(traceback.format_exc())
            flash("Please select only numeric fields")

    # Output Variables
    for o in ovars:
        try:
            csvf[o] = csvf[o].fillna(0)
            # Removing outliers
            outinfo = remOutliers(csvf[o])
            indices = outinfo[0]
            # csvf=csvf.drop(indices)
            var_out_info.append((o, outinfo[1], outinfo[2], outinfo[3]))
        except TypeError as e:
            app.logger.exception(traceback.format_exc())
            flash("Please select only numeric fields")
    # UserSession.query.filter_by(id=sessionid).update({"output":ovars})
    # UserSession.query.filter_by(id=sessionid).update({"input":ivars})
    # UserSession.query.filter_by(id=sessionid).update({"control":cvars})
    # UserSession.query.filter_by(id=sessionid).update({"csvf":csvf})
    print "before storing in session"
    session["ovars"] = ovars
    session["ivars"] = ivars
    session["cvars"] = cvars
    print "type csvf", type(csvf)
    data[pid] = csvf
    # db_session.commit()
    return render_template("outliers.html", data=var_out_info)
示例#2
0
文件: app.py 项目: priya-I/ReadyMade
def transform_data():
	pid=session["pid"]
	aid=session["aid"]
	p=Project.query.filter(Project.id==pid).first()
	inputs=Input.query.filter(Input.analysis==aid).all()
	controls=Control.query.filter(Control.analysis==aid).all()
	outputs=Output.query.filter(Output.analysis==aid).all()
	ovars=[o.varname for o in outputs if o.varname != None and o.varname!='']
	ivars=[i.varname for i in inputs if i.varname != None and i.varname!='']
	cvars=[c.varname for c in controls if c.varname != None and c.varname!='']
	filename=p.file_name
	file_loc=p.file_location
	csvf=convert.transform(file_loc)
	indices=[]
	var_out_info=[]
	for i in ivars:
		#Replace missing data
		try:
			csvf[i]=csvf[i].fillna(0)
			#Removing outliers
			outinfo=remOutliers(csvf[i])
			indices=outinfo[0]
			#csvf=csvf.drop(indices)
			var_out_info.append((i,outinfo[1],outinfo[2],outinfo[3]))
		except TypeError as e:
			app.logger.exception(traceback.format_exc())
			flash('Please select only numeric fields')
			
	#Output Variables
	for o in ovars:
		try:
			csvf[o]=csvf[o].fillna(0)
			#Removing outliers
			outinfo=remOutliers(csvf[o])
			indices=outinfo[0]
			#csvf=csvf.drop(indices)
			var_out_info.append((o,outinfo[1],outinfo[2],outinfo[3]))
		except TypeError as e:
			app.logger.exception(traceback.format_exc())
			flash('Please select only numeric fields')
	session['output']=ovars
	session['input']=ivars
	session['control']=cvars
	data[pid]=csvf
	return render_template("outliers.html",data=var_out_info)