<commit_before>require 'git_sniffer'
require 'ruport'

puts "#" * 30
puts "Example: author changed lines"
puts "#" * 30
puts 

##########################FIXTURE#############################
@base = GitSniffer::Base.open(File.dirname(__FILE__) + "/fixture/JSON-java.git")
##############################################################

##########################EXEC################################
GitSniffer::Commit.add_hook(:changed_lines) { |commit| commit.diff_parent[:insert] + commit.diff_parent[:delete] }
author_commits = @base.commits.group_by { |commit| commit.committer }

result = author_commits.inject({}) do |res, author_with_commits|
	res[author_with_commits[0]] = author_with_commits[1].inject(0) { |res, commit| res += commit.hook_changed_lines }
	res
end

##########################RESULT#############################
table = Ruport::Data::Table.new :column_names => ["author", "changed_lines"],
								:data => result.to_a

puts table.to_text
puts<commit_msg>use sum instead of inject.<commit_after>require 'git_sniffer'
require 'active_support/core_ext'
require 'ruport'

puts "#" * 30
puts "Example: author changed lines"
puts "#" * 30
puts 

##########################FIXTURE#############################
@base = GitSniffer::Base.open(File.dirname(__FILE__) + "/fixture/JSON-java.git")
##############################################################

##########################EXEC################################
GitSniffer::Commit.add_hook(:changed_lines) { |commit| commit.diff_parent[:insert] + commit.diff_parent[:delete] }
author_commits = @base.commits.group_by { |commit| commit.committer }

result = author_commits.inject({}) do |res, author_with_commits|
	res[author_with_commits[0]] = author_with_commits[1].sum(0) { |commit| commit.hook_changed_lines }
	res
end

##########################RESULT#############################
table = Ruport::Data::Table.new :column_names => ["author", "changed_lines"],
								:data => result.to_a

puts table.to_text
puts
{'fraction_non_alphanumeric': 0.3442211055276382, 'fraction_numerical': 0.007035175879396985, 'mean_word_length': 8.13302752293578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3423923', 'n_tokens_mistral': 624, 'n_tokens_neox': 591, 'n_words': 105}