-
Notifications
You must be signed in to change notification settings - Fork 48
Space - Yieni #28
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
base: master
Are you sure you want to change the base?
Space - Yieni #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,253 @@ | ||||||
| ride_share_trips = [ | ||||||
| { | ||||||
| 'DR001' => [ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use symbols as keys
Suggested change
|
||||||
| { | ||||||
| date: '3rd_Feb_2016', | ||||||
| cost: 10.00, | ||||||
| rider: 'RD0003', | ||||||
| rating: 3.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '3rd_Feb_2016', | ||||||
| cost: 30.00, | ||||||
| rider: 'RD0015', | ||||||
| rating: 4.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '5th_Feb_2016', | ||||||
| cost: 45.00, | ||||||
| rider: 'RD0003', | ||||||
| rating: 2.0 | ||||||
| } | ||||||
| ], | ||||||
| 'DR002' => [ | ||||||
| { | ||||||
| date: '3rd_Feb_2016', | ||||||
| cost: 25.00, | ||||||
| rider: 'RD0073', | ||||||
| rating: 5.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '4th_Feb_2016', | ||||||
| cost: 15.00, | ||||||
| rider: 'RD0013', | ||||||
| rating: 1.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '5th_Feb_2016', | ||||||
| cost: 35.00, | ||||||
| rider: 'RD0066', | ||||||
| rating: 3.0 | ||||||
| }, | ||||||
| ], | ||||||
| 'DR003' => [ | ||||||
| { | ||||||
| date: '4th_Feb_2016', | ||||||
| cost: 5.00, | ||||||
| rider: 'RD0066', | ||||||
| rating: 5.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '5th_Feb_2016', | ||||||
| cost: 50.00, | ||||||
| rider: 'RD0003', | ||||||
| rating: 2.0 | ||||||
| } | ||||||
| ], | ||||||
| 'DR004' => [ | ||||||
| { | ||||||
| date: '3rd_Feb_2016', | ||||||
| cost: 5.00, | ||||||
| rider: 'RD0022', | ||||||
| rating: 5.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '4th_Feb_2016', | ||||||
| cost: 10.00, | ||||||
| rider: 'RD0022', | ||||||
| rating: 4.0 | ||||||
| }, | ||||||
| { | ||||||
| date: '5th_Feb_2016', | ||||||
| cost: 20.00, | ||||||
| rider: 'RD0073', | ||||||
| rating: 5.0 | ||||||
| } | ||||||
| ] | ||||||
|
|
||||||
| } | ||||||
| ] | ||||||
|
|
||||||
| #prints to terminal the number of rides each driver has given | ||||||
| puts "---------------------------------------------------" | ||||||
| puts "How many trips did each driver make?" | ||||||
| puts "\n" | ||||||
|
|
||||||
| def driver_trips(ride_share_rides) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the methods here, but I suggest putting the method bodies/definitions at the top of the file and the main program code below, so the method bodies don't break up the flow of the program. Let me know if this is unclear. |
||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.each do |driver, trips| | ||||||
| puts "Driver #{driver} made a total of #{trips.count} trips." | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| driver_trips(ride_share_trips) | ||||||
|
|
||||||
| puts "---------------------------------------------------" | ||||||
|
|
||||||
| #prints in terminal the total amount of money each driver made | ||||||
| puts "How much money did each driver make?" | ||||||
| puts "\n" | ||||||
|
|
||||||
| def driver_pay(ride_share_rides) | ||||||
| pay_hash = Hash.new(0) | ||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.each do |driver, trips| | ||||||
| pay_hash[driver] = 0 | ||||||
| trips.each do |info| | ||||||
| pay_hash[driver] += info[:cost] | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
| return pay_hash | ||||||
| end | ||||||
|
|
||||||
| driver_pay(ride_share_trips).each do |driver, pay| | ||||||
| puts "Driver #{driver} made a total of $#{pay}." | ||||||
| end | ||||||
|
|
||||||
| puts "---------------------------------------------------" | ||||||
|
|
||||||
| #prints in terminal average driver rating | ||||||
|
|
||||||
| puts "What are the average ratings for the drivers?" | ||||||
| puts "\n" | ||||||
|
|
||||||
| def driver_rating(ride_share_rides) | ||||||
| rating_hash = Hash.new(0) | ||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.each do |driver, trips| | ||||||
| rating_hash[driver] = 0 | ||||||
| trips.each do |info| | ||||||
| average_rating = (info[:rating]/trips.count).round(2) #there seems to be some float math happening when I don't round | ||||||
| rating_hash[driver] += average_rating | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
| return rating_hash | ||||||
| end | ||||||
|
|
||||||
| driver_rating(ride_share_trips).each do |driver, rating| | ||||||
| puts "Driver #{driver} has an average rating of #{rating} stars." | ||||||
| end | ||||||
|
|
||||||
| puts "---------------------------------------------------" | ||||||
|
|
||||||
| #prints in terminal which driver made the most money | ||||||
|
|
||||||
| puts "Which driver made the most money?" | ||||||
| puts "\n" | ||||||
| highest_pay = driver_pay(ride_share_trips).values.max | ||||||
| puts "Driver" + " " + driver_pay(ride_share_trips).key(highest_pay) + " " + "made the most money with $#{highest_pay}." | ||||||
|
|
||||||
| puts "---------------------------------------------------" | ||||||
| #prints in terminal which driver had highest average rating | ||||||
|
|
||||||
| puts "Which driver had the highest rating?" | ||||||
| puts "\n" | ||||||
| highest_rating = driver_rating(ride_share_trips).values.max | ||||||
| puts "Driver" + " " + driver_rating(ride_share_trips).key(highest_rating) + " " + "had the highest rating, with a rating of #{highest_rating} stars." | ||||||
|
|
||||||
| puts "---------------------------------------------------" | ||||||
| #print in terminal which day did each driver make the most money | ||||||
| # I tried multiple ways of looping through to get the driver info into one method but each driver's array kept getting cahnged with each loop. | ||||||
|
|
||||||
|
|
||||||
| def driver1_pay_day(ride_share_rides) | ||||||
| pay_hash = Hash.new(0) | ||||||
| day_hash = Hash.new(0) | ||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.values[0].each do |x| | ||||||
| day_hash[x[:date]] += x[:cost] | ||||||
| pay_hash[trip_info.keys[0]] = day_hash | ||||||
| end | ||||||
| end | ||||||
| return pay_hash | ||||||
| end | ||||||
|
|
||||||
| driver =" " | ||||||
| driver1_pay_day(ride_share_trips).keys.each do |key| | ||||||
| driver = key | ||||||
| end | ||||||
|
|
||||||
| highest_pay_day = driver1_pay_day(ride_share_trips).values[0].values.max | ||||||
| date_highest_pay = driver1_pay_day(ride_share_trips).values[0].key(driver1_pay_day(ride_share_trips).values[0].values.max) #for some reason when I put in the variable highest_pay in the keys, it doesn't pull up the key. Only the long hand does | ||||||
|
|
||||||
| puts "Driver #{driver} had the highest pay on #{date_highest_pay}, with a total of $#{highest_pay_day}." | ||||||
|
|
||||||
|
|
||||||
| def driver2_pay_day(ride_share_rides) | ||||||
| pay_hash = Hash.new(0) | ||||||
| day_hash = Hash.new(0) | ||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.values[1].each do |x| | ||||||
| day_hash[x[:date]] += x[:cost] | ||||||
| pay_hash[trip_info.keys[1]] = day_hash | ||||||
| end | ||||||
| end | ||||||
| return pay_hash | ||||||
| end | ||||||
|
|
||||||
| driver =" " | ||||||
| driver2_pay_day(ride_share_trips).keys.each do |key| | ||||||
| driver = key | ||||||
| end | ||||||
|
|
||||||
| highest_pay_day = driver2_pay_day(ride_share_trips).values[0].values.max | ||||||
| date_highest_pay = driver2_pay_day(ride_share_trips).values[0].key(driver2_pay_day(ride_share_trips).values[0].values.max) | ||||||
|
|
||||||
| puts "Driver #{driver} had the highest pay on #{date_highest_pay}, with a total of $#{highest_pay_day}." | ||||||
|
|
||||||
| def driver3_pay_day(ride_share_rides) | ||||||
| pay_hash = Hash.new(0) | ||||||
| day_hash = Hash.new(0) | ||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.values[2].each do |x| | ||||||
| day_hash[x[:date]] += x[:cost] | ||||||
| pay_hash[trip_info.keys[2]] = day_hash | ||||||
| end | ||||||
| end | ||||||
| return pay_hash | ||||||
| end | ||||||
|
|
||||||
| driver =" " | ||||||
| driver3_pay_day(ride_share_trips).keys.each do |key| | ||||||
| driver = key | ||||||
| end | ||||||
|
|
||||||
| highest_pay_day = driver3_pay_day(ride_share_trips).values[0].values.max | ||||||
| date_highest_pay = driver3_pay_day(ride_share_trips).values[0].key(driver3_pay_day(ride_share_trips).values[0].values.max) #for some reason when I put in the variable highest_pay in the keys, it doesn't pull up the key. Only the long hand does | ||||||
|
|
||||||
| puts "Driver #{driver} had the highest pay on #{date_highest_pay}, with a total of $#{highest_pay_day}." | ||||||
|
|
||||||
| def driver4_pay_day(ride_share_rides) | ||||||
| pay_hash = Hash.new(0) | ||||||
| day_hash = Hash.new(0) | ||||||
| ride_share_rides.each do |trip_info| | ||||||
| trip_info.values[3].each do |x| | ||||||
| day_hash[x[:date]] += x[:cost] | ||||||
| pay_hash[trip_info.keys[3]] = day_hash | ||||||
| end | ||||||
| end | ||||||
| return pay_hash | ||||||
| end | ||||||
|
|
||||||
| driver =" " | ||||||
| driver4_pay_day(ride_share_trips).keys.each do |key| | ||||||
| driver = key | ||||||
| end | ||||||
|
|
||||||
| highest_pay_day = driver4_pay_day(ride_share_trips).values[0].values.max | ||||||
| date_highest_pay = driver4_pay_day(ride_share_trips).values[0].key(driver4_pay_day(ride_share_trips).values[0].values.max) #for some reason when I put in the variable highest_pay in the keys, it doesn't pull up the key. Only the long hand does | ||||||
|
|
||||||
| puts "Driver #{driver} had the highest pay on #{date_highest_pay}, with a total of $#{highest_pay_day}." | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suggest setting your default indentation to 2 spaces.