def report_messages_by_module_stats(sect, stats, _): """make errors / warnings by modules report""" if len(stats['by_module']) == 1: # don't print this report when we are analysing a single module raise EmptyReport() by_mod = {} for m_type in ('fatal', 'error', 'warning', 'refactor', 'convention'): total = stats[m_type] for module in stats['by_module'].iterkeys(): mod_total = stats['by_module'][module][m_type] if total == 0: percent = 0 else: percent = float((mod_total) * 100) / total by_mod.setdefault(module, {})[m_type] = percent sorted_result = [] for module, mod_info in by_mod.iteritems(): sorted_result.append( (mod_info['error'], mod_info['warning'], mod_info['refactor'], mod_info['convention'], module)) sorted_result.sort() sorted_result.reverse() lines = ['module', 'error', 'warning', 'refactor', 'convention'] for line in sorted_result: if line[0] == 0 and line[1] == 0: break lines.append(line[-1]) for val in line[:-1]: lines.append('%.2f' % val) if len(lines) == 5: raise EmptyReport() sect.append(Table(children=lines, cols=5, rheaders=1))
def report_similarities(sect, stats, old_stats): """make a layout with some stats about duplication""" lines = ['', 'now', 'previous', 'difference'] lines += table_lines_from_stats(stats, old_stats, ('nb_duplicated_lines', 'percent_duplicated_lines')) sect.append(Table(children=lines, cols=4, rheaders=1, cheaders=1))
def report_by_type_stats(sect, stats, old_stats): """make a report of * percentage of different types documented * percentage of different types with a bad name """ # percentage of different types documented and/or with a bad name nice_stats = {} for node_type in ('module', 'class', 'method', 'function'): nice_stats[node_type] = {} total = stats[node_type] if total == 0: doc_percent = 0 badname_percent = 0 else: documented = total - stats['undocumented_' + node_type] doc_percent = float((documented) * 100) / total badname_percent = (float( (stats['badname_' + node_type]) * 100) / total) nice_stats[node_type]['percent_documented'] = doc_percent nice_stats[node_type]['percent_badname'] = badname_percent lines = ('type', 'number', 'old number', 'difference', '%documented', '%badname') for node_type in ('module', 'class', 'method', 'function'): new = stats[node_type] old = old_stats.get(node_type, None) if old is not None: diff_str = diff_string(old, new) else: old, diff_str = 'NC', 'NC' lines += (node_type, str(new), str(old), diff_str, '%.2f' % nice_stats[node_type]['percent_documented'], '%.2f' % nice_stats[node_type]['percent_badname']) sect.append(Table(children=lines, cols=6, rheaders=1))
def report_total_messages_stats(sect, stats, previous_stats): """make total errors / warnings report""" lines = ['type', 'number', 'previous', 'difference'] lines += table_lines_from_stats(stats, previous_stats, ('convention', 'refactor', 'warning', 'error')) sect.append(Table(children=lines, cols=4, rheaders=1))
def report_messages_stats(sect, stats, _): """make messages type report""" if not stats['by_msg']: # don't print this report when we didn't detected any errors raise EmptyReport() in_order = sorted([(value, msg_id) for msg_id, value in stats['by_msg'].iteritems() if not msg_id.startswith('I')]) in_order.reverse() lines = ('message id', 'occurrences') for value, msg_id in in_order: lines += (msg_id, str(value)) sect.append(Table(children=lines, cols=2, rheaders=1))
def dump_report(self, output=sys.stdout): """dump report in 'output'""" table_elems = ['RQL Query', 'Times', 'Avg Time'] total_time = 0. for query, (cumul_time, times) in zip(self._queries, self._profile_results): avg_time = cumul_time / float(times) table_elems += [str(query), '%f' % times, '%f' % avg_time] total_time += cumul_time table_elems.append('Total time :') table_elems.append(str(total_time)) table_elems.append(' ') table_layout = Table(3, rheaders=True, children=table_elems) TextWriter().format(table_layout, output)
def _display(self, layout): """launch layouts display overridden from BaseReporter to add insert the messages section (in add_message, message is not displayed, just collected so it can be displayed in an html table) """ if self.msgs: # add stored messages to the layout msgs = ['type', 'module', 'object', 'line', 'message'] msgs += self.msgs sect = Section('Messages') layout.append(sect) sect.append(Table(cols=5, children=msgs, rheaders=1)) self.msgs = [] HTMLWriter().format(layout, self.out)
def report_raw_stats(sect, stats, old_stats): """calculate percentage of code / doc / comment / empty """ total_lines = stats['total_lines'] if not total_lines: raise EmptyReport() sect.description = '%s lines have been analyzed' % total_lines lines = ('type', 'number', '%', 'previous', 'difference') for node_type in ('code', 'docstring', 'comment', 'empty'): key = node_type + '_lines' total = stats[key] percent = float(total * 100) / total_lines old = old_stats.get(key, None) if old is not None: diff_str = diff_string(old, total) else: old, diff_str = 'NC', 'NC' lines += (node_type, str(total), '%.2f' % percent, str(old), diff_str) sect.append(Table(children=lines, cols=5, rheaders=1))
def report_by_type_stats(sect, stats, old_stats): """make a report of * percentage of different types documented * percentage of different types with a bad name """ # percentage of different types documented and/or with a bad name nice_stats = {} for node_type in ('module', 'class', 'method', 'function'): try: total = stats[node_type] except KeyError: raise EmptyReport() nice_stats[node_type] = {} if total != 0: try: documented = total - stats['undocumented_'+node_type] percent = (documented * 100.) / total nice_stats[node_type]['percent_documented'] = '%.2f' % percent except KeyError: nice_stats[node_type]['percent_documented'] = 'NC' try: percent = (stats['badname_'+node_type] * 100.) / total nice_stats[node_type]['percent_badname'] = '%.2f' % percent except KeyError: nice_stats[node_type]['percent_badname'] = 'NC' lines = ('type', 'number', 'old number', 'difference', '%documented', '%badname') for node_type in ('module', 'class', 'method', 'function'): new = stats[node_type] old = old_stats.get(node_type, None) if old is not None: diff_str = diff_string(old, new) else: old, diff_str = 'NC', 'NC' lines += (node_type, str(new), str(old), diff_str, nice_stats[node_type].get('percent_documented', '0'), nice_stats[node_type].get('percent_badname', '0')) sect.append(Table(children=lines, cols=6, rheaders=1))
def visit_relationschema(self, rschema, title=True): """get a layout for a relation schema""" _ = self._ if title: title = self.format_rschema(rschema) stereotypes = [] if rschema.meta: stereotypes.append('meta') if rschema.symmetric: stereotypes.append('symmetric') if rschema.inlined: stereotypes.append('inlined') title = Section(children=(title, ), klass='title') if stereotypes: title.append(self.stereotype(','.join(stereotypes))) layout = Section(children=(title, ), klass='schema') else: layout = Section(klass='schema') data = [_('from'), _('to')] schema = rschema.schema rschema_objects = rschema.objects() if rschema_objects: # might be empty properties = [ p for p in RelationDefinitionSchema.rproperty_defs( rschema_objects[0]) if p not in ('cardinality', 'composite', 'eid') ] else: properties = [] data += [_(prop) for prop in properties] cols = len(data) done = set() for subjtype, objtypes in sorted(rschema.associations()): for objtype in objtypes: if (subjtype, objtype) in done: continue done.add((subjtype, objtype)) if rschema.symmetric: done.add((objtype, subjtype)) data.append(self.format_eschema(schema[subjtype])) data.append(self.format_eschema(schema[objtype])) rdef = rschema.rdef(subjtype, objtype) for prop in properties: val = getattr(rdef, prop) if val is None: val = '' elif prop == 'constraints': val = ', '.join([c.expression for c in val]) elif isinstance(val, dict): for key, value in val.items(): if isinstance(value, (list, tuple)): val[key] = ', '.join( sorted(str(v) for v in value)) val = str(val) elif isinstance(val, (list, tuple)): val = sorted(val) val = ', '.join(str(v) for v in val) elif val and isinstance(val, str): val = _(val) else: val = str(val) data.append(Text(val)) table = Table(cols=cols, rheaders=1, children=data, klass='listing') layout.append(Section(children=(table, ), klass='relationDefinition')) layout.append(Section(children='', klass='clear')) return layout