forked from AdaGold/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Space - Faezeh #33
Open
faezeh-ashtiani
wants to merge
1
commit into
Ada-C13:master
Choose a base branch
from
faezeh-ashtiani: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 - Faezeh #33
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 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,103 @@ | ||
# 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" | ||
|
||
# the dates needed a bit of tweeking to be apropriately ordinalized. | ||
|
||
# based on layering (nesting) method 3: | ||
all_rides = { | ||
: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} | ||
] | ||
} | ||
|
||
######################################################## | ||
# Step 4: Total Driver's Earnings and Number of Rides | ||
|
||
rides_num = {} | ||
all_rides.each do |driver, rides| | ||
rides_num[driver] = rides.length | ||
end | ||
|
||
driver_total_income = {} | ||
all_rides.each do |driver, rides| | ||
driver_income = rides.map do |each_ride| | ||
each_ride [:COST] | ||
end | ||
driver_total_income[driver] = driver_income.sum | ||
end | ||
|
||
driver_average_rating = {} | ||
all_rides.each do |driver, rides| | ||
driver_rating = rides.map do |each_ride| | ||
each_ride[:RATING].to_f | ||
end | ||
driver_average_rating[driver] = ( driver_rating.sum / rides.length ).round(2) | ||
end | ||
Comment on lines
+38
to
+57
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 iterate over |
||
# I had found #.round(2) on stackoverflow.com when I was researching for the technical challenge part of the application. | ||
|
||
# Use an iteration blocks to print the following answers: | ||
puts "Faezeh's Ride Share Report:" | ||
puts "" | ||
|
||
# The number of rides each driver has given: | ||
puts "The number of rides each driver has given:" | ||
rides_num.each do |driver, rides| | ||
puts "Driver #{driver[-1]} has given #{rides} rides." | ||
end | ||
puts "" | ||
|
||
# The total amount of money each driver has made: | ||
puts "The total amount of money each driver has made:" | ||
driver_total_income.each do |driver, money| | ||
puts "Driver #{driver[-1]} has made $#{money}." | ||
end | ||
puts "" | ||
|
||
# - the average rating for each driver | ||
puts "The average rating for each driver:" | ||
driver_average_rating.each do |driver, rating| | ||
puts "The average rating for driver #{driver[-1]} is #{rating} " | ||
end | ||
puts "" | ||
|
||
# - Which driver made the most money? | ||
puts "Which driver made the most money?" | ||
puts "Driver #{driver_total_income.key(driver_total_income.values.max)[-1]} has made the most money which is $#{driver_total_income.values.max}." | ||
puts "" | ||
|
||
# - Which driver has the highest average rating? | ||
puts "Which driver has the highest average rating?" | ||
puts "Driver #{driver_average_rating.key(driver_average_rating.values.max)[-1]} has the highest average rating which is #{driver_average_rating.values.max}." | ||
puts "" | ||
|
||
# Optionally, print in the terminal: | ||
puts "For each driver, on which day did they make the most money?" | ||
|
||
all_rides.each do |driver, rides| | ||
driver_income = rides.map do |each_ride| | ||
each_ride [:COST] | ||
end | ||
puts "Driver #{driver[-1]}'s highest paying ride was on #{rides[driver_income.rindex(driver_income.max)][:DATE]}." | ||
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.
Don't forget, when you use symbols as a hash key, you can write lines like this as
DR0001: [