def drawTableVogel(goods, city, x, cost, demand, supply, penaltyDemand, penaltySupply): usedDemand = ['Demand'] for data in demand: usedDemand.append(str(data)) usedDemand.append(str(np.sum(demand))) usedDemand.append('') usedPenaltyDemand = ['Penalty'] for data in penaltyDemand: usedPenaltyDemand.append(str(data)) usedPenaltyDemand.append('') usedPenaltyDemand.append('') table = BeautifulTable() table.column_headers = city for i, used in enumerate(x): row = [] for j, cell in enumerate(used): strCell = str(cell) + ' ' + str(cost[i][j]) row.append(strCell) table.append_row(row) table.insert_column(0, '', goods) table.append_column('Supply', supply) table.append_column('Penalty', penaltySupply) table.append_row(usedDemand) table.append_row(usedPenaltyDemand) print(table)
def menu_travel(): '''Prints list with destinations and respective time of flight Arguments: None Returns: int: new city and travel time''' #print welcome to Employee Travel Service global current_location destinations_times = game_data.keys() list_with_destinations = [place[0] for place in destinations_times] #extracts the cities from the (city, time) tuple and creates a list travel_table = BeautifulTable() #creates a new table travel_table.column_headers = ['Destination', 'Flight Duration'] for destination, ttime in game_data.keys(): travel_table.append_row([destination, ttime]) travel_table.append_column('Flight #', ['1711', '1931']) print travel_table users_location = (raw_input('What is your next destination? (Type city name)\n')).title() #gets user input on next destination if users_location not in list_with_destinations: print 'Invalid Choice' else: current_location = users_location#if the location is on the list, prints the destination and updates the variable current_location print 'Your reservations have been confirmed to {} on Flight # . Enjoy the in-flight meal.'.format(current_location) print current_location #city
def print_releases(releases, all, channel=None): """Prints release info in table format""" if len(releases) > 0: table = BeautifulTable() table.set_style(BeautifulTable.STYLE_GRID) if all: if channel[0] == "Pypi": table.append_column('Version', releases) elif channel[0] == "Github": table.append_column('Version', [ x['tag_name'] if 'tag_name' in x.keys() else x['name'] for x in releases ]) else: table.append_column('Version', [x['version'] for x in releases]) table.append_column('Build', [x['build'] for x in releases]) else: table.column_headers = list(releases.keys()) table.append_row(list(releases.values())) print(table) else: # releases is empty, no data for the package print("No releases.\n")
def show_results(self, rfr_trn, rfr_tst, jac_trn, jac_tst, nn_trn, nn_tst, vot_trn, vot_tst): table = BeautifulTable() table.append_column('', ['Trn', 'Tst', 'Trn Pearson', 'Tst Pearson']) self.__add_table(table, 'Real', self.trn_gs['labels'], self.tst_gs['labels']) self.__add_table(table, 'RFR', rfr_trn, rfr_tst) self.__add_table(table, 'Jaccard', jac_trn, jac_tst) self.__add_table(table, 'NN', nn_trn, nn_tst) self.__add_table(table, 'Voting', vot_trn, vot_tst) plt.scatter(nn_trn, self.trn_gs['labels'], c='Cyan') plt.xlabel('NN label') plt.ylabel('Real label') plt.show() plt.scatter(vot_trn, self.trn_gs['labels'], c='Blue') plt.xlabel('Averaging label') plt.ylabel('Real label') plt.show() plt.scatter(jac_trn, self.trn_gs['labels'], c='Green') plt.xlabel('Jaccard label') plt.ylabel('Real label') plt.show() plt.scatter(rfr_trn, self.trn_gs['labels'], c='Red') plt.xlabel('RFR label') plt.ylabel('Real label') plt.show() plt.scatter(nn_tst, self.tst_gs['labels'], c='Cyan') plt.xlabel('NN label') plt.ylabel('Real label') plt.show() plt.scatter(vot_tst, self.tst_gs['labels'], c='Blue') plt.xlabel('Averaging label') plt.ylabel('Real label') plt.show() plt.scatter(jac_tst, self.tst_gs['labels'], c='Green') plt.xlabel('Jaccard label') plt.ylabel('Real label') plt.show() plt.scatter(rfr_tst, self.tst_gs['labels'], c='Red') plt.xlabel('RFR label') plt.ylabel('Real label') plt.show() print(table) self.show_worst_test(vot_tst, rfr_tst, nn_tst, jac_tst) print() self.show_best_test(vot_tst, rfr_tst, nn_tst, jac_tst) print()
def write_performance_metrics(cms, names, aurocs, man_aurocs, auprcs, man_auprcs, indet_array, threshold_array, excluded_algs, noshow): from beautifultable import BeautifulTable table = BeautifulTable(max_width=300) table.append_column(' ', ['sensitivity', 'specificity', 'PPV', 'NPV', 'accuracy', 'Manual AUROC', 'Manual AUPRC', '% indet', 'Dec. Thresh. (%)']) count = 0 for cm in cms: if (names[count] in excluded_algs): print('Did not include ' + str(names[count]) + 'results!') count += 1 continue if (names[count] in noshow): #print('Did not show ' + str(names[count]) + 'results!') count += 1 continue # if (names[count] == 'APRI' or names[count] == 'FIB4'): # count += 1 # continue #if (names[count] != 'ENS1' and names[count] != 'ENS2' and names[count] != 'ENS3'): # count += 1 # continue tot = cm[0,0] + cm[0,1] + cm[1,0] + cm[1,1] tp = cm[1,1] fp = cm[0,1] tn = cm[0,0] fn = cm[1,0] accuracy = 100*(tp + tn)/(tot) precision = 100*tp/(tp + fp) negPredVal = 100*tn/(tn + fn) sensitivity = 100*tp/(tp + fn) falseNegRate = 100*fn/(fn + tp) specificity = 100*tn/(tn + fp) falsePosRate = 100*fp/(fp + tn) f1 = 100*2*precision*sensitivity/(precision + sensitivity) auc = aurocs[count] man_aucs = man_aurocs[count] prc = auprcs[count] man_prcs = man_auprcs[count] indt = indet_array[count] thresh = threshold_array[count] table.append_column(names[count], [(' %0.1f' % sensitivity), (' %0.1f' % specificity), (' %0.1f' % precision), (' %0.1f' % negPredVal), (' %0.1f' % accuracy), (' %0.1f' % (100*man_aucs)), (' %0.1f' % (100*man_prcs)), (' %0.1f' % (100*indt)), thresh]) count += 1 print(table)
def test_gui(self): self.state.current_player.hand = [self.abusive_sergeant, self.agent_squire, self.selfless_hero, self.divine_strength] self.state.current_player.board = [deepcopy(self.abusive_sergeant), deepcopy(self.selfless_hero), deepcopy(self.steward_of_darshire)] from beautifultable import BeautifulTable table = BeautifulTable() for card in self.state.current_player.hand: table.append_column(card.name, ['Cost = {}'.format(card.cost), get_static_abi(card), get_desc(card)]) print(table) print('\n') table = BeautifulTable() for card in self.state.current_player.board: table.append_column(card.name, [get_static_abi(card), get_desc(card)]) print(table)
def _make_data_table(raw_data, display_fields): """Returns a table-formatted equivalent of the given data. :param raw_data: list of dicts containing data from Uber's API :param display_fields: list of column names to filter the data with :return: data in table form :rtype: :class:`BeautifulTable <BeautifulTable>` """ table = BeautifulTable() data = { k: v for k, v in _transpose_to_columnar(raw_data).items() if k in display_fields } for header_name in display_fields: table.append_column(header_name, data[header_name]) return table
def print_available_languages(): available_languages = googletrans.LANGUAGES language_keys_list = list(available_languages.keys()) language_values_list = list(available_languages.values()) # pad the lists for easier table manipulation by using modulus for decision when to put new column # 120 is divisible by 15 w/o remainder, 106 values in key_list/value list language_keys_list += [''] * (121 - len(language_keys_list)) language_values_list += [''] * (121 - len(language_values_list)) language_table = BeautifulTable(max_width=1000) language_table.set_style(BeautifulTable.STYLE_COMPACT) for idx in range(1, len(language_keys_list)): if idx % 15 == 0: sliced_keys_list = language_keys_list[idx - 15:idx] sliced_values_list = language_values_list[idx - 15:idx] language_table.append_column("Code", sliced_keys_list) language_table.append_column("Language", sliced_values_list) print(language_table)
def predict_json(self, inputs: JsonDict) -> JsonDict: instance = self._json_to_instance(inputs) self.model.vocab.extend_from_instances(None, instances=[instance]) #self.model.extend_embedder_vocab(embedding_sources_mapping) output = self.predict_instance(instance) print('predict json', output) table = BeautifulTable(max_width=120) table.set_style(BeautifulTable.STYLE_RST) table.append_column('words', output['words']) table.append_column('tags', output['tags']) table.append_column('logits', [ " ".join([str(round(f, 1)) for f in l]) for l in output['logits'] ]) print('predict json', output) output = list(zip(output['tags'], output['words'])) return str(table).replace('\n', '<br />') return list(zip(result['tags'], result['words']))
#CREATE TABLE by providing a name for the table and use BeautifulTable() table = BeautifulTable() #CREATE HEADERS: table.column_headers = ['name1', 'name2', 'name3'] #CREATE ROWS: table.append_row(['x', 'x', 'x']) NOTE: both ([]) #!!!!! HEADER DOES NOT COUNT AS A ROW !!!!! table.column_headers = ['name1', 'name2', 'name3'] table.append_row(['1', '2', '3']) table.append_row(['4', '5', '6']) table.append_row(['7', '8', '9']) print(table) #CREATE new COLUMN: table.append_column('NAME'), ['DATA', 'D', 'D', 'D']) #Watch out for the use of both () and [] table.append_column('player', ['X', 'O', 'X']) print(table) #You can also build a NEW TABLE using SLICING: the new table retains #the properties of the original, it is a copy of the data. new_table = table[:3] print(new_table) #!!!!! HEADER DOES NOT COUNT AS A ROW !!!!! #You can ACCESS a ROW using its index: print(list(table[1])) #You can ACCESS a FIELD of a row via A) the index or B) the header #A) print(table[2][3]) #B) print(table[1]['player'])
def show_results(self): # This is the final step of estimation. new_landing_rates, new_landing_volumes, model, which_months = self.check_regions() models = { "1": "CPM", "2": "CPI", "3": "CPA" } months = { 1: "Январь", 2: "Февраль", 3: "Март", 4: "Апрель", 5: "Май", 6: "Июнь", 7: "Июль", 8: "Август", 9: "Сентябрь", 10: "Октябрь", 11: "Ноябрь", 12: "Декабрь" } now = datetime.datetime.now() print("\n🏆 Моя рекомендация будет следующей: 🏆") print("\n--- Лендинг 📄 ---") table_landing = BeautifulTable() table_landing.append_column( "Источник", [key for key, value in new_landing_rates.items()]) table_landing.append_column( f"Ставка {models[model]}", [(str(rate)).replace(".", ",") for key, rate in new_landing_rates.items()]) volumes_all_together = [] for month in which_months: number_of_days_in_month = int(calendar.monthrange(now.year, month)[1]) if month == 2 or month == 11: volumes = [int(((volume / 1000) / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) if model == "1" else int((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) for key, volume in new_landing_volumes.items()] volumes_all_together.append(volumes) table_landing.append_column(months[month], volumes) elif month == 12: volumes = [int(((volume / 1000) / INCREASE_DECEMBER) * number_of_days_in_month) if model == "1" else int((volume / INCREASE_DECEMBER) * number_of_days_in_month) for key, volume in new_landing_volumes.items()] volumes_all_together.append(volumes) table_landing.append_column(months[month], volumes) else: volumes = [int((volume / 1000) * number_of_days_in_month) if model == "1" else int(volume * number_of_days_in_month) for key, volume in new_landing_volumes.items()] volumes_all_together.append(volumes) table_landing.append_column(months[month], volumes) budgets = {} n = 0 for volume in numpy.sum(volumes_all_together, axis=0): if n <= len(new_landing_rates) - 1: key = list(new_landing_rates.keys())[n] rate = list(new_landing_rates.values())[n] budgets[key] = volume * rate n += 1 table_landing.append_column("Всего без НДС", [int(spend) for key, spend in budgets.items()]) print(table_landing) print("\n") for key, spend in budgets.items(): if spend < BUDGET_BOTTOM[key]: difference = BUDGET_BOTTOM[key] - spend print(f"🚨 Обрати внимание, что мы не добираем {int(difference)} до минимального бюджета по {key} для iOS!") else: pass
def show_results(self): # This is the final step of estimation. new_android_rates, new_ios_rates, model, android_platform, ios_platform, new_android_volumes, new_ios_volumes, which_months, budget = self.choose_tracker() models = { "1": "CPM", "2": "CPI", "3": "CPA" } months = { 1: "Январь", 2: "Февраль", 3: "Март", 4: "Апрель", 5: "Май", 6: "Июнь", 7: "Июль", 8: "Август", 9: "Сентябрь", 10: "Октябрь", 11: "Ноябрь", 12: "Декабрь" } now = datetime.datetime.now() if android_platform == True: # Count total volumes for Android. volumes_all_together = [] for month in which_months: number_of_days_in_month = int( calendar.monthrange(now.year, month)[1]) if month == 2 or month == 11: volumes = [int((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) for key, volume in new_android_volumes.items()] volumes_all_together.append(volumes) elif month == 12: volumes = [int((volume / INCREASE_DECEMBER) * number_of_days_in_month) for key, volume in new_android_volumes.items()] volumes_all_together.append(volumes) else: volumes = [int(volume * number_of_days_in_month) for key, volume in new_android_volumes.items()] volumes_all_together.append(volumes) budgets = {} n = 0 for volume in numpy.sum(volumes_all_together, axis=0): if n <= len(new_android_rates) - 1: key = list(new_android_rates.keys())[n] rate = list(new_android_rates.values())[n] if model == "1": budgets[key] = (volume * rate) / 1000 else: budgets[key] = volume * rate n += 1 android_budget = sum(budgets.values()) else: pass if ios_platform == True: # Count total volumes for iOS. volumes_all_together = [] for month in which_months: number_of_days_in_month = int( calendar.monthrange(now.year, month)[1]) if month == 2 or month == 11: volumes = [int((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) for key, volume in new_ios_volumes.items()] volumes_all_together.append(volumes) elif month == 12: volumes = [int((volume / INCREASE_DECEMBER) * number_of_days_in_month) for key, volume in new_ios_volumes.items()] volumes_all_together.append(volumes) else: volumes = [int(volume * number_of_days_in_month) for key, volume in new_ios_volumes.items()] volumes_all_together.append(volumes) budgets = {} n = 0 for volume in numpy.sum(volumes_all_together, axis=0): if n <= len(new_ios_rates) - 1: key = list(new_ios_rates.keys())[n] rate = list(new_ios_rates.values())[n] if model == "1": budgets[key] = (volume * rate) / 1000 else: budgets[key] = volume * rate n += 1 ios_budget = sum(budgets.values()) else: pass # Count total budget and check if there is a need to decrease volumes in order to fit the limited budget. if android_platform == True & ios_platform == True: total_budget = android_budget + ios_budget elif android_platform == True: total_budget = android_budget elif ios_platform == True: total_budget = ios_budget # If budget limit exceeded then decrease volumes accordingly. print("\n🏆 Моя рекомендация будет следующей: 🏆") difference = budget / total_budget if android_platform == True: print("\n--- Android 🤖 ---") table_android = BeautifulTable() table_android.append_column( "Источник", [key for key, value in new_android_rates.items()]) table_android.append_column( f"Ставка {models[model]}", [(str(rate)).replace(".", ",") for key, rate in new_android_rates.items()]) # Count total volumes for Android. volumes_all_together = [] for month in which_months: number_of_days_in_month = int( calendar.monthrange(now.year, month)[1]) if month == 2 or month == 11: if difference < 1: volumes = [int(((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) * difference) for key, volume in new_android_volumes.items()] else: volumes = [int(((volume / 1000) / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) if model == "1" else int((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) for key, volume in new_android_volumes.items()] volumes_all_together.append(volumes) table_android.append_column(months[month], volumes) elif month == 12: if difference < 1: volumes = [int(((volume / INCREASE_DECEMBER) * number_of_days_in_month) * difference) for key, volume in new_android_volumes.items()] else: volumes = [int(((volume / 1000) / INCREASE_DECEMBER) * number_of_days_in_month) if model == "1" else int((volume / INCREASE_DECEMBER) * number_of_days_in_month) for key, volume in new_android_volumes.items()] volumes_all_together.append(volumes) table_android.append_column(months[month], volumes) else: if difference < 1: volumes = [int((volume * number_of_days_in_month) * difference) for key, volume in new_android_volumes.items()] else: volumes = [int((volume / 1000) * number_of_days_in_month) if model == "1" else int(volume * number_of_days_in_month) for key, volume in new_android_volumes.items()] volumes_all_together.append(volumes) table_android.append_column(months[month], volumes) budgets = {} n = 0 for volume in numpy.sum(volumes_all_together, axis=0): if n <= len(new_android_rates) - 1: key = list(new_android_rates.keys())[n] rate = list(new_android_rates.values())[n] if model == "1": budgets[key] = (volume * rate) / 1000 else: budgets[key] = volume * rate n += 1 table_android.append_column( "Всего без НДС", [int(spend) for key, spend in budgets.items()]) print(table_android) print("\n") for key, spend in budgets.items(): if spend < BUDGET_BOTTOM[key]: shortage = BUDGET_BOTTOM[key] - spend print( f"🚨 Обрати внимание, что мы не добираем {int(shortage)} до минимального бюджета по {key} для Android!") else: pass else: pass if ios_platform == True: print("\n--- iOS 🍏 ---") table_ios = BeautifulTable() table_ios.append_column( "Источник", [key for key, value in new_ios_rates.items()]) table_ios.append_column( f"Ставка {models[model]}", [(str(rate)).replace(".", ",") for key, rate in new_ios_rates.items()]) # Count total volumes for iOS. volumes_all_together = [] for month in which_months: number_of_days_in_month = int( calendar.monthrange(now.year, month)[1]) if month == 2 or month == 11: if difference < 1: volumes = [int(((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) * difference) for key, volume in new_ios_volumes.items()] else: volumes = [int(((volume / 1000) / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) if model == "1" else int((volume / INCREASE_FEBRUARY_NOVEMBER) * number_of_days_in_month) for key, volume in new_ios_volumes.items()] volumes_all_together.append(volumes) table_ios.append_column(months[month], volumes) elif month == 12: if difference < 1: volumes = [int(((volume / INCREASE_DECEMBER) * number_of_days_in_month) * difference) for key, volume in new_ios_volumes.items()] else: volumes = [int(((volume / 1000) / INCREASE_DECEMBER) * number_of_days_in_month) if model == "1" else int((volume / INCREASE_DECEMBER) * number_of_days_in_month) for key, volume in new_ios_volumes.items()] volumes_all_together.append(volumes) table_ios.append_column(months[month], volumes) else: if difference < 1: volumes = [int((volume * number_of_days_in_month) * difference) for key, volume in new_ios_volumes.items()] else: volumes = [int((volume / 1000) * number_of_days_in_month) if model == "1" else int(volume * number_of_days_in_month) for key, volume in new_ios_volumes.items()] volumes_all_together.append(volumes) table_ios.append_column(months[month], volumes) budgets = {} n = 0 for volume in numpy.sum(volumes_all_together, axis=0): if n <= len(new_ios_rates) - 1: key = list(new_ios_rates.keys())[n] rate = list(new_ios_rates.values())[n] if model == "1": budgets[key] = (volume * rate) / 1000 else: budgets[key] = volume * rate n += 1 table_ios.append_column("Всего без НДС", [int(spend) for key, spend in budgets.items()]) print(table_ios) print("\n") for key, spend in budgets.items(): if spend < BUDGET_BOTTOM[key]: shortage = BUDGET_BOTTOM[key] - spend print( f"🚨 Обрати внимание, что мы не добираем {int(shortage)} до минимального бюджета по {key} для iOS!") else: pass else: pass
def create_table(sr_list, subject_name, c_h_List, t_m_List, obtained_marks_list, per_list, grade_list, GPA, T_M, O_M, pe, G, S): from beautifultable import BeautifulTable t = BeautifulTable() t1 = BeautifulTable() t.append_column('Sr#', sr_list) t.append_column('COURSES', subject_name) t.append_column('CREDIT HOURS', c_h_List) t.append_column('TOTAL MARKS', t_m_List) t.append_column('OBTAINED MARKS', obtained_marks_list) t.append_column('%', per_list) t.append_column('GRADE', grade_list) print(t) print("\n\t") c_1 = ['GPA', 'TOTAL MARKS', 'OBTAINED MARKS'] c_2 = [GPA, T_M, O_M] c_3 = ['GRADE', 'PERSENTAGE', 'STATUS'] c_4 = [G, p, S] t1.append_column('', c_1) t1.append_column('', c_2) t1.append_column('', c_3) t1.append_column('', c_4) print(t1)
def print_state(player_1, player_2): player_1_hand = BeautifulTable(max_width=140) player_1_board = BeautifulTable(max_width=140) player_2_hand = BeautifulTable(max_width=140) player_2_board = BeautifulTable(max_width=140) print("Player: {}".format(player_1.name)) print("Health: {}".format(player_1.health)) print("Mana: {}".format(player_1.mana)) print("Graveyard: {}".format(', '.join( [card.name for card in player_1.graveyard]))) for card in player_1.hand: player_1_hand.append_column(card.name, [ 'Cost = {}'.format(card.cost), get_static_abi(card), get_desc(card) ]) if player_1_hand: print("Hand:") print(player_1_hand) else: print("Hand: Empty") for card in player_1.board: player_1_board.append_column( card.name, [get_static_abi(card), get_desc(card)]) if player_1_board: print("Board") print(player_1_board) else: print("Board: Empty") print() for card in player_2.board: player_2_board.append_column( card.name, [get_static_abi(card), get_desc(card)]) if player_2_board: print("Board:") print(player_2_board) else: print("Board: Empty") for card in player_2.hand: player_2_hand.append_column(card.name, [ 'Cost = {}'.format(card.cost), get_static_abi(card), get_desc(card) ]) if player_2_hand: print("Hand:") print(player_2_hand) else: print("Hand: Empty") print("Graveyard: {}".format(', '.join( [card.name for card in player_2.graveyard]))) print("Mana: {}".format(player_2.mana)) print("Health: {}".format(player_2.health)) print("Player: {}".format(player_2.name)) print("=" * 130)