Skip to content

Commit

Permalink
[cocom] Add repository level analysis
Browse files Browse the repository at this point in the history
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 <inishchith@gmail.com>
  • Loading branch information
inishchith committed Jun 13, 2019
1 parent 3382cb4 commit 1d04905
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
34 changes: 30 additions & 4 deletions graal/backends/core/cocom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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."""
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions graal/graal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 1d04905

Please sign in to comment.