def show_time_summary(recall_times): title = 'Average Recall Time' title = Color.colorize('yellow', title) avg = '{:.2f}s'.format(sum(recall_times) / len(recall_times)) len_old = len(avg) avg = Color.colorize('green', avg) content = "{} per word".format(avg).center(BANNER_BODY_WIDTH + 6) tb = DoubleTable([[content]], title=title) print(tb.table)
def show_meaning(color): text = wrapped(meaning, BANNER_BODY_WIDTH - 8) if MEANING_WIT_SYNONYM: text += '\n' text += '-'.join( ['' for _ in range(int(3 * BANNER_BODY_WIDTH / 5))]) text += '\n{}'.format(wrapped(synonmy, BANNER_BODY_WIDTH - 8)) #text += '\n'.join(wrap(synonmy, BANNER_BODY_WIDTH - 8)) cl = Color() text = '\n'.join([ cl.colorize( color, t.encode('gb18030').center(BANNER_BODY_WIDTH - 4).decode('gb18030')) for t in text.split('\n') ]) title = ' Meaning [{} ({})]'.format( report, accuracy) if len(report) != 0 else None tb = AsciiTable([[text]], title) tx = tb.table print(tx) return len(tx.split('\n'))
def colorize(color, text, auto=True): """ A simple override of Color.colorize which sets the default auto colors value to True, since it's the more common use case. :param color: Color tag to use :param text: Text to color :param auto: Whether to apply auto colors :return: Colored text """ return Color.colorize(color, text, auto)
def recall_summary(recall_bitmap): def get_color(rate): if rate <= 0.5: return 'red' if rate > 0.5 and rate < 0.8: return 'yellow' if rate >= 0.8: return 'green' recall_num = len(np.where(recall_bitmap == 1)[0]) all_num = len(recall_bitmap) recall_rate = float(recall_num) / all_num cl = get_color(recall_rate) title = Color.colorize(cl, 'Report') color_str_a_b = Color.colorize(cl, '{}/{}'.format(recall_num, all_num)) color_str_rate = Color.colorize(cl, '{:.1f}%'.format(100 * recall_rate)) data = (['Recall Num : {}'.format(color_str_a_b).center(BANNER_BODY_WIDTH + 6)], ['Recall Rate: {}'.format(color_str_rate).center(BANNER_BODY_WIDTH + 6)]) tb = DoubleTable(data, title) print(tb.table) print()
def colorize(color, text, auto=True): """ A simple override of Color.colorize which sets the default auto colors value to True, since it's the more common use case. When output isn't TTY just return text :param color: Color tag to use :param text: Text to color :param auto: Whether to apply auto colors :return: Colored text or text """ if not terminal_info()['isatty']: return text return Color.colorize(color, text, auto)
def prompt_round_info(n_round, n_word): title = 'Round {}'.format(n_round) text = 'Review {} words'.format(n_word) tx = get_inbanner_text(text, title, repeater='=', body_width=BANNER_BODY_WIDTH, fix_width=True, canopy_switcher=(1, 1)) tx = Color.colorize('yellow', tx) print('\n' + tx)