コード例 #1
0
    def get_metrics_from_stat(self, file_diff_stats):
        total_lines = 0
        lines_by_file_type = collections.defaultdict(int)

        for file_diff_stat in file_diff_stats:
            lines_changed = (
                len(file_diff_stat.lines_added) -
                len(file_diff_stat.lines_removed)
            )

            # Track total overall
            total_lines += lines_changed

            # Track by file extension -> type mapping
            file_type = FILE_TYPE_MAP.get(file_diff_stat.extension, 'unknown')
            lines_by_file_type[file_type] += lines_changed

        # Yield overall metric and one per type of expected mapping types
        yield Metric('TotalLinesOfCode', total_lines)
        for file_type in set(FILE_TYPE_MAP.values()) | set(['unknown']):
            lines_changed = lines_by_file_type.get(file_type, 0)
            yield Metric(
                'TotalLinesOfCode_{0}'.format(file_type),
                lines_changed,
            )
コード例 #2
0
ファイル: curse.py プロジェクト: bukzor/git-code-debt
    def get_metrics_from_stat(self, file_diff_stats):
        total_curses = 0
        curses_by_file_type = collections.defaultdict(int)

        for file_diff_stat in file_diff_stats:
            curses_added = count_curse_words(file_diff_stat.lines_added)
            curses_removed = count_curse_words(file_diff_stat.lines_removed)
            curses_changed = curses_added - curses_removed

            # Track total overall
            total_curses = total_curses + curses_changed

            # Track by file extension -> type mapping
            file_type = FILE_TYPE_MAP.get(file_diff_stat.extension, 'unknown')
            curses_by_file_type[file_type] += curses_changed

        # Yield overall metric and one per type of expected mapping types
        yield Metric('TotalCurseWords', total_curses)
        for file_type in set(FILE_TYPE_MAP.values() + ['unknown']):
            curses_changed = curses_by_file_type.get(file_type, 0)
            yield Metric('TotalCurseWords_{0}'.format(file_type), curses_changed)
コード例 #3
0
 def get_possible_metric_ids(self):
     return ['TotalCurseWords'] + [
         'TotalCurseWords_{0}'.format(file_type)
         for file_type in set(FILE_TYPE_MAP.values()) | set(['unknown'])
     ]