Skip to content
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

Update and rename worksheet.rb to Sophia_worksheet.rb #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SoCodeDo
Copy link

Assignment Submission: Ride Share

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Question Answer
What did your data structure look like at first? Did this structure evolve over time? Why? My data structure stayed the same throughout my problem solving processs. When I first envisioned my code, I wrote out on a whiteboard the exact layers/organization I thought would best utilize the data that was given to me. The formatting I chose was to create a Hash of an Array of Hashes. This allowed each driver(KEY) to be paired to a hash of rider information (VALUE).
What was your strategy for going through the data structure and gathering information? I had to think a lot about layers, and how to access information if one layer is nested into another. I leaned heavily on the Data Transformation Worksheet to gather my initial formatting.
What was an example of something that was necessary to store in a variable? Why was it necessary, useful, or helpful? Anytime I was creating a new value, such as calculating sum or average. Its necessary in order to keep data concise and my code readable.
What kinds of iteration did you use? Did you use .map? If so, when? If not, why, or when would be a good opportunity to use it? .each and .map were used, .map was used the most. Now that I am getting more comfortable with enumerables they are SO MUCH easier than the normal itteration methods. One of the tutors helped me wrap my head around them last week!
Were some calculations easier than others? Why? yes! Finding the highest rating/paid gave me so much grief. I tried maybe a dozen itterations and finally had to let it go. I'll be talking with my tutor today about where I went wrong.

Copy link
Collaborator

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Overall pretty well done. You hit the main learning goals here.

I do suggest you use methods a bit rather than put everything into the main program. You also struggled with the last two questions to answer. See my inline comments for some ideas. Let me know if you have questions and I'll be happy to answer them.

Comment on lines +148 to +155
# rider_data.map do |driver, earnings|
# sum = rider_data[driver].sum do |i|
# i[:cost]
# maximum = sum.max {|i|}
# puts maximum
# end
# puts "#{driver}: has made $#{maximum}."
# end
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could do something like this. 1st use map to create an array of hashes with the keys being the driver id and the value being their total earnings.

Suggested change
# rider_data.map do |driver, earnings|
# sum = rider_data[driver].sum do |i|
# i[:cost]
# maximum = sum.max {|i|}
# puts maximum
# end
# puts "#{driver}: has made $#{maximum}."
# end
rider_earnings = rider_data.map do |driver, earnings|
# Total up this driver's earnings
total_earnings = earnings.sum do |trip|
trip[:cost]
end
# map this list of drivers into an array of hashes with the
# driver ids and their total earnings.
{ driver_id: driver, total_earnings: total_earnings}
end
# find the highest paid entry in that array of hashes.
highest_paid_driver = rider_earnings.max_by do |driver_earnings|
driver_earnings[:total_earnings]
end
puts "Highest Paid driver = #{highest_paid_driver}"

puts "Highest Average Rating:"
puts

# Which driver has the highest average rating?
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above you can do something similar here.

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

Successfully merging this pull request may close these issues.

2 participants