From aa941ca3213c3721c8ea2cce1c6208ca68598cb9 Mon Sep 17 00:00:00 2001 From: Shonda860 <57575225+Shonda860@users.noreply.github.com> Date: Sun, 9 Feb 2020 20:13:53 -0800 Subject: [PATCH 1/2] Create ride-share.rb Ride-Share project Stage 1 --- ride-share.rb | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 ride-share.rb diff --git a/ride-share.rb b/ride-share.rb new file mode 100644 index 0000000..b8cc42d --- /dev/null +++ b/ride-share.rb @@ -0,0 +1,175 @@ +driver_info = [ + { driver_id: "DR0001", + trips: [ + { + date: "3rd Feb 2016", + cost: 10, + rider_id: "RD0003", + rating: 5.to_f + }, + { + date: "3rd Feb 2016", + cost: 30, + rider_id: "RD0015", + rating: 4.to_f + }, + { + date: "5th Feb 2016", + cost: 45, + rider_id: "RD0003", + rating: 2.to_f + }, + ]}, + { driver_id: "DR0002", + trips: [ + { + date: "3rd Feb 2016", + cost: 25, + rider_id: "RD0073", + rating: 5.to_f + }, + { + date: "4th Feb 2016", + cost: 15, + rider_id: "RD0013", + rating: 1.to_f + }, + { + date: "5th Feb 2016", + cost: 35, + rider_id: "RD0066", + rating: 3.to_f + }, + ]}, + { driver_id: "DR0003", + trips: [ + { + date: "4th Feb 2016", + cost: 5, + rider_id: "RD0066", + rating: 5.to_f + }, + { + date: "5th Feb 2016", + cost: 20, + rider_id: "RD0003", + rating: 2.to_f + }, + ]}, + { driver_id: "DR0004", + trips: [ + { + date: "3rd Feb 2016", + cost: 5, + rider_id: "RD0022", + rating: 5.to_f + }, + { + date: "4th Feb 2016", + cost: 10, + rider_id: "RD0022", + rating: 4.to_f + }, + { + date: "5th Feb 2016", + cost: 20, + rider_id: "RD0073", + rating: 5.to_f + }, + ]}, + ] + +######################################################## +# Step 2: Assign a data structure to each layer + +# Copy your list from above, and in this section +# determine what data structure each layer should have + +######################################################## +# Step 3: Make the data structure! + +# Setup the entire data structure: +# based off of the notes you have above, create the +# and manually write in data presented in rides.csv +# You should be copying and pasting the literal data +# into this data structure, such as "DR0004" +# and "3rd Feb 2016" and "RD0022" + +######################################################## +# Step 4: Total Driver's Earnings and Number of Rides + +# Use an iteration blocks to print the following answers: +# - the number of rides each driver has given +# - the total amount of money each driver has made +# - the average rating for each driver +# - Which driver made the most money? +# - Which driver has the highest average rating? + +drivers_cost_totals = [] +#this loop identifies each driver(s) id +driver_info.each do |driver| + +#outputs drivers id +puts "This puts driver id: #{driver[:driver_id]}" + +# show the breakdown of each trip a driver to based on driver id +trips_for_this_driver = driver[:trips] +trips_for_this_driver.map do |record| +end + +# empty array gathering all +num = 0 +drivers_cost_totals = [] +driver_total_ratings= [] +trips_for_this_driver.map do |trip| + puts "On #{trip[:date]} Trip #{num+=1} #{trip[:cost]}" + trips_date = trip[:date] + trips_cost = trip[:cost] + trips_rating = trip[:rating] + drivers_cost_totals << trips_cost + driver_total_ratings << trips_rating +end + +#The number of rides each driver has given +puts "DRIVER #{driver[:driver_id]} DROVE #{drivers_cost_totals.count} rides." +puts "On #{driver[:date]} driver made $#{drivers_cost_totals.max}" + + +# The total amount of money each driver has made +puts "DRIVERS TOTAL COST #{driver[:driver_id]} $#{drivers_cost_totals.sum}" + +# The average rating for each driver + puts "DRIVER #{driver[:driver_id]} DROVE #{(driver_total_ratings.sum/driver_total_ratings.length).round(2)}" +end + + +# Which driver made the most money? +most_profitable_driver = driver_info.max_by do |driver| + driver[:trips].sum do |trip| + trip[:cost] + end +end +puts +puts "Most profitable driver #{most_profitable_driver[:driver_id]}" +most_profitable_driver[:trips].each do |trip| + puts "Date #{trip[:date]} Cost $#{trip[:cost]}" + +end + +# Which driver has the highest average rating? +highest_average_rated_driver = driver_info.max_by do |driver| + total_ratings = driver[:trips].sum do |trip| + trip[:rating] + end + avg_rating = total_ratings / driver[:trips].length +end + + +sum_of_highest_rated_drivers_ratings =[] +# puts "Highest Average Rated Driver #{highest_average_rated_driver}" +puts +puts "Highest rated driver name #{highest_average_rated_driver[:driver_id]}" +highest_average_rated_driver[:trips].each do |trip| +puts "Date #{trip[:date]}Rating #{trip[:rating]}" +sum_of_highest_rated_drivers_ratings << trip[:rating] +end From d0807d406e377fb9368c15751d5ce61ffe05055c Mon Sep 17 00:00:00 2001 From: Shonda860 <57575225+Shonda860@users.noreply.github.com> Date: Sat, 15 Feb 2020 11:28:56 -0800 Subject: [PATCH 2/2] Update ride-share.rb moved driver_id's down one for readability Co-Authored-By: Chris M --- ride-share.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ride-share.rb b/ride-share.rb index b8cc42d..760f32e 100644 --- a/ride-share.rb +++ b/ride-share.rb @@ -1,5 +1,6 @@ driver_info = [ - { driver_id: "DR0001", + { + driver_id: "DR0001", trips: [ { date: "3rd Feb 2016",