def updateDf(self, files: list): """ checks if the dataframe can be updated by the newly imported filepaths calls the merge function if there is more than 1 file inside the filelist also udpates the detector frame (displaying dialect data) :param files: the whole filepath list """ if len(files) > 1 or len(self.XMLList) > 0: canMerge = merger.prepareMerge(files, self.XMLList, self.DialectList) self.DialectList = merger.dialectList if canMerge: newDataFrame = merger.mergeFiles() importer.setDataFrame(newDataFrame) self.pt.updateModel(TableModel(newDataFrame)) self.pt.redraw() elif len(files) > 0 and files[0].endswith(".csv"): if not any(files[0] in x for x in self.DialectList): self.dialect.guessDialectCSV(files[0]) self.DialectList.append([files[0], self.dialect]) else: x = [x for x in self.DialectList if files[0] in x][0] self.dialect = self.DialectList[self.DialectList.index(x)][1] importer.importCSV(files[0], self.dialect) updatedDataframe = importer.getDataFrame() self.pt.updateModel(TableModel(updatedDataframe)) self.pt.redraw() self.updateDialect(self.dialect)
def userData(self): self.__foodButton['state'] = NORMAL self.__userButton['state'] = DISABLED self.__selectedState = Sheets.USER self.df = self.table.model.df self.table.updateModel(TableModel(self.uf)) self.table.redraw()
def run_query(self): self.user_query, self.query_group_str, self.agg_function, self.user_agg, self.agg_name, self.cur_table_name = self.query_temp.get_query( ) # logger.debug(self.user_query) self.handle_view ="\nDROP VIEW IF EXISTS user_query;"+\ "\nCREATE VIEW user_query as "+ self.user_query # logger.debug(self.handle_view) try: self.cur.execute(self.handle_view) except: tkinter.messagebox.showinfo("Info", "Invalid Query, Please Doublecheck!") self.original_query_result_df = pd.read_sql(self.user_query, self.conn) self.query_result_df = self.original_query_result_df self.plot_data_convert_dict, self.query_data_convert_dict = self.db_info.get_db_data_type( self.cur_table_name) self.plot_data_convert_dict[self.agg_name] = 'numeric' self.query_data_convert_dict[self.agg_name] = 'float' self.assigned_global_table = 'dev.{}_global'.format( self.cur_table_name) self.assigned_local_table = 'dev.{}_local'.format(self.cur_table_name) model = TableModel(dataframe=self.original_query_result_df) self.query_result_table.updateModel(model) self.query_result_table.redraw()
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) df = self.get_cryptocurrency() tb_m = TableModel(dataframe=df) table = Table(self, model=tb_m) table.show() table.redraw()
def update_window(self, x0, y0, x, h): """ Updates the graphs and the table accroding to the given data :param x0: initial position on x-axis :param y0: f(x0) :param x: final position on x-axis :param h: a grid step :return: None """ x0_new, y0_new, x_new, h_new = float(x0.get()), float(y0.get()), float( x.get()), float(h.get()) if x0_new < x_new and h_new > 0 and y0_new > 0 and ( x_new - x0_new) / h_new <= 10000: plt.figure(1).gca().clear() plt.figure(2).gca().clear() plt.figure(3).gca().clear() df = self.plot.draw_functions( plt.figure(1).gca(), x0_new, y0_new, x_new, h_new) self.canvas1.draw() self.plot.draw_local_errors( plt.figure(2).gca(), x0_new, y0_new, x_new, h_new) self.canvas2.draw() self.plot.draw_approximation_errors( plt.figure(3).gca(), x0_new, y0_new, x_new) self.canvas3.draw() self.table.updateModel(TableModel(df)) self.table.show()
def use_global_filter_local(self): pattern_df_lists = [] for n in self.global_pattern_table.multiplerowlist: model_name = self.global_pattern_table.model.df.iloc[int( n)]['model'] # logger.debug("model_name"+model_name) global_partition = self.global_pattern_table.model.df.iloc[int( n)]['partition'] global_predictor = self.global_pattern_table.model.df.iloc[int( n)]['predictor'] g_filter_l_query = " select array_to_string(fixed,',') as Partition,array_to_string(variable,',') as Predictor,"+\ "array_to_string(fixed_value,',') as partition_values,agg,model,fixed,fixed_value,variable,"+\ "theta,param,stats,dev_pos,dev_neg from "+self.assigned_local_table+\ " where array_to_string(fixed,',')='"+global_partition+\ "' and array_to_string(variable,',')='"+global_predictor+\ "' and model = '"+model_name+"';" self.local_output_pattern_df = pd.read_sql(g_filter_l_query, self.conn) # logger.debug(g_filter_l_query) local_shown = self.local_output_pattern_df[[ 'partition', 'partition_values', 'predictor', 'agg' ]] model = TableModel(dataframe=local_shown) self.local_pattern_table.updateModel(model) self.local_pattern_table.redraw()
def show_updated_output(self): filtered_result_df = self.use_local_filter_output()[1] self.query_result_df = filtered_result_df model = TableModel(dataframe=filtered_result_df) self.query_result_table.updateModel(model) self.query_result_table.redraw()
def reset_output(self): model = TableModel(dataframe=self.original_query_result_df) self.query_result_table.updateModel(model) self.query_result_table.redraw() self.query_result_df = self.original_query_result_df
def import_csv(self): # Get file to import input_file = tkFileDialog.askopenfilename() if not input_file.strip(): tkMessageBox.showerror(title="Import Failed", message="Import failed as no file was selected.") return try: import_df = pd.read_csv(input_file) except ParserError: tkMessageBox.showerror( "The supplied file is not a valid CSV file, could not import.") if len(import_df) > 0: # Data was loaded. DataStore.data.reset_index(level=["id_product"], inplace=True) table_df = DataStore.data.append(import_df, ignore_index=False) table_df.set_index("id_product", inplace=True) DataStore.data = table_df self.data_table.updateModel(TableModel(table_df)) self.data_table.redraw() tkMessageBox.showinfo(title="Import Successful", message="Import Completed Successfully!") else: tkMessageBox.showinfo(title="Import Failed", message="Input file did not have any CSV data so no data was added.")
def filter_data(): global df global table # df.drop('column_name', axis=1, inplace=True) # df.drop(df.columns[[0, 1, 3]], axis=1) # df.drop([Column Name or list],inplace=True,axis=1) def f(x): suf = '(?={0})[^0-9]*'.format(re.escape(suf_filter.get())) bf = '(?={0})[^0-9]*'.format(re.escape(bf_filter.get())) hf = '(?={0})[^0-9]*'.format(re.escape(hf_filter.get())) chf = '(?={0})[^0-9]+'.format(re.escape(chf_filter.get())) b = ((active_characters[x[CHAR]].get() == 1) and (command_filter.get() == '' or x[CMD] == command_filter.get()) and (hl_filter.get() == '' or re.match(hl_filter.get(), x[HL]) is not None) and (suf_filter.get() == '' or re.match(suf, x[SUF]) is not None) and (bf_filter.get() == '' or re.search(bf, x[BF]) is not None) and (hf_filter.get() == '' or re.search(hf, x[HF]) is not None) and (chf_filter.get() == '' or re.search(chf, x[CHF]) is not None)) return b tf = df[df[[CHAR, CMD, HL, SUF, BF, HF, CHF]].apply(f, axis=1)] temp = table.model.columnwidths table.model = TableModel(tf) table.model.columnwidths = temp table.redraw()
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) df = self.get_history() tb_m = TableModel(dataframe=df) table = Table(self, model=tb_m) table.show() #alter the DataFrame in some way, then update table.redraw()
def get_data_for_symbol_list(self, parameter): self.parameter = parameter self.setting_view.update_view(parameter=parameter) df = self.get_correlation() tbm = TableModel(dataframe=df) self.table.model = tbm self.table.show() self.table.redraw()
def reset_output(self): model = TableModel(dataframe=self.original_query_result_df) self.query_result_table.updateModel(model) self.query_result_table.redraw() self.query_result_table.setRowColors( rows=self.high_outlier_row_numbers, clr='#ffffff', cols='all') self.query_result_table.setRowColors(rows=self.low_outlier_row_numbers, clr='#ffffff', cols='all') self.query_result_df = self.original_query_result_df
def refresh_table_data(self): res = tkMessageBox.askyesno(title="Ready to reboot DB.", message="Ready to reboot DB.\n" "Undo") if res == tkMessageBox.NO: return data_df = get_db_data() Vault.data = data_df self.data_table.updateModel(TableModel(data_df)) self.data_table.redraw()
def update(self): history = HistoryController.History() self.parameters = history.get_all_parameter_from_history() self.parameter_list = ParameterList(self, self.parameters) self.parameter_list.grid(row=1, column=1, sticky=(tk.N, tk.S, tk.E, tk.W)) self.parameter_list.config(relief=tk.GROOVE, bd=2) df = self.get_correlation() tbm = TableModel(dataframe=df) if df.empty: return True self.table.model = tbm self.table.show() self.table.redraw()
def show_global_pattern(self): global_query = "select array_to_string(fixed,',') as Partition,array_to_string(variable,',') as Predictor,agg,"+\ "round((lambda)::numeric(4,2),2) as Support,model from "+self.assigned_global_table+\ " where array_to_string(array_sort(fixed||variable),',')='"+self.query_group_str+"';" # logger.debug(global_query) self.global_pattern_df = pd.read_sql(global_query, self.conn) # logger.debug(self.global_pattern_df.head()) # logger.debug(list(self.global_pattern_df)) pattern_model = TableModel(dataframe=self.global_pattern_df) self.global_pattern_table.updateModel(pattern_model) self.global_pattern_table.redraw()
def refresh_table_data(self): res = tkMessageBox.askyesno(title="Are you sure you want to refresh the DB.", message="Are you sure that you want to refresh the DB.\n" "This will undo any changes that you made before saving your data. This includes CSV file that you have imported") if res == tkMessageBox.NO: return data_df = get_db_data() DataStore.data = data_df self.data_table.updateModel(TableModel(data_df)) self.data_table.redraw()
def show_updated_output(self): self.low_outlier_text = Label(self.high_low_frame, text='Unusually\nLow: ', font=('Times New Roman bold', 10), bg='light yellow') self.low_outlier_text.grid(column=0, row=0) self.low_outlier_label = Label(self.high_low_frame, bg='#98df8a', height=2, width=2) self.low_outlier_label.grid(column=1, row=0) self.high_outlier_text = Label(self.high_low_frame, text='Unusually\nHigh: ', font=('Times New Roman bold', 10), bg='light yellow') self.high_outlier_text.grid(column=0, row=1) self.high_outlier_label = Label(self.high_low_frame, bg='#ff9896', height=2, width=2) self.high_outlier_label.grid(column=1, row=1) if (self.low_outlier_row_numbers): self.query_result_table.setRowColors( rows=self.low_outlier_row_numbers, clr='#ffffff', cols='all') if (self.high_outlier_row_numbers): self.query_result_table.setRowColors( rows=self.high_outlier_row_numbers, clr='#ffffff', cols='all') chosen_row, filtered_result_df = self.use_local_filter_output() low_outlier_rows, self.low_outlier_row_numbers, high_outlier_rows, self.high_outlier_row_numbers = self.get_outlier_frame( chosen_row, filtered_result_df) self.query_result_df = filtered_result_df model = TableModel(dataframe=filtered_result_df) self.query_result_table.updateModel(model) self.query_result_table.redraw() if (self.low_outlier_row_numbers): self.query_result_table.setRowColors( rows=self.low_outlier_row_numbers, clr='#98df8a', cols='all') if (self.high_outlier_row_numbers): self.query_result_table.setRowColors( rows=self.high_outlier_row_numbers, clr='#ff9896', cols='all')
def show_local_pattern(self): local_query = "select array_to_string(fixed,',') as Partition,array_to_string(variable,',') as Predictor,"+\ "array_to_string(fixed_value,',') as partition_values,agg,model,fixed,fixed_value,variable,"+\ "theta,param,stats,dev_pos,dev_neg from "+self.assigned_local_table+\ " where array_to_string(array_sort(fixed||variable),',')='"+self.query_group_str+"';" for n in self.local_pattern_table.multiplerowlist: self.chosen_local_pattern = self.global_pattern_table.model.df.iloc[ int(n)] self.local_output_pattern_df = pd.read_sql(local_query, self.conn) local_shown = self.local_output_pattern_df[[ 'partition', 'partition_values', 'predictor', 'agg' ]] pattern_model = TableModel(local_shown) self.local_pattern_table.updateModel(pattern_model) self.local_pattern_table.redraw()
def run_query(self): self.low_outlier_text.destroy() self.low_outlier_label.destroy() self.high_outlier_text.destroy() self.high_outlier_label.destroy() self.user_query, self.query_group_str, self.agg_function, self.user_agg, self.agg_name, self.cur_table_name = self.query_temp.get_query( ) # logger.debug(self.user_query) self.handle_view ="\nDROP VIEW IF EXISTS user_query;"+\ "\nCREATE VIEW user_query as "+ self.user_query # logger.debug(self.handle_view) try: self.cur.execute(self.handle_view) self.conn.commit() except: tkinter.messagebox.showinfo("Info", "Invalid Query, Please Doublecheck!") self.original_query_result_df = pd.read_sql(self.user_query, self.conn) self.query_result_df = self.original_query_result_df self.plot_data_convert_dict, self.query_data_convert_dict = self.db_info.get_db_data_type( self.cur_table_name) self.plot_data_convert_dict[self.agg_name] = 'numeric' self.query_data_convert_dict[self.agg_name] = 'float' self.assigned_global_table = 'pattern.{}_global'.format( self.cur_table_name) self.assigned_local_table = 'pattern.{}_local'.format( self.cur_table_name) model = TableModel(dataframe=self.original_query_result_df) self.query_result_table.updateModel(model) self.query_result_table.setRowColors( rows=self.high_outlier_row_numbers, clr='#ffffff', cols='all') self.query_result_table.setRowColors(rows=self.low_outlier_row_numbers, clr='#ffffff', cols='all') self.query_result_table.redraw()
def open(self): if self.view.column_mapping_dataframe is None: self.model = TableModel(dataframe=pd.read_excel( io=self.view.wb_filename, header=self.view.header_row - 1, sheet_name=self.view.ws_name_selection)) self.mapper_dict = {} for column_name in self.model.df.columns.values.tolist(): self.mapper_dict[column_name] = ColumnMapper( master_frame=self, paned_frame=self.mapping_paned_window, col_name=column_name) for obj in self.mapper_dict.values(): self.mapping_paned_window.add(obj, minsize=30, stretch="never") else: self.model = self.view.column_mapping_dataframe self.table.updateModel(self.model) self.table.statusbar.update() self.bind_all("<KP_8>", self.table.handle_arrow_keys) self.bind_all("<Return>", self.table.handle_arrow_keys) self.bind_all("<Tab>", self.table.handle_arrow_keys) self.grid()
def import_csv(self): input_file = tkFileDialog.askopenfilename() if not input_file.strip(): tkMessageBox.showerror(title="Error, Failed!", message="...") return try: import_df = pd.read_csv(input_file) except ParserError: tkMessageBox.showerror("Failed, Try again!.") if len(import_df) > 0: Vault.data.reset_index(level=["id_product"], inplace=True) table_df = Vault.data.append(import_df, ignore_index=False) table_df.set_index("id_product", inplace=True) Vault.data = table_df self.data_table.updateModel(TableModel(table_df)) self.data_table.redraw() tkMessageBox.showinfo(title="Done",message="Pass") else: tkMessageBox.showinfo(title="Error, Failed!", message="...")
def __update_table(self): """__update_table updates pandastable to display the actual dataframe""" self.__pdtable.updateModel(TableModel(self.__importer.dfx)) self.__pdtable.redraw()
def run_search(self): self.search_results_df = pd.DataFrame() self.table.updateModel(TableModel(self.search_results_df)) self.table.redraw() self.status_str.set("Running search...") self.parent.update() try: # see doc under https://linkedin-api.readthedocs.io/en/latest/api.html search_result = self.linkedin_conn[0].search_people( network_depths=[ x['name'] for x in self.con_dict_list if x['bool_val'].get() ], connection_of=next( (x.value for x in self.conn_of_frame.get_current_selection()), None), regions=[ x.value for x in self.loc_frame.get_current_selection() ], current_company=[ x.value for x in self.current_comp_frame.get_current_selection() ], past_companies=[ x.value for x in self.past_comp_frame.get_current_selection() ], schools=[ x.value for x in self.school_frame.get_current_selection() ], industries=[ x.value for x in self.industry_frame.get_current_selection() ], keywords=self.entry_keywords.get(), keyword_first_name=self.entry_keywords_first_name.get(), keyword_last_name=self.entry_keywords_last_name.get(), keyword_title=self.entry_keywords_title.get(), keyword_company=self.entry_keywords_company.get(), keyword_school=self.entry_keywords_school.get(), ) if self.quick_search: self.search_results_df = pd.DataFrame(search_result) self.table.updateModel(TableModel(self.search_results_df)) self.table.redraw() else: result_size = len(search_result) self.status_str.set( "Found " + str(result_size) + " results! Searching contact details... This can take a while..." ) self.parent.update() if result_size > 999: answer_is_yes = messagebox.askyesno( "Too many results!", "This search yields more than 1000 results (upper limit for this app).\nProceed anyway?", icon="warning") if not answer_is_yes: self.status_str.set("Search cancelled.") self.parent.update() return row = 1 for people in search_result: profile = self.linkedin_conn[0].get_profile( urn_id=people['urn_id']) if profile != {}: if 'geoLocationName' in profile.keys(): geolocation = profile['geoLocationName'] else: geolocation = "" profile_dict = { 'First Name': [profile['firstName']], 'Last Name': [profile['lastName']], 'Title': [profile['experience'][0]['title']], 'Company': [profile['experience'][0]['companyName']], 'Location': [geolocation], 'Headline': [profile['headline']], 'Profile Link': [ 'https://www.linkedin.com/in/' + profile['profile_id'] ] } if self.get_skills.get(): skills_raw = self.linkedin_conn[ 0].get_profile_skills(urn_id=people['urn_id']) skills = [dic['name'] for dic in skills_raw] profile_dict.update({'Skills': [skills]}) if self.get_contact_info.get(): contact_info = self.linkedin_conn[ 0].get_profile_contact_info( urn_id=people['urn_id']) contact_info = { k: [v] for k, v in contact_info.items() } profile_dict.update(contact_info) self.search_results_df = pd.concat([ self.search_results_df, pd.DataFrame(profile_dict) ]) self.table.updateModel( TableModel(self.search_results_df)) self.table.redraw() self.status_str.set("Scanned " + str(row) + " out of " + str(result_size) + " profiles") self.parent.update() row += 1 self.export_to_file_btn.configure(state="normal") self.status_str.set("Done") self.parent.update() except Exception as e: utils.show_exception(e) self.status_str.set( "Something went wrong! Check console output for more details.") self.parent.update()
def handle_question(self, direction): self.question_tuple = '' config = ExplConfig() config.conn = self.config.conn config.cur = self.config.cur config.query_table_name = self.cur_table_name eg = ExplanationGenerator( config, { 'pattern_table': 'dev.{}'.format(self.cur_table_name), 'query_result_table': self.cur_table_name }) eg.initialize() col_name = [ 'Explanation_Tuple', "Score", 'From_Pattern', "Drill_Down_To", "Distance", "Outlierness", "Denominator", "relevent_model", "relevent_param", "refinement_model", "drill_param" ] exp_df = pd.DataFrame(columns=[ "From_Pattern", "Drill_Down_To", "Score", "Distance", "Outlierness", "Denominator", "relevent_model", "relevent_param", "refinement_model", "drill_param" ]) for n in self.query_result_table.multiplerowlist: self.question = self.query_result_table.model.df.iloc[[int(n)]] self.original_question = self.question.copy(deep=True) self.question.rename(columns={self.agg_name: self.user_agg}, inplace=True) self.question_tuple = self.query_result_df.iloc[[int(n)]] # logger.debug(self.question) self.question['direction'] = direction self.question['lambda'] = 0.2 question = self.question.iloc[0].to_dict() # logger.debug(question) elist = eg.do_explain_online(question) exp_list = [] for e in elist: tuple_list = [] # print(str(e.tuple_value)) # print(str(e.tuple_value.keys())) # e_tuple_str = ','.join(map(str, e.tuple_value.values())) e_tuple_str = e.ordered_tuple_string() tuple_list.append(e_tuple_str) score = round(e.score, 2) tuple_list.append(score) if e.expl_type == 1: local_pattern=( '[' + ','.join(e.relevent_pattern[0]) +\ '=' + ','.join(list(map(str, e.relevent_pattern[1]))) +']:'+ \ ','.join(list(map(str, e.relevent_pattern[2])))+' \u2933 '+self.agg_name ) relevent_model = e.relevent_pattern[4] if e.relevent_pattern[4] == 'const': relevent_param = str( round( float(e.relevent_pattern[6].split(',')[0][1:]), 2)) else: # relevent_param = 'Intercept=' + str(e.relevent_pattern[7]['Intercept'])+', '+str(list(e.relevent_pattern[7])[1])+'='+str(round(e.relevent_pattern[7][list(e.relevent_pattern[7])[1]],2)) relevent_param = e.relevent_pattern[7] drill_down_to = ','.join([ x for x in e.refinement_pattern[0] if x not in e.relevent_pattern[0] ]) refinement_model = e.refinement_pattern[4] if e.refinement_pattern[4] == 'const': drill_param = str( round( float( e.refinement_pattern[6].split(',')[0][1:]), 2)) else: drill_param = e.refinement_pattern[7] else: relevent_model = e.relevent_pattern[4] local_pattern=( '[' + ','.join(e.relevent_pattern[0]) +\ '=' + ','.join(list(map(str, e.relevent_pattern[1]))) +']:'+ \ ','.join(list(map(str, e.relevent_pattern[2])))+' \u2933 '+self.agg_name ) if e.relevent_pattern[4] == 'const': relevent_param = str( round( float(e.relevent_pattern[6].split(',')[0][1:]), 2)) else: # relevent_param = 'Intercept=' + str(e.relevent_pattern[7]['Intercept'])+', '+str(list(e.relevent_pattern[7])[1])+'='+str(e.relevent_pattern[7][list(e.relevent_pattern[7])[1]]) relevent_param = e.relevent_pattern[7] refinement_model = '' drill_down_to = '' drill_param = '' tuple_list.append(local_pattern) tuple_list.append(drill_down_to) distance = round(e.distance, 2) tuple_list.append(distance) outlierness = round(e.deviation, 2) tuple_list.append(outlierness) denominator = round(e.denominator, 2) tuple_list.append(denominator) tuple_list.append(relevent_model) tuple_list.append(relevent_param) tuple_list.append(refinement_model) tuple_list.append(drill_param) exp_list.append(tuple_list) df_exp = pd.DataFrame(exp_list, columns=col_name) exp_df = exp_df.append(df_exp, ignore_index=True) self.exp_df = exp_df[col_name] model = TableModel(dataframe=self.exp_df) self.exp_table.updateModel(model) self.exp_table.redraw()
def update(self, standings) -> None: self.table.updateModel(TableModel(standings)) self.table.redraw()
def filter_data(): global df global table def f(row: pandas.core.series.Series): if not active_characters[row[CHAR]].get() == 1: return False filt = command_filter.get() if filt: if not row[CMD] == filt: return False filt = hl_filter.get() if filt: cell = row[HL] #TODO(edahl): debug TC and TJ if not re.match(filt, cell) or \ not filter_on_token(filt, cell, 'TC') or \ not filter_on_token(filt, cell, 'TJ'): return False # Query numbers filt = suf_filter.get() if filt: cell = row[SUF] if not filter_on_number(filt, row[SUF]) or \ not filter_on_token(filt, cell, 's') or \ not filter_on_token(filt, cell, 'a'): return False filt = bf_filter.get() if filt: cell = row[BF] if not filter_on_number(filt, cell) or \ not filter_on_token(filt, cell, 'KND') or \ not filter_on_token(filt, cell, 'CS'): return False filt = hf_filter.get() if filt: cell = row[HF] if not filter_on_number(filt, cell) or \ not filter_on_token(filt, cell, 'KND') or \ not filter_on_token(filt, cell, 'CS'): return False filt = chf_filter.get() if filt: cell = row[CHF] if not filter_on_number(filt, cell) or \ not filter_on_token(filt, cell, 'KND') or \ not filter_on_token(filt, cell, 'CS'): return False notes = '(?={0})'.format(re.escape(notes_filter.get())) if not (notes_filter.get() or re.search(notes, row[NOTES], re.IGNORECASE) is not None): return False return True tf = df[df[[CHAR, CMD, HL, SUF, BF, HF, CHF, NOTES]].apply(f, axis=1)] # Preserve widths tmp_widths = table.model.columnwidths table.model = TableModel(tf) table.model.columnwidths = tmp_widths table.redraw()
def updateData(self, data): model = TableModel(pd.DataFrame.from_records(data)) self.table.updateModel(model) self.table.redraw()
def filter_characters(): global df global table table.updateModel(TableModel(df[df[SUF] == '12'])) table.redraw()
def run_search(self): self.search_results_df = pd.DataFrame() self.table.updateModel(TableModel(self.search_results_df)) self.table.redraw() self.status_str.set("Running search...") self.parent.update() loc_fallback = None if self.loc_fallback_frame.get_current_selection(): loc_fallback = self.loc_fallback_frame.get_current_selection()[0].lbl_name.get() try: # see doc under https://linkedin-api.readthedocs.io/en/latest/api.html search_result = self.linkedin_conn[0].search_jobs( keywords=self.entry_keywords.get(), sort_by=self.sort_by.get(), listed_at=24 * 3600 * self.date_posted.get(), companies=[x.value for x in self.comp_frame.get_current_selection()], experience=[x['name'] for x in self.exp_dict_list if x['bool_val'].get()], job_type=[x['name'] for x in self.job_type_dict_list if x['bool_val'].get()], location_name = loc_fallback, geo_urn_ids=[x.value for x in self.loc_frame.get_current_selection()], industries=[x.value for x in self.industry_frame.get_current_selection()], ) if self.quick_search: self.search_results_df = pd.DataFrame(search_result) try: self.search_results_df.drop(['dashEntityUrn', '$recipeTypes', '$type'], axis=1, inplace=True) self.search_results_df['companyDetails'] = self.search_results_df['companyDetails'].apply( lambda x: x.get('company', '').rsplit(':', 1)[-1] ) self.search_results_df.rename(columns={'companyDetails': 'companyUrn'}, inplace=True) self.search_results_df['entityUrn'] = self.search_results_df['entityUrn'].str.rsplit(':', 1, expand=True)[1] self.search_results_df['listedAt'] = self.search_results_df['listedAt'].apply( lambda x : datetime.fromtimestamp(x/1000).date() ) except Exception as e: print(repr(e)) self.table.updateModel(TableModel(self.search_results_df)) self.table.redraw() else: result_size = len(search_result) self.status_str.set("Found " + str(result_size) + " results! Searching jobs details... This can take a while...") self.parent.update() if result_size > 999: answer_is_yes = messagebox.askyesno("Too many results!", "This search yields more than 1000 results (upper limit for this app).\nProceed anyway?", icon="warning") if not answer_is_yes: self.status_str.set("Search cancelled.") self.parent.update() return row = 1 for job in search_result: job_obj = self.linkedin_conn[0].get_job(job['dashEntityUrn'].rsplit(':',1)[1]) if job_obj != {}: job_dict = { 'Title': job_obj['title'], 'Company': job_obj['companyDetails'] .get('com.linkedin.voyager.deco.jobs.web.shared.WebCompactJobPostingCompany', {}, ).get('companyResolutionResult', {} ).get('name', ''), 'Location': job_obj['formattedLocation'], 'Description': job_obj.get('description', {}).get('text', ''), #'Remote': job_obj['workRemoteAllowed'], 'Work Place': job_obj.get('workplaceTypesResolutionResults', {}) .get('urn:li:fs_workplaceType:1', {}) .get('localizedName', ''), 'Posted On': datetime.fromtimestamp(job_obj['listedAt']/1000).date(), 'LinkedIn Link': f"https://www.linkedin.com/jobs/view/{job_obj['jobPostingId']}", 'Direct Link': job_obj.get('applyMethod',{}) .get('com.linkedin.voyager.jobs.OffsiteApply', {} ).get('companyApplyUrl', '').split('?', 1)[0] } # if self.get_contact_info.get(): # contact_info = self.linkedin_conn[0].get_profile_contact_info(urn_id=job['urn_id']) # contact_info = {k: [v] for k,v in contact_info.items()} # job_dict.update(contact_info) self.search_results_df = pd.concat([self.search_results_df, pd.DataFrame([job_dict.values()], columns=job_dict.keys())]) self.table.updateModel(TableModel(self.search_results_df)) self.table.redraw() self.status_str.set("Scanned " + str(row) + " out of " + str(result_size) + " profiles") self.parent.update() row += 1 self.export_to_file_btn.configure(state="normal") self.status_str.set("Done") self.parent.update() except Exception as e: utils.show_exception(e) self.status_str.set("Something went wrong! Check console output for more details.") self.parent.update()