Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

rorybot warning analytics test script [WIP] #17

Closed
wants to merge 10 commits into from

Conversation

jeremyhansonfinger
Copy link
Contributor

@jeremyhansonfinger jeremyhansonfinger commented May 18, 2016

At the moment this script asks you what file type you want to analyze, recursively runs Rorybot on every file of that type in your current directory, and outputs the frequency of each warning to a CSV file that you can manipulate further with Google Sheets.

image

image

Closes #4

@jeremyhansonfinger jeremyhansonfinger changed the title Initial commit of rorybot warning analytics test script [WIP] rorybot warning analytics test script [WIP] May 18, 2016
frequency = Hash.new(0)

puts "Counting warning messages"
input_file.read.scan(warning_message) do |word|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input_file.read.scan(warning_message).map { |w| frequency[w] + 1 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get this to add to frequency (even taking out read). If I try to print frequency it gives me {}

If I put it back to

input_file.scan(warning_message) do |word|
  frequency[word] = frequency[word] + 1

it does work, however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I misread this. That said, frequency[word] = frequency[word] + 1 should work as frequency[word] += 1


input_file = File.open('rorybot_output.txt', 'r')
output_file = File.open('frequency.csv', 'w+')
warning_message = /(?:warning\s{2,}?)(.+?)(?=\s{2,})/
Copy link
Contributor

@jules2689 jules2689 May 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty nasty regex, what is it intending to match? I dont really wanna take the time to figure it out lol

Copy link
Contributor Author

@jeremyhansonfinger jeremyhansonfinger May 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, yeah, there's got to be a better way. I'm trying to match this:

http://rubular.com/r/ILo7BWe8ux

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^.*warning (.*)$

  • ^ denotes the beginning of the line.
  • .* matches everything up to warning
  • warning matches warning
  • matches the 2 spaces (could also be\s+)
  • (.*)$ creates a capture group for the rest of the line because $ means "end of line"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Waaaaaay cleaner. I don't know what I was thinking.

@jules2689
Copy link
Contributor

Looks like my comments got suppressed. Can you go through all the outdated ones and comment on them?

@jules2689
Copy link
Contributor

basically all these:
image

@jeremyhansonfinger
Copy link
Contributor Author

Will do!
On May 18, 2016 11:29 AM, "Julian Nadeau" [email protected] wrote:

basically all these:
[image: image]
https://cloud.githubusercontent.com/assets/3074765/15364781/cccee5b6-1ceb-11e6-83b3-2b05af03d9d3.png


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#17 (comment)

@jeremyhansonfinger
Copy link
Contributor Author

jeremyhansonfinger commented May 18, 2016

@jules2689 I'm running into an error now on my most recent commit, on line 26:

input_file.scan(warning_message).map { |w| frequency[w] + 1 }

image

Any ideas?

@jeremyhansonfinger
Copy link
Contributor Author

jeremyhansonfinger commented May 18, 2016

Regarding my error above, I did change your suggestion to

- input_file.read.scan(warning_message).map { |w| frequency[w] + 1 }
+ input_file.scan(warning_message).map { |w| frequency[w] + 1 }

because of the suggestion to change File.open to File.read, but leaving read in there resulted in a an undefined method error.

@jules2689
Copy link
Contributor

jules2689 commented May 18, 2016

Okay, so frequency[w] would be initialized as nil. Apparently when passing a value to Hash.new it does this:

Hashes have a default value that is returned when accessing keys that do not exist in the hash. If no default is set nil is used. You can set the default value by sending it as an argument to ::new:

TIL. Change the frequency = {} above back to frequency = Hash.new(0)

@jeremyhansonfinger
Copy link
Contributor Author

No longer required.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants