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

Ports - Kasey #47

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

Ports - Kasey #47

wants to merge 1 commit into from

Conversation

kaseea
Copy link

@kaseea kaseea commented Feb 19, 2019

ride share

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What did your data structure look like at first? Did this structure evolve over time? Why? this is what it looked like at first, I tried it another way for a second and went back, it just works in a way my mind gets
What was your strategy for going through the data structure and gathering information? first loop to get to the array of hashes, then access the array of hashes for final info
What was an example of something that was necessary to store in a variable? Why was it necessary, useful, or helpful? a hash
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? yup
Were some calculations easier than others? Why? easier to just make it to sum

@droberts-sea
Copy link

Ride Share

What We're Looking For

Feature Feedback
Answers the comprehension questions You need to provide more in-depth answers to these in the future. We assign these comprehension questions for a reason - the process of thinking through and explaining is important to solidify your learning. Typically we expect at least a full sentence or two for each.
Readable code with consistent indentation and reasonable code style some - see inline
Outputs the correct number of rides each driver has given yes
Outputs the total amount of money each driver has made yes
Outputs the average rating for each driver yes
Outputs which driver made the most money yes
Outputs which driver has the highest average rating yes

This code certainly solves the problem at hand, and is for the most part well-organized. However, there are definitely some pieces that could be cleaned up, as I've tried to call out in the inline comments below. Action items for you before your next submission:

  • Make sure you've got a good handle on the difference between return and puts
  • Use more descriptive variable names

Beyond that, I'm not too concerned. Keep up the hard work!

rideinfo = {
DR0004: [{date: Time.new(2016, 2, 3, 0, 0, 0),
cost: 5,
rider_id: "RD0022",

Choose a reason for hiding this comment

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

It's not a huge deal, but at Ada, our recommendation is that each key/value pair get a separate line, and that each level of a data structure gets a separate level of indentation. Applying those rules, this data structure would look like:

rideinfo = {
  DR0004: [
    {
      date: Time.new(2016, 2, 3, 0, 0, 0),
      cost: 5,
      rider_id: "RD0022",
      rating: 5
    },
    {
      ...
    }
  ],
  DR001: [
    ...
  ],
  ...
}

rating: 5},
{date: Time.new(2016, 2, 4, 0, 0, 0),
cost: 10,
rider_id: "RD0022",

Choose a reason for hiding this comment

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

Good use of the Time class here.


rideinfo.each do |k, v|
puts v.length
end

Choose a reason for hiding this comment

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

This just prints out the number of rides, not who was driving. This is especially confusing since your drivers are out of order (driver 4 comes first).

rideinfo.each do |k, v|
summed = v.sum { |x| x[:cost] }
puts "driver #{k} made $#{summed}"
end

Choose a reason for hiding this comment

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

k, v and x are not great variable names. As a newcomer to this code, I have no idea what these variables are supposed to contain. driver_id, trips, and trip might be better choices.

As an engineer, a huge portion of your job is communicating your ideas to other engineers, and variable names are part of that. Remember, your code will be read many more times than it is written.

puts "driver #{highest} has the highest rating with #{holder[highest].round(2)}"
end

puts highestRating(rideinfo)

Choose a reason for hiding this comment

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

Your highestRating method finishes with a puts (line 81), which means it implicitly returns nil. That means that line 84 will print out nothing but an empty line. The same thing happens with mostMoney.

In general, we recommend you return values from methods, and puts from whatever code calls that method.

def mostMoney(rideinfo)
holder = rideinfo.map { |k, v|
[k, v.sum { |x| x[:cost] }]
}.to_h

Choose a reason for hiding this comment

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

I like that you've broken this work out into separate methods - good organization!

def highestRating(rideinfo)
holder = rideinfo.map { |k, v|
[k, (v.sum { |x| x[:rating] } / v.length.to_f)]
}.to_h

Choose a reason for hiding this comment

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

I like that you're using the enumerable methods we learned about in class here. However, the fact that you're having to make this complicated array structure and then call .to_h on the result indicates to me that the map pattern doesn't quite fit this problem.

Unfortunately Ruby doesn't have a builtin method to map a hash to a hash (which is what you're really looking for), but you might find this article interesting.

@kaidamasaki
Copy link

Test Grade! Hope this did the normal grade things!

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.

3 participants