Create ride_share_sabine.rb#39
Conversation
|
You created a good structure for the data, but your calculations were not methods and they used hard-coded values for the driver ids and dates instead of using loops and enumerables to do the work without having to know specific driver IDs and dates. So a good start, but you need to work on creating methods that work on that structure regardless of the specific values. |
| ride_share[:DR0001][:Feb3_2016][:trips].length | ||
| ride_share[:DR0001][:Feb5_2016][:trips].length | ||
| driver_1 = ride_share[:DR0001][:Feb3_2016][:trips].length + ride_share[:DR0001][:Feb5_2016][:trips].length | ||
| puts "Total of rides for driver 1 is #{driver_1}" |
There was a problem hiding this comment.
This works, but you need to calculate the number of trips programatically not by hard coding the specific driver IDs and dates
|
|
||
|
|
||
| driver_1_total_cost = [] | ||
| cost1_1 = ride_share[:DR0001][:Feb3_2016][:trips][0][:cost] |
There was a problem hiding this comment.
This is similarly calculating the costs by hard-coding the driver ids and dates.
| driver_1_total_cost = [] | ||
| cost1_1 = ride_share[:DR0001][:Feb3_2016][:trips][0][:cost] | ||
| cost1_2 = ride_share[:DR0001][:Feb3_2016][:trips][1][:cost] | ||
| cost1_3 = ride_share[:DR0001][:Feb5_2016][:trips][0][:cost] |
There was a problem hiding this comment.
This might work better as a method that returns the driver costs.
def driver_costs(data)
return data.keys.map do |driver_id|
driver_totals = {id: driver_id}
total = 0
data[driver_id].keys.each do |date|
total += data[driver_id][date][:trips].sum do |trip|
trip[:cost]
end
end
driver_totals[:costs] = total
end
end
ride share
Congratulations! You're submitting your assignment.
Comprehension Questions
| What was your strategy for going through the data structure and gathering information? |
My strategy ( quite foundational) was to go through each layer of the data and figure out a way to pull the information from the array/hashes. My next strategy would have been to organize the information utilizing more sophisticated methods learned in class.
|
| 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 need to store the data from each driver/per day into a variable. For example, In order to calculate total cost for each driver, I created several variables to capture the cost per driver/day. This variable further served to be part of the addition of each's day earnings.
| What kinds of iteration did you use? Did you use
.map? || Were some calculations easier than others? Why? | |
I am aware that I did not complete the assignment fully utilizing the tools given. I will go over it with my tutor today and a few classmates - compare/contrast various tools utilized and learn from the process.
Thank you!