def data_preview(): user = get_user() page = Page() data_type = "" df3_html = "" if request.method == "POST": req = request.form data_type = req.get("data_type") # add action to user log user_log = UserLog(user.id, "data_preview", datetime.now().replace(microsecond=0)) user_log.add() # convert obs file to df path = os.path.join(app.config["OBS_FILES_DIR"] ) #+ ("/{}".format(user.username)) + ("/obs") files = [ name for name in os.listdir(path) if os.path.isfile(os.path.join(path, name)) ] obs_file_1 = path + '/' + 'file1.obs' obs_file_2 = path + '/' + 'file2.obs' df1 = converttoDF(obs_file_1) df2 = converttoDF(obs_file_2) df1[df1.columns[1]] = df1[df1.columns[1]].astype(float) df1[df1.columns[2]] = df1[df1.columns[2]].astype(float) df1[df1.columns[3]] = df1[df1.columns[3]].astype(float) df2[df2.columns[1]] = df2[df2.columns[1]].astype(float) df2[df2.columns[2]] = df2[df2.columns[2]].astype(float) df2[df2.columns[3]] = df2[df2.columns[3]].astype(float) #df1['SWE(1) 1'] = df1['SWE(1) 1'].astype(float) #df1_style = df1.style.apply(highlight_diff_2,threshold=0,column_1=df1.columns, column_2=df2.columns, axis=1) #df1_html = df1_style.render(classes="table table-hover table-striped table-sm table-bordered") #df1.to_html(classes="table table-hover table-striped table-sm table-bordered") #df2_html = df2.to_html(classes="table table-hover table-striped table-sm table-bordered") df3 = df1.merge(df2, on='time', how='outer') df3_style = df3.style.apply(highlight_diff, threshold=1.0, column=df3.columns, axis=1) df3_html = df3_style.render( classes="table table-hover table-striped table-sm table-bordered") #df4 = df1.merge(df2, how ='outer', left_index=True, right_index=True) #df4_html = df4.to_html(classes="table table-hover table-striped table-sm table-bordered") return render_template("public/data_preview.html", data_type=data_type, df3=df3_html, page=page.get_page_number(user))
def data_preview(): user = get_user() if user is None: return redirect(url_for("signin")) data_type = "" df1_html = "" df2_html = "" df3_html = "" df4_html = "" if request.method == "POST": req = request.form data_type = req.get("data_type") print('*************', data_type) # add action to user log user_log = UserLog(user.id, "data_preview", datetime.now().replace(microsecond=0)) user_log.add() # convert obs file to df path = os.path.join(app.config["FILE_UPLOADS"]) + ("/{}".format( user.username)) + ("/obs") files = [ name for name in os.listdir(path) if os.path.isfile(os.path.join(path, name)) ] obs_file_1 = path + '/' + files[0] obs_file_2 = path + '/' + files[1] df1 = converttoDF(obs_file_1) df1_html = df1.to_html( classes="table table-hover table-striped table-sm table-bordered") df2 = converttoDF(obs_file_2) df2_html = df2.to_html( classes="table table-hover table-striped table-sm table-bordered") df3 = df1.merge(df2, on='time', how='outer') df3_html = df3.to_html( classes="table table-hover table-striped table-sm table-bordered") df4 = df1.merge(df2, how='outer', left_index=True, right_index=True) df4_html = df4.to_html( classes="table table-hover table-striped table-sm table-bordered") return render_template("public/data_preview.html", username=user.username, data_type=data_type, df1=df1_html, df2=df2_html, df3=df3_html, df4=df4_html)
def show_plot(): user = get_user() path = os.path.join(app.config["FILE_UPLOADS"]) + ("/{}".format( user.username)) + ("/obs") html_path = os.path.join(app.config["FILE_UPLOADS"]) + ("/{}".format( user.username)) files = [ name for name in os.listdir(path) if os.path.isfile(os.path.join(path, name)) ] obs_file_1 = path + '/' + files[0] obs_file_2 = path + '/' + files[1] df1 = converttoDF(obs_file_1) df2 = converttoDF(obs_file_2) df3 = df1.merge(df2, on='time', how='outer') plot_go(df3, 'test', html_path) return render_template("public/plot.html", username=user.username)
def show_plot(): user = get_user() # add action to user history user_log = UserLog(user.id, "show_plot", datetime.now().replace(microsecond=0)) user_log.add() path = os.path.join(app.config["OBS_FILES_DIR"]) + ("/{}".format( user.username)) + ("/obs") html_path = os.path.join(app.config["HTML_FILE_PATH"]) + ("/{}".format( user.username)) if not os.path.exists(html_path): os.makedirs(html_path) files = [ name for name in os.listdir(path) if os.path.isfile(os.path.join(path, name)) ] if len(files) == 1: obs_file_1 = path + '/' + files[0] df1 = converttoDF(obs_file_1) plot_go(df1, os.path.basename(obs_file_1), html_path) elif len(files) == 2: obs_file_1 = path + '/' + files[0] obs_file_2 = path + '/' + files[1] df1 = converttoDF(obs_file_1) df2 = converttoDF(obs_file_2) df3 = df1.merge(df2, on='time', how='outer') plot_go( df3, os.path.basename(obs_file_1) + ' and ' + os.path.basename(obs_file_2), html_path) return render_template('public/user_html/' + user.username + '/temp-plot.html')
import numpy as np import sys import os from termcolor import colored import plotly.offline as pyo import plotly.graph_objects as go from plot import converttoDF, checkTime, plot import random import secrets obsFile1 = sys.argv[1] obsFile2 = sys.argv[2] mode = sys.argv[3] if mode == 'time': df1 = checkTime(converttoDF(obsFile1)) df2 = checkTime(converttoDF(obsFile2)) df = df1.merge(df2, left_on='time', right_on='time') df.to_csv('merged.csv') elif mode == 'id': df1 = checkTime(converttoDF(obsFile1)) df2 = checkTime(converttoDF(obsFile2)) df = df1.merge(df2, left_on=df1.index, right_on=df2.index) del df['time_y'], df['key_0'] df = df.rename(columns={'time_x': 'time'}) else: print(colored('Error', 'red'), ': mode should be id or time.') plot(df, '{0} and {1} comparison'.format(obsFile1, obsFile2))