def _format_histogram(cls, title, histogram): #maximum column name width and value max_value = max(c[1] for c in histogram) widths = [Text.text_width-cls._hist_width-1, cls._hist_width+1] histogram_string = '-'*Text.text_width + '\n' #wrap column and hist titles histogram_string += line_by_line([title, cls._hist_column_title], widths, j_center=True) histogram_string += '-'*Text.text_width + '\n' #histogram lines for col in histogram: #line value hist_value = int(round((cls._hist_width*col[1])/max_value)) col_spacer = cls._hist_width - hist_value #value figure value_str = tdf.format_concentration(col[1]) hist_bar = '' if len(value_str) < col_spacer: _spacer = col_spacer-len(value_str) hist_bar += '#'*hist_value + ' '*_spacer + value_str else: _bar = hist_value-len(value_str) hist_bar += '#'*(_bar/2) + value_str hist_bar += '#'*(_bar-_bar/2) + ' '*col_spacer histogram_string += line_by_line([col[0],hist_bar], widths, divider=':') histogram_string += '-'*Text.text_width + '\n' histogram_string += '\n' return histogram_string
def _format_histogram(cls, title, histogram): #maximum column name width and value max_value = max(c[1] for c in histogram) widths = [Text.text_width - cls._hist_width - 1, cls._hist_width + 1] histogram_string = '-' * Text.text_width + '\n' #wrap column and hist titles histogram_string += line_by_line([title, cls._hist_column_title], widths, j_center=True) histogram_string += '-' * Text.text_width + '\n' #histogram lines for col in histogram: #line value hist_value = int(round((cls._hist_width * col[1]) / max_value)) col_spacer = cls._hist_width - hist_value #value figure value_str = tdf.format_concentration(col[1]) hist_bar = '' if len(value_str) < col_spacer: _spacer = col_spacer - len(value_str) hist_bar += '#' * hist_value + ' ' * _spacer + value_str else: _bar = hist_value - len(value_str) hist_bar += '#' * (_bar / 2) + value_str hist_bar += '#' * (_bar - _bar / 2) + ' ' * col_spacer histogram_string += line_by_line([col[0], hist_bar], widths, divider=':') histogram_string += '-' * Text.text_width + '\n' histogram_string += '\n' return histogram_string
''' Created on 2016-01-14 @author: Allis Tauri <*****@*****.**> ''' import cProfile from BioUtils.Tools.Text import wrap_text, line_by_line if __name__ == '__main__': txt = '''If true, TextWrapper attempts to detect sentence endings and ensure that sentences are always separated by exactly two spaces. This is generally desired for text in a monospaced font. However, the sentence detection algorithm is imperfect: it assumes that a sentence ending consists of a lowercase letter followed by one of '.', '!', or '?', possibly followed by one of '"' or "'", followed by a space. One problem with this is algorithm is that it is unable to detect the difference between “Dr.” in''' print wrap_text(txt) print '='*80 texts = ['asdfasd sreydstnsr mywyy eratg AG RADFG SDFGA lkjoiuguivuasdfhpwoiefjahgaiohghouygmuimjiuh', 'qasf; a[r uq[ewjrfasdhfuiah [WERJ AOSF BA;We werqt', 'wreyqeuqy a poiertqprohg aspoei toeaprt a'] widths = [20,30,30] print line_by_line(texts, widths) cProfile.run('''for i in xrange(10000): wrap_text(txt)''', 'word_wrap.profile') print 'Done'
''' Created on 2016-01-14 @author: Allis Tauri <*****@*****.**> ''' import cProfile from BioUtils.Tools.Text import wrap_text, line_by_line if __name__ == '__main__': txt = '''If true, TextWrapper attempts to detect sentence endings and ensure that sentences are always separated by exactly two spaces. This is generally desired for text in a monospaced font. However, the sentence detection algorithm is imperfect: it assumes that a sentence ending consists of a lowercase letter followed by one of '.', '!', or '?', possibly followed by one of '"' or "'", followed by a space. One problem with this is algorithm is that it is unable to detect the difference between “Dr.” in''' print wrap_text(txt) print '=' * 80 texts = [ 'asdfasd sreydstnsr mywyy eratg AG RADFG SDFGA lkjoiuguivuasdfhpwoiefjahgaiohghouygmuimjiuh', 'qasf; a[r uq[ewjrfasdhfuiah [WERJ AOSF BA;We werqt', 'wreyqeuqy a poiertqprohg aspoei toeaprt a' ] widths = [20, 30, 30] print line_by_line(texts, widths) cProfile.run('''for i in xrange(10000): wrap_text(txt)''', 'word_wrap.profile') print 'Done'