def get_elementwise_min_max(items): """Returns element-wise min and max over all lists of values in *items*. The length of the output is equal to the longest list in the input. """ contains_lists = all(isinstance(item, list) for item in items) if not contains_lists: return (tools.get_min_max(items)) num_elements = max([len(item) for item in items]) res = [] for index in range(num_elements): values = [item[index] if index < len(item) else None for item in items] res.append((tools.get_min_max(values))) return res
def _format_row(self, row_name, row): """Format all entries in **row** (in place).""" if row_name == self.header_row: for col_name, value in row.items(): row[col_name] = value.replace('_', '_' + ESCAPE_WORDBREAK) return # Get the slice of the row that should be formated (i.e. the data columns). # Note that there might be other columns (e.g. added by dynamic data # modules) that should not be formated. row_slice = dict((col_name, row.get(col_name)) for col_name in self.col_names) min_value, max_value = tools.get_min_max(row_slice.values()) min_wins = self.get_min_wins(row_name) highlight = min_wins is not None colors = tools.get_colors(row_slice, min_wins) if self.colored else None for col_name, value in row.items(): color = None bold = False # Format data columns if col_name in row_slice: rounded_value = round(value, 2) if isinstance(value, float) else value if self.colored: color = tools.rgb_fractions_to_html_color(*colors[col_name]) elif highlight and (rounded_value == min_value and min_wins or rounded_value == max_value and not min_wins): bold = True row[col_name] = self._format_cell(row_name, col_name, value, color=color, bold=bold)
def _format_row(self, row_name, row): """Format all entries in **row** (in place).""" if row_name == self.header_row: for col_name, value in row.items(): # Allow breaking after underlines. value = value.replace("_", "_" + ESCAPE_WORDBREAK) # Right-align headers (except the left-most one). if col_name != self.header_column: value = " " + value row[col_name] = value return # Get the slice of the row that should be formated (i.e. the data columns). # Note that there might be other columns (e.g. added by dynamic data # modules) that should not be formated. row_slice = { col_name: row.get(col_name) for col_name in self.col_names } min_wins = self.get_min_wins(row_name) highlight = min_wins is not None colored = self.colored and highlight colors = tools.get_colors(row_slice, min_wins) if colored else None if highlight: min_value, max_value = tools.get_min_max(row_slice.values()) else: min_value, max_value = None, None def is_close(a, b): # Highlight based on precision visible in table, not actual values. return self._format_value(a) == self._format_value(b) for col_name, value in row.items(): color = None bold = False # Format data columns if col_name in row_slice: if colored: color = tools.rgb_fractions_to_html_color( *colors[col_name]) elif (highlight and value is not None and ((is_close(value, min_value) and min_wins) or (is_close(value, max_value) and not min_wins))): bold = True row[col_name] = self._format_cell(row_name, col_name, value, color=color, bold=bold)
def _format_row(self, row_name, row): """Format all entries in **row** (in place).""" if row_name == self.header_row: for col_name, value in row.items(): # Allow breaking after underlines. value = value.replace('_', '_' + ESCAPE_WORDBREAK) # Right-align headers (except the left-most one). if col_name != self.header_column: value = ' ' + value row[col_name] = value return # Get the slice of the row that should be formated (i.e. the data columns). # Note that there might be other columns (e.g. added by dynamic data # modules) that should not be formated. row_slice = dict( (col_name, row.get(col_name)) for col_name in self.col_names) min_wins = self.get_min_wins(row_name) highlight = min_wins is not None colored = self.colored and highlight colors = tools.get_colors(row_slice, min_wins) if colored else None if highlight: min_value, max_value = tools.get_min_max(row_slice.values()) else: min_value, max_value = None, None def is_close(a, b, rel_tol=1e-09, abs_tol=0.0): return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) for col_name, value in row.items(): color = None bold = False # Format data columns if col_name in row_slice: if colored: color = tools.rgb_fractions_to_html_color( *colors[col_name]) elif highlight and value is not None and ( (is_close(value, min_value) and min_wins) or (is_close(value, max_value) and not min_wins)): bold = True row[col_name] = self._format_cell(row_name, col_name, value, color=color, bold=bold)
def _format_row(self, row_name, row): """Format all entries in **row** (in place).""" if row_name == self.header_row: for col_name, value in row.items(): row[col_name] = value.replace('_', '_' + ESCAPE_WORDBREAK) return # Get the slice of the row that should be formated (i.e. the data columns). # Note that there might be other columns (e.g. added by dynamic data # modules) that should not be formated. row_slice = dict( (col_name, row.get(col_name)) for col_name in self.col_names) min_value, max_value = tools.get_min_max(row_slice.values()) min_wins = self.get_min_wins(row_name) highlight = min_wins is not None colors = tools.get_colors(row_slice, min_wins) if self.colored else None for col_name, value in row.items(): color = None bold = False # Format data columns if col_name in row_slice: rounded_value = round(value, 2) if isinstance(value, float) else value if self.colored: color = tools.rgb_fractions_to_html_color( *colors[col_name]) elif highlight and (rounded_value == min_value and min_wins or rounded_value == max_value and not min_wins): bold = True row[col_name] = self._format_cell(row_name, col_name, value, color=color, bold=bold)