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
131 changes: 131 additions & 0 deletions sara_nilsen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
uber_data =
{
"DR0001": [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there a good reason to use a string here rather than a symbol?


{
rider_id: "RD0003",
date_ride: "3rd Feb 2016",
cost: 10,
rating: 3
},
{
rider_id: "RD0015",
date_ride: "3rd Feb 2016",
cost: 30,
rating: 4
},
{
rider_id: "RD0003",
date_ride: "5th Feb 2016",
cost: 45,
rating: 2
}
],

"DR0002": [

{
rider_id: "RD0073",
date_ride: "3rd Feb 2016",
cost: 25,
rating: 5
},
{
rider_id: "RD0013",
date_ride: "4th Feb 2016",
cost: 15,
rating: 1
},
{
rider_id: "RD0066",
date_ride: "5th Feb 2016",
cost: 35,
rating: 3
}
],

"DR0003":
[
{
rider_id: "RD0066",
date_ride: "4th Feb 2016",
cost: 5,
rating: 5
},
{
rider_id: "RD0003",
date_ride: "5th Feb 2016",
cost: 50,
rating: 2
}
],

"DR0004": [
{
rider_id: "RD0022",
date_ride: "3rd Feb 2016",
cost: 5,
rating: 5
},
{
rider_id: "RD0022",
date_ride: "4th Feb 2016",
cost: 10,
rating: 4
},
{
rider_id: "RD0073",
date_ride: "5th Feb 2016",
cost: 20,
rating: 5
}
]
}

def get_total_money(ride_data)
t_money_made = 0
ride_data.each do |info|
t_money_made += info[:cost]
end
return t_money_made
end


def get_rating_average(ride_data)
total_rate = 0.0
rate_info = ride_data.map do |info|
total_rate += info[:rating]
end
return total_rate / rate_info.length
end

puts "Driver amount of rides"
uber_data.each do |driver, info|
puts "Driver #{driver}: #{info.length} rides."
end
puts ""
most_money = 0
driver_most_money = ""
puts "Total amount earned by each driver"
uber_data.each do |driver, info|
total_money = get_total_money(info)
puts "Driver #{driver}: $#{total_money}"
if total_money > most_money
most_money = total_money
driver_most_money = driver
end
end
puts ""
most_average = 0
driver_most_average = ""
Comment on lines +102 to +120

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 would be nice if you broke different sections into chunks using new lines, that way I can read relevant code groupings as a chunk.

uber_data.each do |driver, info|
rating_average = get_rating_average(info)
puts "The average rating of Driver #{driver} %0.2f" %[rating_average]
if rating_average > most_average
most_average = rating_average
driver_most_average = driver
end
end
puts ""
puts "The driver who made the most money: #{driver_most_money}."
puts "The driver with the highest rating #{driver_most_average}."