-
Notifications
You must be signed in to change notification settings - Fork 23
Yordanos Dirar - mood-analysis #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,61 @@ | ||
| FEELINGS = { | ||
| happy: %w(yay, good, great), | ||
| sad: %w(terrible, awful, horrible) | ||
| happy: %w(yay good great), | ||
| sad: %w(terrible awful horrible) | ||
| } | ||
|
|
||
| def analyze_mood(words) | ||
| happy = 0 | ||
| sad = 0 | ||
| words.downcase! | ||
|
|
||
| # using regex to extract the punctuation | ||
| words.gsub!(/[^[:word:]\s]/, ' ') | ||
|
|
||
| words.split(" ").each do |word| | ||
| if FEELINGS[:happy].include? word | ||
| happy += 1 | ||
| elsif FEELINGS[:sad].include? word | ||
| sad += 1 | ||
| end | ||
| end | ||
|
|
||
| return ":-)" if happy > sad | ||
| return ":-(" if happy < sad | ||
| return ":-|" | ||
| end | ||
|
|
||
| def happy_days(result) | ||
| happy_days = 0 | ||
| day_count = 0 | ||
|
|
||
| result.each do |journal| | ||
|
|
||
| mood = journal[1] | ||
|
|
||
| if happy_days < 3 | ||
| day_count += 1 | ||
| happy_days += 1 if mood == ":-)" | ||
| end | ||
| end | ||
| day_count | ||
| end | ||
|
|
||
|
|
||
| def overall_mood(result) | ||
|
|
||
| overall_mood_result = {} | ||
| overall_mood_result[":-)"] = 0 | ||
| overall_mood_result[":-|"] = 0 | ||
| overall_mood_result[":-("] = 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do |
||
|
|
||
| result.each do |journal| | ||
| overall_mood_result[journal[1]] += 1 | ||
| end | ||
|
|
||
| overall_mood_result.max_by {|mood, count| count}.first | ||
|
|
||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't do anything with journal[0] ever, why should we send |
||
|
|
||
| text = [ | ||
| "03/01 I'm having a terrible horrible no good day.", | ||
| "03/13 Yesterday was horrible, but today is great! Yay!", | ||
|
|
@@ -28,5 +65,14 @@ def analyze_mood(words) | |
| "05/11 Yay, yay, yay! I'm having a awfuly great day." | ||
| ] | ||
|
|
||
| puts analyze_mood(text[0]) | ||
| puts analyze_mood(text[1]) | ||
| result = text.map do |day| | ||
| date = day.split(" ").first | ||
| mood = analyze_mood(day) | ||
| puts | ||
| puts "#{date} #{mood}" | ||
|
|
||
| [date, mood] | ||
| end | ||
|
|
||
| puts "It takes #{happy_days(result)} entries for 3 happy days to occur" | ||
| puts "The most common mood is #{overall_mood(result)}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! Good job returning the smallest piece of information necessary and not an entire string encapsulating that information! |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there aren't 3 happy days in the entire log of days?