Skip to content

Commit

Permalink
Lint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Edsall committed Apr 4, 2015
1 parent 315c814 commit 73055b0
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions applications/reports/Table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
# under the License.
#
class Table(object):

"""
Class that will build a nicely formated table.
"""

@staticmethod
def column(table_data, table_title):
"""
Expand All @@ -29,12 +32,12 @@ def column(table_data, table_title):
for column in table_data:
if num_rows < len(column):
num_rows = len(column)

# reformat into rows of columns
data = []
for row in range(num_rows):
new_row = []

for column in range(num_columns):
if row < len(table_data[column]):
new_row.append(str(table_data[column][row][0]))
Expand All @@ -47,60 +50,58 @@ def column(table_data, table_title):
# now build similar to other table
num_columns = len(data[0])
num_rows = len(data)

#get column widths
column_width = []
for column in range(num_columns):
if data[0][column]:
column_width.append(len(data[0][column]))
else:
column_width.append(len('None'))

for column in range(num_columns):
for row in range(num_rows):
if column_width[column] < len(data[row][column]):
column_width[column] = len(data[row][column])

# Get total width
total_width = 0
for column in range(num_columns):
total_width += column_width[column]
total_width += (num_columns-1)*3+2

#build format strings
format_title_line = '+{0:=^'+str(total_width)+'}+\n'
format_title = '{0:^'+str(total_width)+'}\n'
format_title = '{0:^'+str(total_width)+'}\n'
format_line = '+'
format_row = '|'
for column in range(num_columns/2) :
for column in range(num_columns/2):
format_line += '{'+str(column*2)+':->'+str(column_width[column*2])+'}---'
format_line += '{'+str(column*2+1)+':-<'+str(column_width[column*2+1])+'}'
format_row += '{'+str(column*2)+':>'+str(column_width[column*2])+'} : '
format_row += '{'+str(column*2+1)+':<'+str(column_width[column*2+1])+'}'
if (column*2+1) < num_columns -1 :
if (column*2+1) < num_columns -1:
format_row += ' | '
format_line+= '-+-'
format_line += '-+-'

# build blank data for divider
divider = []
for column in range(num_columns):
divider.append('')

#build table
text_string = ''
if table_title :
#text_string += format_title_line.format('')
if table_title:
text_string += format_title.format(table_title)

text_string += format_line.format(*divider)+'+\n'
for row in range(0,num_rows):
for row in range(0, num_rows):
text_string += format_row.format(*data[row])+'|\n'

text_string += format_line.format(*divider)+'+\n'
return text_string

@staticmethod
def row_column(data, table_title = None):
def row_column(data, table_title=None):
"""
Will build a table using the data. Data is
a list of table rows.
Expand All @@ -112,9 +113,9 @@ def row_column(data, table_title = None):
#fill out incomplete rows
for row in range(num_rows):
if len(data[row]) < num_columns:
for column in range(len(data[row]),num_columns):
for column in range(len(data[row]), num_columns):
data[row].append('')

#get column widths
column_width = []
for column in range(num_columns):
Expand All @@ -128,39 +129,36 @@ def row_column(data, table_title = None):
for column in range(num_columns):
total_width += column_width[column]
total_width += (num_columns-1)*3+2

#build format strings
format_title_line = '+{0:=^'+str(total_width)+'}+\n'
format_title = '{0:^'+str(total_width)+'}\n'
format_title = '{0:^'+str(total_width)+'}\n'
format_line = '+'
format_div = '+'
format_row = '|'
for column in range(num_columns) :
for column in range(num_columns):
format_line += '{'+str(column)+':-^'+str(column_width[column])+'}'
format_row += '{'+str(column)+':^'+str(column_width[column])+'}'
format_div += '{'+str(column)+':=^'+str(column_width[column])+'}'
if column < num_columns -1 :
if column < num_columns -1:
format_div += '=+='
format_row += ' | '
format_line+= '-+-'
format_line += '-+-'

# build blank data for divider
divider = []
for column in range(num_columns):
divider.append('')

#build table
text_string = ''
if table_title :
#text_string += format_title_line.format('')
if table_title:
text_string += format_title.format(table_title)

text_string += format_line.format(*divider)+'+\n'
text_string += format_row.format(*data[0])+'|\n'
text_string += format_div.format(*divider)+'+\n'
for row in range(1,num_rows):
for row in range(1, num_rows):
text_string += format_row.format(*data[row])+'|\n'

text_string += format_line.format(*divider)+'+\n'
return text_string

0 comments on commit 73055b0

Please sign in to comment.