Module: Diggit::DevelopersActivity::ModuleMetricsExtractor

Extended by:
ModuleMetricsExtractor
Included in:
ModuleMetricsExtractor
Defined in:
lib/diggit/developers_activity/module_metrics_extractor.rb

Instance Method Summary collapse

Instance Method Details

#extract_bugfixes(bug_fix_commits, repo) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/diggit/developers_activity/module_metrics_extractor.rb', line 26

def extract_bugfixes(bug_fix_commits, repo)
	modules_bugfixes = Hash.new { |hash, key| hash[key] = Set.new }
	bug_fix_commits.each do |commit_oid|
		commit = repo.lookup(commit_oid)
		next if commit.parents.size != 1 # ignore merges
		diff = commit.parents[0].diff(commit, DIFF_OPTIONS)
		diff.find_similar!(DIFF_RENAME_OPTIONS)
		diff.each do |patch|
			maudule = ActivityExtractor::Modules.get_patch_module(patch)
			modules_bugfixes[maudule] = (modules_bugfixes[maudule] << commit_oid) unless maudule.nil?
		end
	end
	modules_bugfixes
end

#extract_loc(source, db) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/diggit/developers_activity/module_metrics_extractor.rb', line 41

def extract_loc(source, db)
	modules_loc = Hash.new(0)
	db.client['cloc-file'].find({ source: source.url }).each do |cloc_source|
		cloc_source['cloc'].each do |cloc_file|
			maudule = ActivityExtractor::Modules.get_module(cloc_file['path'])
			modules_loc[maudule] = modules_loc[maudule] + cloc_file['code'] unless maudule.nil?
		end
	end
	modules_loc
end

#extract_module_metrics(source, source_options, db, repo) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/diggit/developers_activity/module_metrics_extractor.rb', line 14

def extract_module_metrics(source, source_options, db, repo)
	modules_bugfixes = extract_bugfixes(source_options['bug-fix-commits'], repo)
	modules_loc = extract_loc(source, db)

	modules_metrics = []
	modules_loc.each do |maudule, loc|
		modules_metrics << { project: source.url, 'module' => maudule, 'LoC' => loc,
											   'BugFixes' => modules_bugfixes[maudule].size }
	end
	modules_metrics
end