def update_results(): # get user choices if they exist (batch required) bSelected = request.args.get('bSelected', type=str) if len(bSelected) == 0: # TODO: Figure out a better way to catch this error, probably # through html solution that requires user to choose batch before # using other selects return jsonify(resultstable="MUST SELECT A BATCH") cSelected = request.args.getlist('cSelected[]') mSelected = request.args.getlist('mSelected[]') #query narf results by batch, store in dataframe results = qg.QueryGenerator(dbc,tablename='NarfResults',\ batchnum=bSelected).send_query() # TODO: Figure out why models parsed from analysis selection aren't # matching up with cells filtered by batch selection. #filter dataframe by selected cells, if any if not (len(cSelected) == 0): results = results[results.cellid.isin(cSelected)] #same for selected models, if any if not (len(mSelected) == 0): results = results[results.modelname.isin(mSelected)] return jsonify(resultstable=results.to_html(classes='table-hover\ table-condensed'))
def main_view(): tablelist = 'NarfResults' plottypelist = 'Scatter' measurelist = 'r_test' resultstable = '' # TODO: Figure out how to get initial lists to load faster - added distinct # and field selections to shrink query, but initial page load is still very slow # if selection limit is lifted (so far tested up to 200k, takes ~20 seconds to load) # possibility: organize as analysis, batch, model objects and load a global-scope # dataframe with the relevant data on app launch? then just have view functions index # into dataframe as needed instead of generating new queries each time analyses = qg.QueryGenerator(dbc, column='name', tablename='NarfAnalysis').send_query() analyses = analyses.iloc[:, 0] #convert from 1-dim df to series analysislist = analyses.tolist() batches = qg.QueryGenerator(dbc,distinct=True,column='batch',tablename=\ 'NarfBatches').send_query() batches = batches.iloc[:, 0] batchlist = batches.tolist() # Leave this out for now to improve page load time """ ## Maybe don't need this one with new setup? Cells can just populate after ## analysis is selected. Unless want to be able to sort by a specific cell first. cells = qg.QueryGenerator(dbc,distinct=True,column='cellid',tablename='NarfBatches').send_query() cells = cells.iloc[:,0] # get unique list since there are duplicates celllist = cells.tolist() models = qg.QueryGenerator(dbc,distinct=True,column='modelname',tablename='NarfResults').send_query() models = models.iloc[:,0] modellist = models.tolist() """ return render_template('main.html', analysislist = analysislist,\ tablelist = tablelist,\ batchlist = batchlist,\ #celllist = celllist,\ #modellist = modellist,\ plottypelist = plottypelist, measurelist = measurelist, )
def view_database(): tablelist = 'NarfResults' batches = qg.QueryGenerator(dbc, column='batch', tablename='NarfBatches').send_query() batches = batches.iloc[:, 0] # get unique list since there are duplicates batchlist = list(set(batches.tolist())) models = qg.QueryGenerator(dbc, column='modelname', tablename='NarfResults').send_query() models = models.iloc[:, 0] modellist = list(set(models.tolist())) return render_template('database.html', tablelist=tablelist, batchlist=batchlist,\ modellist=modellist)
def update_cells(): bSelected = request.args.get('bSelected', 'no selection', type=str) celllist = qg.QueryGenerator(dbc,column='cellid',tablename='NarfBatches',\ batchnum=bSelected).send_query() celllist = celllist.iloc[:, 0].tolist() return jsonify(celllist=celllist)
def update_batch(): aSelected = request.args.get('aSelected', 'no selection', type=str) batch = qg.QueryGenerator(dbc,tablename='NarfAnalysis',\ analysis=aSelected).send_query() # get string of first 3 characters, rest is description of batch batchnum = batch['batch'].iloc[0][:3] #return batchnum for selected analysis in jQuery-friendly format return jsonify(batchnum=batchnum)
def req_query(tablename, batchnum, modelname): # parse variables from URL and pass to QueryGenerator object as attributes query = qg.QueryGenerator(tablename, batchnum, modelname) # populate dataframe by calling send_query() on qg object data = query.send_query() # TODO: Figure out best practice for when and where to close database connection. # For now, will continue putting it in any time the conneciton is no longer needed # for current operation. query.close_connection() # generate descriptive table title from variables tabletitle = ("%s, filter by: batch=%s, model=%s" % (tablename, batchnum, modelname)) # generage html page via table.html template, pass in html export of dataframe # and table title as variables return render_template('table.html', table=data.to_html(classes='Table'),\ title=tabletitle)
def req_query(): # add if statements to check if request data exists before pulling tablename = request.form['tablename'] batchnum = request.form['batchnum'] modelname = request.form['modelname'] query = qg.QueryGenerator(dbc,tablename=tablename,batchnum=batchnum,\ modelname=modelname) # populate dataframe by calling send_query() on qg object data = query.send_query() tabletitle = ("%s, filter by: batch=%s, model=%s" % (tablename, batchnum, modelname)) # generage html page via table.html template, pass in html export of dataframe # and table title as variables return render_template('table.html', table=data.to_html(classes='table'),\ title=tabletitle)
def update_models(): aSelected = request.args.get('aSelected', 'no selection', type=str) #currently disabled until modelfinder methods are fixed - combo array #recursion crashing website analysis = qg.QueryGenerator(dbc,column='modeltree',tablename='NarfAnalysis',\ analysis=aSelected).send_query() # pull modeltree text from NarfAnalysis # and convert to string rep modeltree = analysis.iloc[0, 0] modelFinder = mf.ModelFinder(modeltree) modellist = modelFinder.modellist #modellist = ['testing','jquery','code','for','analysis','update',aSelected] return jsonify(modellist=modellist)
- Used to parse modelstring from NarfAnalysis - into a list of model names that can be passed back - to model selector """ import ast import re #for testing w/ actual model string import QueryGenerator as qg import DB_Connection as dbcon db = dbcon.DB_Connection() dbc = db.connection analysis = qg.QueryGenerator(dbc, tablename='NarfAnalysis', analysis='Jake Test').send_query() modstring = analysis['modeltree'][0] """ # for testing with simpler nested list that (hopefully) won't crash the universe modstring = "{'a','b', {{'c','d'},{ 'e','f' }}, 'g'}" # list of combos should end up as: # ['abceg','abcfg','abdeg','abdfg'] """ class ModelFinder(): def __init__(self, modelstring=''): self.modelstring = modelstring # as soon as modelstring is passed, go ahead and # parse into array then to list so that attribs can be retrieved