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
106 changes: 106 additions & 0 deletions ride-share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
drivers_statistics = {
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
}
],
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
}
]
}

total_driver_earnings = []
total_driver_ratings = []
driver_highest_earnings = []
driver_highest_rating = []

drivers_statistics.each do |driver_id, rides|
rides.each do |ride_info|
total_driver_earnings.push(ride_info[:cost])
total_driver_ratings.push(ride_info[:rating])
end

"\nDriver #{driver_id}:"
"\nNumber of rides given - #{drivers_statistics[driver_id].length} rides"
"Total amount of money made - $#{(total_driver_earnings.sum)}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

it looks like you formatted strings, but didn't print or puts them. Was this copied in from a web based tool?

"Average rating - #{'%.2f' % (total_driver_ratings.sum.to_f/total_driver_ratings.length)}"

driver_highest_rating << '%.2f' % ((total_driver_ratings.sum.to_f/total_driver_ratings.length))

driver_highest_earnings.push(total_driver_earnings.sum)

total_driver_earnings.clear
total_driver_ratings.clear
end

"\n~Driver with the highest average rating~"
"Driver DR000#{driver_highest_rating.index(driver_highest_rating.max) + 1} - #{driver_highest_rating.max}"

"\n~Driver with highest earnings~"
"Driver DR000#{driver_highest_earnings.index(driver_highest_earnings.max) + 1}: $#{driver_highest_earnings.max}"