Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaves - Georgina #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
140 changes: 140 additions & 0 deletions ride-share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
rides_by_driver_id = {
DR0004: [
{
date:"3rd Feb 2016",
cost: 5,
rider_id: "RD0022",
rating: 5,
},
{
date: "4th Feb 2016",
cost: 10,
rider_id: "RD0022",
rating: 4,
},
{
date: "5th Feb 2016",
cost: 20,
rider_id: "RD0073",
rating: 5,
}],
DR0001: [
{
date: "3rd Feb 2016",
cost: 10,
rider_id: "RD0003",
rating: 3,
},
{
date: "3rd Feb 2016",
cost: 30,
rider_id: "RD0015",
rating: 4,
},
{
date: "5th Feb 2016",
cost: 45,
rider_id: "RD0003",
rating: 2,
}],
DR0002: [
{
date: "3rd Feb 2016",
cost: 25,
rider_id: "RD0073",
rating: 5,
},
{
date: "4th Feb 2016",
cost: 15,
rider_id: "RD0013",
rating: 1,
},
{
date: "5th Feb 2016",
cost: 35,
rider_id: "RD0066",
rating: 3,
}],
DR0003: [
{
date: "4th Feb 2016",
cost: 5,
rider_id: "RD0066",
rating: 5,
},
{
date: "5th Feb 2016",
cost: 50,
rider_id: "RD0003",
rating: 2,
}]
}

# The number of rides each driver has given

array_rides_by_driver_id = rides_by_driver_id.map do |driver_id, rides|
{driver_id => rides.length}
end

puts "The number of rides each driver has given: "

array_rides_by_driver_id.each do |total_rides_by_driver_id|
total_rides_by_driver_id.each do |driver_id, rides|
puts "#{driver_id}: #{rides}"
end
end

# The total amount of money each driver has made

array_salary_by_driver_id = rides_by_driver_id.map do |driver_id, rides|
{driver_id => rides.map do |ride|
ride[:cost]
end.sum}
end

puts "The total amount of money each driver has made: "

array_salary_by_driver_id.each do |salary_by_driver_id|
salary_by_driver_id.each do |driver_id, salary|
puts "#{driver_id}: #{salary}"
end
end

# The average rating for each driver

array_rating_by_driver_id = rides_by_driver_id.map do |driver_id, rides|
{driver_id => rides.map do |ride|
ride[:rating]
end}
end

average_rating_by_driver_id = {}
array_rating_by_driver_id.each do |driver|
driver.each do |driver_id, rating|
average_rating_by_driver_id[driver_id] = ((rating.sum.to_f) / rating.length).round(2)
end
end

puts "The average rating for each driver: "

average_rating_by_driver_id.each do |driver_id, average_rating|
puts "#{driver_id}: #{average_rating}"
end

# Which driver made the most money?

richest_driver = array_salary_by_driver_id.max_by do |salary_by_driver_id|

Choose a reason for hiding this comment

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

I appreciate the high level comments walking the reader through your process!

driver_id, salary = salary_by_driver_id.first
salary
end

puts "The driver who made the most money is: #{richest_driver.first.first.to_s}"

# Which driver has the highest average rating?

best_driver = average_rating_by_driver_id.max_by do |driver_id, rating|
rating
end

puts "The driver who has the highest average rating is #{best_driver.first}"