From 1d049052fc2ef12150312dddfba57c5e7c6bcc63 Mon Sep 17 00:00:00 2001 From: inishchith Date: Thu, 13 Jun 2019 19:20:24 +0530 Subject: [PATCH] [cocom] Add repository level analysis The idea is to produce repository level analysis for CoCom backend using a history of files and picking the latest values of the available results Signed-off-by: inishchith --- graal/backends/core/cocom.py | 34 ++++++++++++++++++++++++++++++---- graal/graal.py | 3 +++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/graal/backends/core/cocom.py b/graal/backends/core/cocom.py index 356bbee..ef9d23e 100644 --- a/graal/backends/core/cocom.py +++ b/graal/backends/core/cocom.py @@ -70,7 +70,7 @@ class CoCom(Graal): :raises RepositoryError: raised when there was an error cloning or updating the repository. """ - version = '0.2.4' + version = '0.2.5' CATEGORIES = [CATEGORY_COCOM] @@ -80,9 +80,12 @@ def __init__(self, uri, git_path, worktreepath=DEFAULT_WORKTREE_PATH, super().__init__(uri, git_path, worktreepath, entrypoint=entrypoint, in_paths=in_paths, out_paths=out_paths, details=details, tag=tag, archive=archive) + + self.history = dict() + self.repository_level = None self.file_analyzer = FileAnalyzer(details) - def fetch(self, category=CATEGORY_COCOM, paths=None, + def fetch(self, category=CATEGORY_COCOM, paths=None, repository_level=False, from_date=DEFAULT_DATETIME, to_date=DEFAULT_LAST_DATETIME, branches=None, latest_items=False): """Fetch commits and add code complexity information.""" @@ -91,6 +94,7 @@ def fetch(self, category=CATEGORY_COCOM, paths=None, from_date=from_date, to_date=to_date, branches=branches, latest_items=latest_items) + self.repository_level = repository_level return items @staticmethod @@ -155,8 +159,10 @@ def _analyze(self, commit): if committed_file.get("newfile", None): file_path = committed_file["newfile"] local_path = self.worktreepath + '/' + file_path + self.history.pop(file_path, None) analysis.append(file_info) elif committed_file.get("action", None) == "D": + self.history.pop(file_path, None) analysis.append(file_info) continue else: @@ -165,8 +171,28 @@ def _analyze(self, commit): file_info = self.file_analyzer.analyze(local_path) file_info.update({'file_path': file_path}) analysis.append(file_info) - - return analysis + self.history[file_path] = file_info + + if self.repository_level: + repository_level_analysis = { + 'blanks': 0, + 'comments': 0, + 'loc': 0, + 'ccn': 0, + 'num_funs': 0, + 'tokens': 0, + } + for file_path in self.history: + repository_level_analysis['blanks'] += self.history[file_path].get('blanks', 0) + repository_level_analysis['comments'] += self.history[file_path].get('comments', 0) + repository_level_analysis['loc'] += self.history[file_path].get('loc', 0) + repository_level_analysis['ccn'] += self.history[file_path].get('ccn', 0) + repository_level_analysis['num_funs'] += self.history[file_path].get('num_funs', 0) + repository_level_analysis['tokens'] += self.history[file_path].get('tokens', 0) + + return repository_level_analysis + else: + return analysis def _post(self, commit): """Remove attributes of the Graal item obtained diff --git a/graal/graal.py b/graal/graal.py index 941b8e3..169b3e8 100644 --- a/graal/graal.py +++ b/graal/graal.py @@ -497,6 +497,9 @@ def setup_cmd_parser(categories, exec_path=False): group.add_argument('--details', dest='details', action='store_true', default=False, help="include details") + group.add_argument('--repository-level', dest='repository_level', + action='store_true', default=False, + help="Perform analysis at repository level") # Required arguments parser.parser.add_argument('uri',