Skip to content

Commit 1d04905

Browse files
committed
[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 <[email protected]>
1 parent 3382cb4 commit 1d04905

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

graal/backends/core/cocom.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CoCom(Graal):
7070
:raises RepositoryError: raised when there was an error cloning or
7171
updating the repository.
7272
"""
73-
version = '0.2.4'
73+
version = '0.2.5'
7474

7575
CATEGORIES = [CATEGORY_COCOM]
7676

@@ -80,9 +80,12 @@ def __init__(self, uri, git_path, worktreepath=DEFAULT_WORKTREE_PATH,
8080
super().__init__(uri, git_path, worktreepath,
8181
entrypoint=entrypoint, in_paths=in_paths, out_paths=out_paths, details=details,
8282
tag=tag, archive=archive)
83+
84+
self.history = dict()
85+
self.repository_level = None
8386
self.file_analyzer = FileAnalyzer(details)
8487

85-
def fetch(self, category=CATEGORY_COCOM, paths=None,
88+
def fetch(self, category=CATEGORY_COCOM, paths=None, repository_level=False,
8689
from_date=DEFAULT_DATETIME, to_date=DEFAULT_LAST_DATETIME,
8790
branches=None, latest_items=False):
8891
"""Fetch commits and add code complexity information."""
@@ -91,6 +94,7 @@ def fetch(self, category=CATEGORY_COCOM, paths=None,
9194
from_date=from_date, to_date=to_date,
9295
branches=branches, latest_items=latest_items)
9396

97+
self.repository_level = repository_level
9498
return items
9599

96100
@staticmethod
@@ -155,8 +159,10 @@ def _analyze(self, commit):
155159
if committed_file.get("newfile", None):
156160
file_path = committed_file["newfile"]
157161
local_path = self.worktreepath + '/' + file_path
162+
self.history.pop(file_path, None)
158163
analysis.append(file_info)
159164
elif committed_file.get("action", None) == "D":
165+
self.history.pop(file_path, None)
160166
analysis.append(file_info)
161167
continue
162168
else:
@@ -165,8 +171,28 @@ def _analyze(self, commit):
165171
file_info = self.file_analyzer.analyze(local_path)
166172
file_info.update({'file_path': file_path})
167173
analysis.append(file_info)
168-
169-
return analysis
174+
self.history[file_path] = file_info
175+
176+
if self.repository_level:
177+
repository_level_analysis = {
178+
'blanks': 0,
179+
'comments': 0,
180+
'loc': 0,
181+
'ccn': 0,
182+
'num_funs': 0,
183+
'tokens': 0,
184+
}
185+
for file_path in self.history:
186+
repository_level_analysis['blanks'] += self.history[file_path].get('blanks', 0)
187+
repository_level_analysis['comments'] += self.history[file_path].get('comments', 0)
188+
repository_level_analysis['loc'] += self.history[file_path].get('loc', 0)
189+
repository_level_analysis['ccn'] += self.history[file_path].get('ccn', 0)
190+
repository_level_analysis['num_funs'] += self.history[file_path].get('num_funs', 0)
191+
repository_level_analysis['tokens'] += self.history[file_path].get('tokens', 0)
192+
193+
return repository_level_analysis
194+
else:
195+
return analysis
170196

171197
def _post(self, commit):
172198
"""Remove attributes of the Graal item obtained

graal/graal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ def setup_cmd_parser(categories, exec_path=False):
497497
group.add_argument('--details', dest='details',
498498
action='store_true', default=False,
499499
help="include details")
500+
group.add_argument('--repository-level', dest='repository_level',
501+
action='store_true', default=False,
502+
help="Perform analysis at repository level")
500503

501504
# Required arguments
502505
parser.parser.add_argument('uri',

0 commit comments

Comments
 (0)