Skip to content

Sockets - Grace#41

Open
gracemshea wants to merge 3 commits intoAda-C11:masterfrom
gracemshea:master
Open

Sockets - Grace#41
gracemshea wants to merge 3 commits intoAda-C11:masterfrom
gracemshea:master

Conversation

@gracemshea
Copy link

@gracemshea gracemshea 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? Initially, I was focused on making a dictionary-like structure, but it took me a while to work out how to incorporate the array of trip information I needed. I eventually went with a hash with a nested array of hashes. I can't take credit for this, I studied with some classmates and Tatiana's geniusness gave me the idea.
What was your strategy for going through the data structure and gathering information? Although I knew my data needed to be structured around the driver, I did worry about making a structure that would be inflexible to answering on some other aspect. But I decided to stop my brain and to focus on iterating through the driver's information. I used loops of .each .map and .sum on the drivers info as needed.
What was an example of something that was necessary to store in a variable? Why was it necessary, useful, or helpful? The drivers' total income, since I needed it for later calculation. It was necessary for my approach.
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? It seems like .map is best when you need to return a new array. I used it a few times to make arrays of hashes that I needed to perform some calculation on - for example max_by to find highest average rating.
Were some calculations easier than others? Why? Figuring out 3 - how to return who made the most money, was definitely the most time intensive to figure out. Once I got that one, the rest went really smoothly since I used the same approach. I actually kept the "key, value" verbage throughout because I had to have that little reminder of what data structures I was dealing with and how they would behave.

@droberts-sea
Copy link

Ride Share

What We're Looking For

Feature Feedback
Answers the comprehension questions yes
Readable code with consistent indentation and reasonable code style There is room for improvement here. I've tried to call this out inline where I see it, but in general your variable names need to be more descriptive, and it seems like you're sometimes trying to cram too many things on a line. Remember that one of the main jobs of a piece of code is to be read by other humans.
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

Good job overall! While there are certainly some things that could be cleaned up, your code works well and it is clear to me that the learning goals around working with enumerables and complex data structures were met. Keep up the hard work!

}
# count each driver's rides
rideshare.each {|key, value| puts "Driver #{key} went on a total of #{value.count} rides."}

Choose a reason for hiding this comment

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

Two comments here:

  • I would probably break this out across multiple lines and use do..end instead of curly braces
  • key and value are not very descriptive variable names. What about driver_id and rides?

highest_income = rideshare.map do |key, value|
{ name: key, total: value.sum do |record|
record[:cost]
end }

Choose a reason for hiding this comment

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

Your code structure here is a little odd. It looks like the combination of do..end and hash curly braces made VS Code confused about indentation (it's confusing to me as well). We could rewrite it a little more clearly as:

income_by_driver = rideshare.map do |driver_id, rides|
  income = rides.sum do |ride|
    ride[:cost]
  end
  { name: driver_id, total: income }
end

Choose a reason for hiding this comment

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

Note also the modified variable names 😉

rideshare.each do |key, value|
avg_rating = value.sum do |record|
((record[:rating].to_f) / value.length).round(2)
end

Choose a reason for hiding this comment

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

I notice that you used integer division for the average rating, and lost a little precision.

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