def test_format_decimal(self): """Test Format Decimal """ os.environ['LANG'] = 'en' interval = 0.9912 my_number = 10 my_result = format_decimal(interval, my_number) # print my_result assert my_result == '10', 'Format decimal is not valid %s' % my_result my_number = 10.0121034435 my_result = format_decimal(interval, my_number) # print my_result assert my_result == '10.012', \ 'Format decimal is not valid %s' % my_result my_number = float('nan') my_result = format_decimal(interval, my_number) # print my_result assert my_result == 'nan', \ 'Format decimal is not valid %s' % my_result my_number = float('10000.09') my_result = format_decimal(interval, my_number) # print my_result assert my_result == '10,000.09', \ 'Format decimal is not valid %s' % my_result
def format_pivot_table( pivot_table, caption=None, header_text='', total_columns=False, total_rows=False, total_affected=False, total_percent_affected=False, bar_chart=False): table = m.Table(style_class='table table-condensed table-striped') table.caption = caption row = m.Row() row.add(m.Cell(header_text, header=True)) if bar_chart: row.add(m.Cell('', header=True, attributes='width="100%"')) for column_name in pivot_table.columns: row.add(m.Cell(column_name, header=True, align='right')) if total_rows: row.add(m.Cell(tr('All'), header=True, align='right')) if total_affected: row.add(m.Cell(tr('Affected'), header=True, align='right')) if total_percent_affected: row.add(m.Cell(tr('Affected (%) *'), header=True, align='right')) table.add(row) max_value = max(max(row) for row in pivot_table.data) for row_name, data_row, total_row, affected, percent_affected in zip( pivot_table.rows, pivot_table.data, pivot_table.total_rows, pivot_table.total_rows_affected, pivot_table.total_percent_rows_affected): row = m.Row() row.add(m.Cell(row_name)) if bar_chart: svg = _svg_bar_chart_hazard(data_row, max_value) row.add(m.Cell(svg, header=False)) for column_value in data_row: row.add(m.Cell(format_decimal(0.1, column_value), align='right')) if total_rows: row.add(m.Cell( format_decimal(0.1, total_row), align='right', header=True)) if total_affected: row.add(m.Cell( format_decimal(0.1, affected), align='right', header=True)) if total_percent_affected: row.add(m.Cell( format_decimal( 0.1, percent_affected), align='right', header=True)) table.add(row) if total_columns: row = m.Row() row.add(m.Cell(tr('All'), header=True)) if bar_chart: row.add(m.Cell('', header=False)) for column_value in pivot_table.total_columns: row.add(m.Cell( format_decimal(0.1, column_value), align='right', header=True)) if total_rows: row.add(m.Cell(format_decimal( 0.1, pivot_table.total), align='right', header=True)) if total_affected: row.add(m.Cell(format_decimal( 0.1, pivot_table.total_affected), align='right', header=True)) if total_percent_affected: row.add(m.Cell(format_decimal( 0.1, pivot_table.total_percent_affected), align='right', header=True)) table.add(row) return table
def format_pivot_table(pivot_table, caption=None, header_text='', total_columns=False, total_rows=False, total_affected=False, total_percent_affected=False, bar_chart=False): table = m.Table(style_class='table table-condensed table-striped') table.caption = caption row = m.Row() row.add(m.Cell(header_text, header=True)) if bar_chart: row.add(m.Cell('', header=True, attributes='width="100%"')) for column_name in pivot_table.columns: row.add(m.Cell(column_name, header=True, align='right')) if total_rows: row.add(m.Cell(tr('All'), header=True, align='right')) if total_affected: row.add(m.Cell(tr('Affected'), header=True, align='right')) if total_percent_affected: row.add(m.Cell(tr('Affected (%) *'), header=True, align='right')) table.add(row) max_value = max(max(row) for row in pivot_table.data) for row_name, data_row, total_row, affected, percent_affected in zip( pivot_table.rows, pivot_table.data, pivot_table.total_rows, pivot_table.total_rows_affected, pivot_table.total_percent_rows_affected): row = m.Row() row.add(m.Cell(row_name)) if bar_chart: svg = _svg_bar_chart_hazard(data_row, max_value) row.add(m.Cell(svg, header=False)) for column_value in data_row: row.add(m.Cell(format_decimal(0.1, column_value), align='right')) if total_rows: row.add( m.Cell(format_decimal(0.1, total_row), align='right', header=True)) if total_affected: row.add( m.Cell(format_decimal(0.1, affected), align='right', header=True)) if total_percent_affected: row.add( m.Cell(format_decimal(0.1, percent_affected), align='right', header=True)) table.add(row) if total_columns: row = m.Row() row.add(m.Cell(tr('All'), header=True)) if bar_chart: row.add(m.Cell('', header=False)) for column_value in pivot_table.total_columns: row.add( m.Cell(format_decimal(0.1, column_value), align='right', header=True)) if total_rows: row.add( m.Cell(format_decimal(0.1, pivot_table.total), align='right', header=True)) if total_affected: row.add( m.Cell(format_decimal(0.1, pivot_table.total_affected), align='right', header=True)) if total_percent_affected: row.add( m.Cell(format_decimal(0.1, pivot_table.total_percent_affected), align='right', header=True)) table.add(row) return table