def show_results(): try: task.ready() except: db.load('plots.db',False) names = db.getall() return render_template('params.html', params=params, airfoil_params=airfoil_params, status="Click RUN", results="", images = names) if task.ready() == False: global show show = 0 print "not ready" db.load('plots.db',False) names = db.getall() return render_template('params.html', params=params, airfoil_params=airfoil_params, status="PENDING", results="...computing...", images=names) else: global show print "Task Done" if show == 0: try: objects = task.get() except: db.load('plots.db',False) names = db.getall() return render_template('params.html', params=params, airfoil_params=airfoil_params, status="FAILED", results="Something went wrong, return to index and try again...", images=names) for o in objects: obj = o[0] task_name=o[1] #taskname tmp = obj.split() #drag_ligt.m del tmp[:4] #removes "%", "time", "lift", "drag" l1=tmp[::3] #time list l2=tmp[1::3] #lift list l3=tmp[2::3] #drag list l=np.array(l2, dtype=np.float) #lift array d=np.array(l3, dtype=np.float) #drag array t=np.array(l1, dtype=np.float) #time array pic_name = "air"+task_name + ".png" pic_path = "static/" + pic_name db.set(pic_name, pic_path) #uploads the results to the db #plot and save it as png with open(pic_path,'w') as image: plot(image, t, l, d, 'b') db.dump() #saves the db put_file('plots.db', 'plots.db') #uploads the db to the container #uploads the files as a python thread for not blocking the webapplication thread.start_new_thread( put_file, (pic_name, pic_path, ) ) show = 1 print "got results" names = db.getall() return render_template('params.html', params=params, airfoil_params=airfoil_params, status="DONE", results="Click on the buttons to change pictures", images=names)
def show_results(): try: task.ready() except: db.load('plots.db',False) names = db.getall() #names = os.listdir(os.path.join(app.static_folder)) return render_template('params.html', params=params, airfoil_params=airfoil_params, status="Click RUN", results="", images = names) if task.ready() == False: global show show = 0 print "not ready" db.load('plots.db',False) names = db.getall() #names = os.listdir(os.path.join(app.static_folder)) return render_template('params.html', params=params, airfoil_params=airfoil_params, status="PENDING", results="...computing...", images=names) else: global show print "Task Done" status = "DONE" if show == 0: try: objects = task.get() except: names = db.getall() return render_template('params.html', params=params, airfoil_params=airfoil_params, status="FAILED", results="Something went wrong, return to index and try again...", images=names) for o in objects: print o obj = o[0] task_name=o[1] print task_name tmp = obj.split() tmp.pop(0) #remove % print "...1" l1 = tmp[::3] l2=tmp[1::3] l3=tmp[2::3] l1.pop(0) #remove time l2.pop(0) #remove lift l3.pop(0) #remove drag a=np.array(l2, dtype=np.float) b=np.array(l3, dtype=np.float) d= np.array(l1, dtype = np.float) pic_name = "air"+task_name + ".png" pic_path = "static/" + pic_name db.set(pic_name, pic_path) with open(pic_path,'w') as image: plot(image, d, a, b, 'b') db.dump() put_file('plots.db', 'plots.db') #upload_thread = threading.Thread(target=put_file, args=(pic_name, pic_path, )) thread.start_new_thread( put_file, (pic_name, pic_path, ) ) #put_file(pic_name, pic_path) #LD = "Best L/D ratio: %f" %(np.max(c)) #r = requests.post("https://smog.uppmax.uu.se/dashboard/project/containers/matstorage/", # files={pic_name: open(pic_path, 'rb')}) #r = requests.post("https://smog.uppmax.uu.se/dashboard/project/containers/matstorage/", # files={'plots.db': open('plots.db', 'rb')}) results = "Click on the buttons to change pictures" show = 1 print "got results" #names = os.listdir(os.path.join(app.static_folder)) names = db.getall() global results global status return render_template('params.html', params=params, airfoil_params=airfoil_params, status=status, results=results, images=names)