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

Pipes - Sara Frandsen - Ride Share #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
56 changes: 56 additions & 0 deletions ride-share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
driver_id = { # hash
DR0001: [ # key: v(array)
{passenger: "RD0003", date: "02/03/2016", price: 10, rating: 3},
{passenger: "RD0015", date: "02/03/2016", price: 30, rating: 4},
{passenger: "RD0003", date: "02/05/2016", price: 45, rating: 2}
],
DR0002: [
{passenger: "RD0073", date: "02/03/2016", price: 25, rating: 5},
{passenger: "RD0013", date: "02/04/2016", price: 15, rating: 1},
{passenger: "RD0066", date: "02/05/2016", price: 35, rating: 3}
],
DR0003: [
{passenger: "RD0066", date: "02/04/2016", price: 5, rating: 5},
{passenger: "RD0003", date: "02/05/2016", price: 50, rating: 2}
],
DR0004: [
{passenger: "RD0022", date: "02/03/2016", price: 5, rating: 5},
{passenger: "RD0022", date: "02/04/2016", price: 10, rating: 4},
{passenger: "RD0073", date: "02/05/2016", price: 20, rating: 5}
]
}

driver_id.each do | id, driver_record |

total_rides = 0
total_earned = 0
average_rating = 0

puts "Driver #{id}: "
driver_record.each do | record | # is this the best way to dig this deep?
total_rides += 1 # really just the total number of indexes in each array
total_earned += record[:price] # adds total to itself
average_rating += record[:rating] # where the rating TOTAL is stored so it can be divided later
end
# display desired info
puts "Total rides given: #{total_rides}"
puts "Total earned: $#{total_earned}"
puts "Average rating: #{(average_rating.to_f/total_rides).round(1)}/5"
puts
end

# might as well show all the data inputted!
puts "Would you like to view the rest of the data? Y/N"
user_response = gets.chomp.downcase

if user_response == "y"
driver_id.each do | id, driver_record |
puts "Driver #{id}: "
puts
driver_record.each do | record |
puts "#{record[:date]} - Passenger ##{record[:passenger]} - Fare: $#{record[:price]} - Rating: #{record[:rating]}/5"
end
end
else
puts "Ride safely!"
end
49 changes: 45 additions & 4 deletions worksheet.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
########################################################
# Step 1: Establish the layers

# Write a list of the layers here
parent
driver id
passenger, date, price, rating

########################################################
# Step 2: Assign a data structure to each layer

# Copy your list from above, and write what data structure each layer should have
parent - hash
driver id - array
passenger, date, price, rating - hash

########################################################
# Step 3: Make the data structure!

# Setup the data strcture and manually write in data presented in rides.csv
driver_id = {
DR0001: [
{passenger: "RD0003", date: "02/03/2016", price: 10, rating: 3},
{passenger: "RD0015", date: "02/03/2016", price: 30, rating: 4},
{passenger: "RD0003", date: "02/05/2016", price: 45, rating: 2}
],
DR0002: [
{passenger: "RD0073", date: "02/03/2016", price: 25, rating: 5},
{passenger: "RD0013", date: "02/04/2016", price: 15, rating: 1},
{passenger: "RD0066", date: "02/05/2016", price: 35, rating: 3}
],
DR0003: [
{passenger: "RD0066", date: "02/04/2016", price: 5, rating: 5},
{passenger: "RD0003", date: "02/05/2016", price: 50, rating: 2}
],
DR0004: [
{passenger: "RD0022", date: "02/03/2016", price: 5, rating: 5},
{passenger: "RD0022", date: "02/04/2016", price: 10, rating: 4},
{passenger: "RD0073", date: "02/05/2016", price: 20, rating: 5}
]
}

########################################################
# Step 4: Total Divers Earnings and Number of Rides

# Use an iteration block to print driver's total rides and money made
driver_id.each do | id, driver_record |

total_rides = 0
total_earned = 0
average_rating = 0

puts "Driver #{id}: "
driver_record.each do | record |
total_rides += 1
total_earned += record[:price]
average_rating += record[:rating]
end

puts "Total rides given: #{total_rides}"
puts "Total earned: $#{total_earned}"
puts "Average rating: #{(average_rating.to_f/total_rides).round(1)}/5"
puts
end