Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions rideshare.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Ga-Young Jin, Cohort 12
# Wednesday, August 7th, 2019
# Week 1

rideshare_data = [
[
{ driver: "DR0001",
date: "3rd Feb 2016",

Choose a reason for hiding this comment

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

You have these arrays grouped by driver, but chose to leave the data inside these hashes, even though it's redundant. When I see groupings like this, it makes me think the outermost layer should probably be a hash!

cost: 10,
rider: "RD0003",
rating: 3
},
{ driver: "DR0001",
date: "3rd Feb 2016",
cost: 30,
rider: "RD0015",
rating: 4
},
{ driver: "DR0001",
date: "5th Feb 2016",
cost: 45,
rider: "RD0003",
rating: 2
}
],
[
{ driver: "DR0002",
date: "3rd Feb 2016",
cost: 25,
rider: "RD0073",
rating: 5
},
{ driver: "DR0002",
date: "4th Feb 2016",
cost: 15,
rider: "RD0013",
rating: 1
},
{ driver: "DR0002",
date: "5th Feb 2016",
cost: 35,
rider: "RD0066",
rating: 3
},
],
[
{ driver: "DR0003",
date: "4th Feb 2016",
cost: 5,
rider: "RD0066",
rating: 5
},
{ driver: "DR0003",
date: "5th Feb 2016",
cost: 50,
rider: "RD0003",
rating: 2
}
],
[
{ driver: "DR0004",
date: "3rd Feb 2016",
cost: 5,
rider: "RD0022",
rating: 5
},
{ driver: "DR0004",
date: "4th Feb 2016",
cost: 10,
rider: "RD0022",
rating: 4
},
{ driver: "DR0004",
date: "5th Feb 2016",
cost: 20,
rider: "RD0073",
rating: 5
}
]
]

# number of drives each driver has given
puts "Number of drives each driver has given:"
rideshare_data.each do |drives|
puts "#{drives[0][:driver]}: #{drives.length}"
end

# total amount of money each driver has made
puts "Total amount of money each driver made:"
rideshare_data.each do |drives|
total_money = 0
drives.each do |price|
total_money = total_money + price[:cost]
end
puts "#{drives[0][:driver]}: #{total_money}"
end

# average rating for each driver
puts "The average rating for each driver:"
rideshare_data.each do |drives|
total_rating = 0
drives.each do |ride|
total_rating = total_rating + ride[:rating]
end
avg_rating = total_rating / drives.length.to_f
puts "#{drives[0][:driver]}: #{sprintf('%.2f', avg_rating)}"
end

# driver that made the most money
most_money_driver = ""
money_made_array = Array.new
rideshare_data.each do |drives|
money_made = 0
drives.each do |ride|
money_made = money_made + ride[:cost]
end
money_made_array << money_made
end
most_money = 0
money_made_array.each do |total|
if total > most_money
most_money_driver = rideshare_data[0][0][:driver]
end
end

puts "The driver that made the most money: #{most_money_driver}."

# driver that has the highest average rating
highest_avg_rating_driver = ""
rideshare_data.each do |drives|
highest_avg_rating = 0
avg_rating_array = Array.new
total_rating = 0
drives.each do |ride|
total_rating = total_rating + ride[:rating]
end
avg_rating_array << total_rating / drives.length.to_f
total_rating = 0
avg_rating_array.each do |avg|
if avg > highest_avg_rating
highest_avg_rating_driver = drives[0][:driver]
end
end
end

puts "The driver with the highest average rating: #{highest_avg_rating_driver}."