def get_rows(dependencygroup, leadingpath): """Return the rows for dependencygroup. Caller may have to format the values as strings.""" rows = [] sortedfilenames = sorted(dependencygroup.depnode_to_ca.keys()) for i in range(len(sortedfilenames)): f = sortedfilenames[i] ca = dependencygroup.depnode_to_ca[f] ce = dependencygroup.depnode_to_ce[f] rows.append([utils.prettify_path(f, leadingpath), ca, ce, _calc_instability(ca, ce)]) return rows
def format_data(self, files_stats_failures): """Formats the output of measure_cyclcompl ([filename, stats], [failures]).""" rows = [] def abovethreshold(flatstat): return _above_threshold(flatstat, self.threshold) for filename, stats in files_stats_failures[0]: filename = utils.prettify_path(filename, self.leading_path) for type, name, cc in filter(abovethreshold, stats.flatStats): rows.append([filename, type, name, cc]) self.outstream().write(self.chart.second_part(rows))
def create_rows(dependencygroup, leadingpath): """Returns a list of rows for a dependencygroup.""" converter = pagerank.DependenciesToLinkMatrix(dependencygroup.dependencies) matrix = converter.create_matrix() ranking = pagerank.page_rank(matrix) ids = [idx for idx in range(len(matrix))] filenames = [utils.prettify_path(converter.id_to_node_map[nid], leadingpath) for nid in ids] rowinfos = zip(filenames, ranking, ids, matrix) rowinfos.sort(key=lambda item: item[1]) # sort by ranking rowinfos.reverse() return rowinfos
def format_data(self, dependencygroup): header = 'Filename', 'Ca', 'Ce', 'I' c = tableprint.JUST_C justs = tableprint.JUST_L, c, c, c rows = [] sortedfilenames = sorted(dependencygroup.depnode_to_ca.keys()) for i in range(len(sortedfilenames)): f = sortedfilenames[i] ca = dependencygroup.depnode_to_ca[f] ce = dependencygroup.depnode_to_ce[f] rows.append([utils.prettify_path(f), str(ca), str(ce), self._calc_instability(ca, ce)]) tbl = tableprint.Table(header, rows, just=justs) tbl.write(self._outstream)
def create_rows(dependencygroup, leadingpath): """Returns a list of rows for a dependencygroup.""" converter = pagerank.DependenciesToLinkMatrix(dependencygroup.dependencies) matrix = converter.create_matrix() ranking = pagerank.page_rank(matrix) ids = [idx for idx in range(len(matrix))] filenames = [utils.prettify_path(converter.id_to_node_map[nid], leadingpath) for nid in ids] rowinfos = zip(filenames, ranking, ids, matrix) rowinfos.sort(key=lambda item: item[1]) #sort by ranking rowinfos.reverse() return rowinfos
def format_data(self, files_stats_failures): """Formats the output of measure_cyclcompl ([filename, stats], [failures]).""" self.format_failures(map(utils.prettify_path, files_stats_failures[1])) allrows = [] for filename, stat in files_stats_failures[0]: filename = utils.prettify_path(filename) rows = self.format_file_and_stats(filename, stat) for r in rows: r.insert(0, filename) allrows.extend(rows) sortby_cc_desc = lambda row: -(int(row[3])) tbl = tableprint.Table(["Filename", "Type", "Name", "CC"], sorted(allrows, key=sortby_cc_desc)) self.outstream().write("All results, sorted by CC:\n") tbl.write(self.outstream())
def _create_rows(slocgroup, leading_path): """Returns a list of rows.""" rows = [] sortedbyfilename = sorted(slocgroup.filenamesToSlocInfos.items(), key=lambda kvp: kvp[0]) for filename, d in sortedbyfilename: row = [ utils.prettify_path(filename, leading_path), d['code'], d['codeperc'], d['comment'], d['commentperc'], d['blank'], d['blankperc'], d['total'], d['totalperc'] ] rows.append(row) rows.append(_get_totals_row(slocgroup)) return rows
def _create_rows(slocgroup, leading_path): """Returns a list of rows.""" rows = [] sortedbyfilename = sorted( slocgroup.filenamesToSlocInfos.items(), key=lambda kvp: kvp[0]) for filename, d in sortedbyfilename: row = [utils.prettify_path(filename, leading_path), d['code'], d['codeperc'], d['comment'], d['commentperc'], d['blank'], d['blankperc'], d['total'], d['totalperc']] rows.append(row) rows.append(_get_totals_row(slocgroup)) return rows
def format_data(self, slocgroup): header = 'Filename', 'Code', 'Code%', 'Comment', 'Comment%', 'Blank', 'Blank%', 'Total', 'Total%' c = tableprint.JUST_C justs = tableprint.JUST_L, c, c, c, c, c, c, c, c rows = [] sortedbyfilename = sorted(slocgroup.filenamesToSlocInfos.items(), key=lambda kvp: kvp[0]) for filename, d in sortedbyfilename: row = (utils.prettify_path(filename), str(d['code']), self._fmtperc(d['codeperc']), str(d['comment']), self._fmtperc(d['commentperc']), str(d['blank']), self._fmtperc(d['blankperc']), str(d['total']), self._fmtperc(d['totalperc'])) rows.append(row) rows.append([''] * len(header)) #blank row rows.append(self._get_totals_row(slocgroup)) tbl = tableprint.Table(header, rows, just=justs) tbl.write(self.out)
def format_data(self, dependencygroup): header = 'Filename', 'PageRank', 'PageID', 'Outgoing Links' converter = pagerank.DependenciesToLinkMatrix(dependencygroup.dependencies) matrix = converter.create_matrix() ranking = pagerank.pageRank(matrix) ids = [idx for idx in range(len(matrix))] filenames = [utils.prettify_path(converter.id_to_node_map[nid]) for nid in ids] rowinfos = zip(filenames, ranking, ids, matrix) rowinfos.sort(key=lambda item: item[1]) #sort by ranking rowinfos.reverse() rows = [] for rowi in rowinfos: row = (rowi[0], self._fmt_rank(rowi[1]), str(rowi[2]), str(rowi[3])) rows.append(row) tbl = tableprint.Table(header, rows) tbl.write(self._outstream)
def nodetext(self, s): """Prettifies s for rendering on the node. Escape s and remove some junk (cwd, drive, ext) so that it can be used as a proper nodename. """ #First look for __init__ and move it down to the dir if it is s2 = s s2 = os.path.splitext(s2)[0] if s2.endswith('__init__'): s2 = s2[:-9] #-9 is len of __init__ and preceding path sep s2 = utils.prettify_path(s2, self.leading_path) if not s2: # We've removed the whole path, # grab the last dir from the leadingpath that removed it s2 = self.leading_path.replace(os.altsep, os.sep).split(os.sep)[-1] else: s2 = os.path.splitdrive(s2)[1] s2 = s2.replace(os.sep, '.').replace(os.altsep, '.') return s2.strip('.')
def testWorks(self): """Test basic functionality.""" s = utils.prettify_path(r'C:\foo\bar\eggs.spam', leading='C:\\') self.assertEqual(s, 'foo\\bar\\eggs')