Skip to content

Create ride_share_sabine.rb#39

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

Create ride_share_sabine.rb#39
Sabineth17 wants to merge 1 commit into
Ada-C10:masterfrom
Sabineth17:master

Conversation

@Sabineth17

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?
  • My data structure took some time to organize. I initially didn't have a ride_share array containing all data as I immediately split each driver into hashes. After a few iterations I organized the data structure based on the information that I needed to pull from the hashes/array.

| 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? |

  • I am not comfortable yet using .map and need to work on it with my classmates or instructor or tutor. Although I am familiar with .map's function (equivalent to each.do), I am still having a bit of challenge applying it to my codes.

| Were some calculations easier than others? Why? | |

  • Most calculations were straigntforward because of a well organized data structure. It was clear where to pull information that would contribute to the desired calculations.

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!

@CheezItMan

Copy link
Copy Markdown

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.

Comment thread ride_share_sabine.rb
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}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works, but you need to calculate the number of trips programatically not by hard coding the specific driver IDs and dates

Comment thread ride_share_sabine.rb


driver_1_total_cost = []
cost1_1 = ride_share[:DR0001][:Feb3_2016][:trips][0][:cost]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is similarly calculating the costs by hard-coding the driver ids and dates.

Comment thread ride_share_sabine.rb
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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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