forked from AdaGold/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 48
Ride Share App - Nora #38
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
thenora
wants to merge
1
commit into
Ada-C13:master
Choose a base branch
from
thenora: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
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,186 @@ | ||
| ######################################################## | ||
| # Step 1: Establish the layers | ||
|
|
||
| # In this section of the file, as a series of comments, | ||
| # create a list of the layers you identify. | ||
|
|
||
| # DriverID array > Rides array > HASH :Date :Cost :Rider_ID :Rating | ||
|
|
||
| # Drivers [driver_data] - array | ||
| # drives - array | ||
| # hash of ride info (:Date :Cost :Rider_ID :Rating) | ||
|
|
||
| # Which layers are nested in each other? | ||
|
|
||
| # ride data (date/cost/rider/rating) inside of drives inside of drivers | ||
|
|
||
| # Which layers of data "have" within it a different layer? | ||
|
|
||
| # QUESTION how is this question different than above? | ||
|
|
||
| # Which layers are "next" to each other? | ||
|
|
||
| # The ride info is next to each other on the same level | ||
|
|
||
| ######################################################## | ||
| # Step 2: Assign a data structure to each layer | ||
|
|
||
| # Copy your list from above, and in this section | ||
| # determine what data structure each layer should have | ||
|
|
||
| # Drivers [driver_data] - array | ||
| # drives - array | ||
| # hash of ride info (:Date :Cost :Rider_ID :Rating) | ||
|
|
||
| ######################################################## | ||
| # Step 3: Make the data structure! | ||
|
|
||
| # Setup the entire data structure: | ||
| # based off of the notes you have above, create the | ||
| # and manually write in data presented in rides.csv | ||
| # You should be copying and pasting the literal data | ||
| # into this data structure, such as "DR0004" | ||
| # and "3rd Feb 2016" and "RD0022" | ||
|
|
||
| driver_data = { | ||
| 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, | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| # puts "This code is working." | ||
|
|
||
| ######################################################## | ||
| # Step 4: Total Driver's Earnings and Number of Rides | ||
|
|
||
| # Use iteration blocks to print the following answers: | ||
| # - the number of rides each driver has given | ||
|
|
||
| driver_calcs = [] | ||
| driver_data.each do |driver, rides| | ||
| money_earned = 0 | ||
| total_rating = 0.0 | ||
| rides.each do |ride| | ||
| money_earned += ride[:cost] | ||
| total_rating += ride[:rating] | ||
| end | ||
| driver_calcs << { driver_data: driver, num_rides: rides.size, driver_money: money_earned, driver_rating: (total_rating / rides.size) } | ||
| end | ||
|
|
||
| def print_variables(array, variable, descriptor) | ||
| array.each do |key, value| | ||
| puts "- ID #{key[:driver_data]}: #{key[variable]} #{descriptor}" | ||
| end | ||
| end | ||
|
|
||
| puts "How many rides has each driver given?" | ||
| print_variables(driver_calcs, :num_rides, "rides") | ||
|
|
||
| # - the total amount of money each driver has made | ||
|
|
||
| puts "How much total money has each driver earned?" | ||
| print_variables(driver_calcs, :driver_money, "dollars") | ||
|
|
||
| # - the average rating for each driver | ||
|
|
||
| rating_sentences = [] | ||
| puts "What's each driver's average rating?" | ||
| driver_calcs.each do |key, value| | ||
| puts "- The driver with ID #{key[:driver_data]} has an average rating of #{key[:driver_rating].round(1)}." | ||
| end | ||
|
|
||
| # - Which driver made the most money? | ||
| top_money = 0 | ||
| top_money_id = "" | ||
| driver_calcs.each do |key, value| | ||
| if key[:driver_money] > top_money | ||
| top_money_id = key[:driver_data] | ||
| top_money = key[:driver_money] | ||
| end | ||
| end | ||
|
|
||
| puts "The driver with the highest earnings has ID # #{top_money_id}. They earned $#{top_money}." | ||
|
|
||
| # - Which driver has the highest average rating? | ||
|
|
||
| top_rating = 0.0 | ||
| top_rating_id = "" | ||
| driver_calcs.each do |key, value| | ||
| if key[:driver_rating] > top_rating | ||
| top_rating_id = key[:driver_data] | ||
| top_rating = key[:driver_rating] | ||
| end | ||
| end | ||
|
|
||
| puts "The driver with the highest average rating has ID # #{top_rating_id}. They earned #{top_rating.round(1)} stars." | ||
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.
Is there anything you could do to break this sort of loop down using a method?