forked from AdaGold/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 48
Space - Katie #39
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
Open
ktvoort123
wants to merge
1
commit into
Ada-C13:master
Choose a base branch
from
ktvoort123:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Space - Katie #39
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # a method to add a driver to the driver hash | ||
| def add_driver_to_hash(ride_hash, drivers_hash) | ||
| drivers_hash[ride_hash[:driver_id]] = { | ||
| num_rides_given: 1, | ||
| total_amt_made: ride_hash[:cost], | ||
| total_of_ratings: ride_hash[:rating] | ||
| } | ||
| end | ||
|
|
||
| # a method to update an existing driver's hash | ||
| def modify_driver_hash(ride_hash, drivers_hash) | ||
| drivers_hash[ride_hash[:driver_id]][:num_rides_given] += 1 | ||
| drivers_hash[ride_hash[:driver_id]][:total_amt_made] += ride_hash[:cost] | ||
| drivers_hash[ride_hash[:driver_id]][:total_of_ratings] += ride_hash[:rating] | ||
| end | ||
|
|
||
| # ride information copied from the rides.csv file, organized as an array of hashes, where each hash represents one ride | ||
| 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 this structure! |
||
| { | ||
| driver_id: "DR0004", | ||
| date: "3rd Feb 2016", | ||
| cost: 5, | ||
| rider_id: "RD0022", | ||
| rating: 5 | ||
| }, | ||
| { | ||
| driver_id: "DR0001", | ||
| date: "3rd Feb 2016", | ||
| cost: 10, | ||
| rider_id: "RD0003", | ||
| rating: 3 | ||
| }, | ||
| { | ||
| driver_id: "DR0002", | ||
| date: "3rd Feb 2016", | ||
| cost: 25, | ||
| rider_id: "RD0073", | ||
| rating: 5 | ||
| }, | ||
| { | ||
| driver_id: "DR0001", | ||
| date: "3rd Feb 2016", | ||
| cost: 30, | ||
| rider_id: "RD0015", | ||
| rating: 4 | ||
| }, | ||
| { | ||
| driver_id: "DR0003", | ||
| date: "4th Feb 2016", | ||
| cost: 5, | ||
| rider_id: "RD0066", | ||
| rating: 5 | ||
| }, | ||
| { | ||
| driver_id: "DR0004", | ||
| date: "4th Feb 2016", | ||
| cost: 10, | ||
| rider_id: "RD0022", | ||
| rating: 4 | ||
| }, | ||
| { | ||
| driver_id: "DR0002", | ||
| date: "4th Feb 2016", | ||
| cost: 15, | ||
| rider_id: "RD0013", | ||
| rating: 1 | ||
| }, | ||
| { | ||
| driver_id: "DR0003", | ||
| date: "5th Feb 2016", | ||
| cost: 50, | ||
| rider_id: "RD0003", | ||
| rating: 2 | ||
| }, | ||
| { | ||
| driver_id: "DR0002", | ||
| date: "5th Feb 2016", | ||
| cost: 35, | ||
| rider_id: "RD0066", | ||
| rating: 3 | ||
| }, | ||
| { | ||
| driver_id: "DR0004", | ||
| date: "5th Feb 2016", | ||
| cost: 20, | ||
| rider_id: "RD0073", | ||
| rating: 5 | ||
| }, | ||
| { | ||
| driver_id: "DR0001", | ||
| date: "5th Feb 2016", | ||
| cost: 45, | ||
| rider_id: "RD0003", | ||
| rating: 2 | ||
| } | ||
| ] | ||
|
|
||
| # initiliaze the new drivers hash where information per driver will be stored | ||
| drivers = {} | ||
|
|
||
| # loop through the rides array of hashes | ||
|
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. Some of these segments could be broken into methods. |
||
| rides.each do |ride| | ||
| if !drivers.keys.include? ride[:driver_id] # if the driver's id does not already exist in the drivers' hash, call the add_driver_to_hash method to add it | ||
| add_driver_to_hash(ride, drivers) | ||
| else # if the driver's id already exists in the drivers' hash, call the modify_driver_hash method to add it | ||
| modify_driver_hash(ride, drivers) | ||
| end | ||
| end | ||
|
|
||
| highest_amt_money_made = 0 # create the variable to store the highest amount of money made and set it to 0 | ||
| driver_with_highest_amt_money = "" # create the variable to store the driver id for the driver who earned the most amount of money | ||
| highest_average_rating = 0 # create the variable to store the highest average rating and set it to 0 | ||
| driver_with_highest_rating = "" # create the variable to store the driver id for the driver who had the highest average rating | ||
|
|
||
| # loop through the drivers hash | ||
| drivers.each do |driver_id, driver_info| | ||
| avg_rating = driver_info[:total_of_ratings].to_f / driver_info[:num_rides_given] # calculate the drivers average rating | ||
| driver_info[:avg_rating] = avg_rating # add the driver's average rating to their hash | ||
| # print driver's information | ||
| puts "Driver #{driver_id} Information: | ||
| Number of rides given: #{driver_info[:num_rides_given]} | ||
| Total amount of money made: $#{driver_info[:total_amt_made]} | ||
| Average rating: #{driver_info[:avg_rating].round(2)} | ||
| ......................." | ||
| # set the highest_amt_money_made variable to the driver's total amt made if it's higher than the current highest_amt_money_made | ||
| if driver_info[:total_amt_made] > highest_amt_money_made | ||
| highest_amt_money_made = driver_info[:total_amt_made] | ||
| driver_with_highest_amt_money = driver_id # also set the driver_with_highest_amt_money variable to the driver's id | ||
| end | ||
| # set the highest_average_rating variable to the driver's average rating if it's higher than the current highest_average_rating | ||
| if driver_info[:avg_rating] > highest_average_rating | ||
| highest_average_rating = driver_info[:avg_rating] | ||
| driver_with_highest_rating = driver_id # also set the driver_with_highest_rating variable to the driver's id | ||
| end | ||
| end | ||
|
|
||
| puts "The driver with the highest amount of money made was #{driver_with_highest_amt_money} who made $#{highest_amt_money_made}." # output driver w/ highest amt money made | ||
| puts "The driver with the highest rating was #{driver_with_highest_rating} with a rating of #{highest_average_rating.round(2)}." # output driver w/ highest avg rating | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So any driver you add this this won't have any rides listed, but will have a cost and total of ratings?