From 04fc49be2973ac1b1586f37d1c6f77f8492c749a Mon Sep 17 00:00:00 2001 From: Jeremy Hanson-Finger Date: Tue, 17 May 2016 22:14:45 -0400 Subject: [PATCH] Initial commit of rorybot warning analytics test script --- analytics-test.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 analytics-test.rb diff --git a/analytics-test.rb b/analytics-test.rb new file mode 100644 index 0000000..e148b98 --- /dev/null +++ b/analytics-test.rb @@ -0,0 +1,29 @@ +require 'FileUtils' + +puts "Enter the filetype you want to search (rb, erb, md, or html" +filetype = gets.chomp.to_s + +puts "Processing #{filetype} files recursively in #{Dir.pwd} with Rorybot" +`rorybot **/*.#{filetype} | tee rorybot_output.txt` + +input_file = File.open('rorybot_output.txt', 'r') +output_file = File.open('frequency.csv', 'w+') +warning_message = /(?:warning\s{2,}?)(.+?)(?=\s{2,})/ +frequency = Hash.new(0) + +puts "Counting warning messages" +input_file.read.scan(warning_message) do |word| + frequency[word] = frequency[word] + 1 +end + +puts "Writing result to frequency.csv" +frequency.each do |key, value| + kv = "#{key}, #{value}" + kv.encode("UTF-8") + output_file.puts kv.gsub("[", "").gsub("]", "") +end + +puts "Deleting temporary files" +FileUtils.rm('rorybot_output.txt') + +puts "Use Google Sheets to open frequency.csv for further processing"