<commit_before>require "temporal_locality/version"

module TemporalLocality
	class TemporalLocality
		def report
			render_view
			
		end

		def render_view
puts """
| resource |   | 1   | 2   |
| file_a   | 1 | x   | 100 |
| file_b   | 2 | 100 | x   |
"""
		end
	end
end
<commit_msg>Removed the duplication between the test fixture and the implementation for temporal_locality.rb.<commit_after>require "temporal_locality/version"

module TemporalLocality
	class TemporalLocality
		def initialize
			@occurrences = {} 
		end

		def report
			change_sets.each do |change_set|
				with_each_resource_from(change_set) do |resource_a|
					with_each_resource_from(change_set) do |resource_b|
						record_locality(resource_a, resource_b)
					end
				end
			end

			render_view
		end

		def change_sets
			`/home/stuart/code/temporal_locality/stubbed_binaries/svn log http://svn/repo/trunk`.split(/^-+$/)
		end

		def with_each_resource_from(change_set)
			change_set.split(/\n/).each do |line|
				match_result = line.match(/^M (.+)$/)
				yield match_result[1] if match_result
			end
		end

		def record_locality(resource_a, resource_b)
			if (!@occurrences[resource_a]) 
				@occurrences[resource_a] = {}
			end
		
			if (!@occurrences[resource_a][resource_b])
				@occurrences[resource_a][resource_b] = 0
			end

			@occurrences[resource_a][resource_b] += 1
		end

		def render_view
			puts header(@occurrences) + rows(@occurrences)
		end

		def header(occurrences)
			resource_numbering = (1..occurrences.size).collect do |resource_number| "   #{resource_number} |" end
			"| resource |     |" + resource_numbering.join + "\n"
		end

		def rows(occurrences)
			body = ""
			index = 0
			occurrences.each_pair do |resource_a, occurrences_for_resource_a|
				body += "|  #{resource_a} |   #{index += 1 } |"
					occurrences_for_resource_a.each_pair do |resource_b, occurrences_for_resource_b|
						body += "  #{resource_a == resource_b ? "x" : occurrences_for_resource_b * 100} |"
					end
				body += "\n"
			end
			return body
		end
	end
end

{'fraction_non_alphanumeric': 0.10763209393346379, 'fraction_numerical': 0.009295499021526418, 'mean_word_length': 3.4945054945054945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4406257', 'n_tokens_mistral': 896, 'n_tokens_neox': 708, 'n_words': 150}