def elbow_plot_handler_old(request): resp_data = dict() file_name = request.GET.get("file_name") column_header = request.GET.get("column_header") exclude_columns = request.GET.get("exclude_columns") print(column_header) if file_name: fs = FileStorage() file_full_path = fs.get_base_location() + file_name # If the file does exist, read data by panda and drop columns (if any) if fs.is_file(file_full_path): # Get data from file column_header_idx = None if column_header == "on": column_header_idx = 0; df = DataFrameUtil.convert_file_to_dataframe(file_full_path, header=column_header_idx) # Drop column specified by user if exclude_columns: str_column_indexs = exclude_columns.split(",") # column_indexs = list(map(int, str_column_indexs)) column_indexs = [int(i) - 1 for i in str_column_indexs] df = DataFrameUtil.drop_column_by_index(df, column_indexs) is_nan = np.any(np.isnan(df)) is_finite = np.all(np.isfinite(df)) # Standardize data X_scaled = PreProcessingUtil.standardize(df) # Get explain variance ratio pca_helper = PcaUtil() pca = pca_helper.get_fit_transfrom_pca(X_scaled) arr_variance_ratio = pca.explained_variance_ratio_ # Prepare all tabs to display Plot, Table by Bokeh # Add ratio to bokeh line graph elbow_plot = draw_elbow_plot(arr_variance_ratio) # Describe data # df_describe = df.describe().to_json() # df_describe_table = draw_df_describe_table(df) # Add line to a panel tab1 = Panel(child=elbow_plot, title="Elbow Curve Plot") # tab2 = Panel(child=df_describe_table, title="Data Description") # Add a panel to tab tabs = Tabs(tabs=[ tab1 ]) script, div = components(tabs) plots = { 'script': script, 'div': div} resp_data["bokeh_plot"] = plots # resp_data["data_describe"] = bokeh_df_describe_table else: resp_data["msg"] = "[ERROR] File is not found." else: resp_data['msg'] = "[ERROR] File name is invalid." return JsonResponse(resp_data)
def elbow_plot_handler(request): form = PcaPlotForm(request.POST, request.FILES) resp_data = dict(); if form.is_valid(): # Get input files data_file = form.cleaned_data["data_file"] df_input = DataFrameUtil.file_to_dataframe(data_file, header=None) X_scaled = PreProcessingUtil.standardize(df_input) # Get explain variance ratio pca_helper = PcaUtil() pca = pca_helper.get_fit_transfrom_pca(X_scaled) arr_variance_ratio = pca.explained_variance_ratio_ # Prepare all tabs to display Plot, Table by Bokeh # Add ratio to bokeh line graph elbow_plot = draw_elbow_plot(arr_variance_ratio) # Add line to a panel tab1 = Panel(child=elbow_plot, title="Elbow Curve Plot") # tab2 = Panel(child=df_describe_table, title="Data Description") # Add a panel to tab tabs = Tabs(tabs=[ tab1 ]) script, div = components(tabs) plots = { 'script': script, 'div': div} resp_data["bokeh_plot"] = plots else: resp_data[msg.ERROR] = escape(form._errors) return JsonResponse(resp_data)