forked from AdaGold/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Tanja Stroble -- Carets Ride Share #23
Open
misstonbon
wants to merge
2
commits into
Ada-C8:master
Choose a base branch
from
misstonbon:patch-1
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,73 @@ | ||
######################################################## | ||
# Step 1: Establish the layers | ||
|
||
# Write a list of the layers here | ||
# I set up an array named "drivers" | ||
# The indices of drivers array are driver1 - driver4, all hashes containing | ||
# the :keys ride_id, pay, rating,and dates_active. | ||
# corresponding elements were fed into an array, making the | ||
# data structure an array of hashes with arrays as values. | ||
# | ||
######################################################## | ||
# Step 2: Assign a data structure to each layer | ||
# top layer - array (4 elements) | ||
# 2nd layer - hash (4 elements containing inside array of up to 3 elements) | ||
|
||
# Copy your list from above, and write what data structure each layer should have | ||
# top layer - array (4 elements) - should contain hash | ||
# 2nd layer - hash - 4 elements containing a symbol as key and array of up to 3 elements as value) | ||
# values are arrays containing strings and integers. | ||
######################################################## | ||
# Step 3: Make the data structure! | ||
|
||
# Setup the data strcture and manually write in data presented in rides.csv | ||
|
||
######################################################## | ||
# Step 4: Total Divers Earnings and Number of Rides | ||
|
||
# Use an iteration block to print driver's total rides and money made | ||
|
||
|
||
i = 0 | ||
drivers = [ # drivers array | ||
#index 0 of drivers array | ||
driver1 = { | ||
:ride_id => %w(RD0003 RD0015 RD0003), | ||
:rating => [3,4,2], | ||
:pay => [10,30,45], | ||
:dates_active => %w(3rd-Feb-2016 5th-Feb-2016) | ||
}, | ||
# index 1 | ||
driver2 = { | ||
:ride_id => %w(RD0073 RD0013 RD0066), | ||
:rating => [5,1,3], | ||
:pay => [25,15,35], | ||
:dates_active => %w(3rd-Feb-2016 4th-Feb-2016 5th-Feb-2016) | ||
}, | ||
# index 2 | ||
driver3 = { | ||
:ride_id => %w(RD0066 RD0003), | ||
:rating => [5,2], | ||
:pay => [5,50], | ||
:dates_active => %w(4th-Feb-2016 5th-Feb-2016) | ||
}, | ||
# index 3 | ||
driver4 = { | ||
:ride_id => %w(RD0022 RD0022 RD0073), | ||
:rating => [5,4,5], | ||
:pay => [5,10,20], | ||
:dates_active => %w(3rd-Feb-2016 4th-Feb-2016 5th-Feb-2016) | ||
} | ||
] | ||
|
||
puts "Here's the rundown : \n\n" | ||
|
||
#itearate over the array to print pay, number of rides and average rating | ||
|
||
drivers.each do |driver| | ||
i += 1 | ||
puts "Driver#{i} pay: $#{driver[:pay].sum} for #{driver[:ride_id].length} rides." #calculating pay and ride number | ||
puts "Driver#{i}'s average rating is #{(driver[:rating].inject(0.0) { |sum, el| sum + el } / driver[:rating].size).round(2) | ||
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. Nice work using an enumerable ( Also good work using |
||
}.\n\n" # calculating avg rating and rounding to 2 | ||
end | ||
|
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.
You don't need things like this
driver1 = {
here.I also think making these internal hashes containing 3 arrays, rather awkward to traverse. It's also problematic if you accidentally add an element to one array and not the others, they become out of synch.
I would suggest instead doing something like:
That makes it easier to loop through things and keeps trips together logically.