-
Notifications
You must be signed in to change notification settings - Fork 25
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
Panda Tiger Eagle #6
Open
seejohnplay
wants to merge
5
commits into
RubyoffRails:master
Choose a base branch
from
seejohnplay:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1d5c4b
Add error handling when searching for non-existant movies and keep a …
seejohnplay 2f03808
Show average year of movies and determine user temperament based on s…
seejohnplay 409a9af
Add message if best and worst rating score is the same.
seejohnplay f8eed78
Find average of all movies in max and min years and use results to fi…
seejohnplay 83e7d9a
Improve exception handling
seejohnplay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,63 @@ | |
require_relative "lib/api" | ||
|
||
def find_movie | ||
puts "OH HAI. Search?" | ||
puts 'Add a movie you really like:' | ||
movie_title = gets | ||
movie = Api.search_by_title(movie_title) | ||
puts "Found: #{movie.title}. Score: #{movie.score}" | ||
if !(current_movie = Api.search_by_title(movie_title)) | ||
puts 'Oops. Something went wrong or title not found.' | ||
else | ||
@movies << current_movie | ||
puts "Found: #{@movies.last.title}. Score: #{@movies.last.score} Year: #{@movies.last.year}" | ||
if @movies.length > 1 | ||
puts "Average movie score: #{get_average(@movies, "score", "float")}" | ||
puts "Average movie year: #{get_average(@movies, "year", "integer")}" | ||
puts get_satisfaction(@movies) | ||
end | ||
end | ||
end | ||
|
||
def get_average(movies, attribute, type) | ||
attribute_sum = 0 | ||
movies.each { |rating| attribute_sum += rating.send(attribute) } | ||
if type == "float" | ||
return attribute_sum / movies.length.to_f | ||
else | ||
return attribute_sum / movies.length | ||
end | ||
end | ||
|
||
def get_satisfaction(movies) | ||
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. This method is probably a bit too long. Good guideline: 3,4,5 lines are all your methods "should" be. |
||
min_movie = movies.min_by(&:year) | ||
max_movie = movies.max_by(&:year) | ||
return "neutral" if min_movie == max_movie | ||
max_movie_count, max_movie_score_total = 0, 0 | ||
min_movie_count, min_movie_score_total = 0, 0 | ||
movies.each do |movie| | ||
if movie.year == max_movie.year | ||
max_movie_count += 1 | ||
max_movie_score_total += movie.score | ||
end | ||
if movie.year == min_movie.year | ||
min_movie_count += 1 | ||
min_movie_score_total += movie.score | ||
end | ||
end | ||
user_slope = ((max_movie_score_total/max_movie_count).to_f - (min_movie_score_total/min_movie_count).to_f) / (max_movie.year - min_movie.year).to_f | ||
if user_slope == 0 | ||
return "neutral" | ||
elsif user_slope > 0 | ||
return "getting happier" | ||
else | ||
return "getting madder" | ||
end | ||
end | ||
|
||
@movies = [] | ||
|
||
find_movie | ||
|
||
while true do | ||
puts "Search Again (Y/N)" | ||
puts 'Search Again (Y/N)' | ||
answer = gets.upcase[0] | ||
if answer == "Y" | ||
find_movie | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Minor note: I don't love the use of a false here to indicate that nothing was found. This could be referred to as "primitive obsession". It gets the job done, but a different class like NilMovie might be "better"