Skip to content

Laura_ride-share.rb#32

Open
lauracodecreations wants to merge 1 commit into
Ada-C10:masterfrom
lauracodecreations:master
Open

Laura_ride-share.rb#32
lauracodecreations wants to merge 1 commit into
Ada-C10:masterfrom
lauracodecreations:master

Conversation

@lauracodecreations

@lauracodecreations lauracodecreations commented Aug 13, 2018

Copy link
Copy Markdown

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? Yes, when I tried to calculate total amount made per driver, I knew I needed the transactions to be in one array to call the .sum method
What was your strategy for going through the data structure and gathering information? I spent a lot of time deciding on the structure before implementing it. It helped to think about how one would look like, and how to calculate the statistics for just one person, then expanding it to all the drivers and deciding what structure would be best for all structures
What was an example of something that was necessary to store in a variable? What was the scope of each of that variables? Why? I needed to store all the money made by each driver in one array, to use .max to get the maximum amount made in the group and use that to identify the driver. This also applied to the maximum average rating. I declared these variables at the beginning and updated the variable with the max value.
What kinds of iteration did you use? Did you use .map? .each, .each_with index, max_by
Were some calculations easier than others? Why? yes, calculating money made, average rating, and total rides was easy because I could just access the data and use it in my equation for average, and calculating total

@CheezItMan

Copy link
Copy Markdown

Your data structure works although it can be a bit awkward to keep rating, date, rider and cost all aligned with the same index. You've got some good helper methods and you did a good job checking to see if a driver had multiple trips on one day. Really nice work! You hit all the learning goals.

Comment thread Laura_ride-share.rb
{
:driver_id => "DR0001",
:rating => [3,4,2],
:rider_id => ["RD0003","RD0015","RD0003"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're using parallel arrays here, which is fine, but it can be awkward to keep them aligned. It would be easier to have one array of trips with date, rider_id, rating, and cost keys.

Comment thread Laura_ride-share.rb
def add_values_hash(hash)
newhash = Hash.new()
hash.each do |k, v|
newhash[k] = v.reduce(:+)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So this will replace the array of values with the sum, eliminating the original data.

Comment thread Laura_ride-share.rb
totals_rating << driver[:average_rating]

# calculate the date in which the highest money was made
if driver[:dates].uniq.length == driver[:dates].length # one trip per day

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would think about drying this out so you could have one block of code that would calculate the max money on each date regardless if they had 1 trip or multiple.

Comment thread Laura_ride-share.rb
hash = Hash.new()
dates.each_with_index do |date, index|
# if key is not present in the hash, create it with an array as the value
hash[date] ||= [] # hash[key] = hash[key] || []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's also a group_by Enumerable which could be helpful.

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