forked from AdaGold/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Leaves -- Janice #33
Open
jaitch
wants to merge
11
commits into
Ada-C12:master
Choose a base branch
from
jaitch: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
Leaves -- Janice #33
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
456f315
Copy code from VS Code
jaitch 532288a
Update worksheet.rb
jaitch b29c441
Answer comprehension questions more thoroughly
janicewhuang fa7d7b5
Delete comprehension questions (realized there's another set)
janicewhuang b00c2c6
Use .map in place of loops to find total made and avg rating
janicewhuang 7c2c3ef
Get code to running state with all questions answered
janicewhuang 7097abb
Add method
janicewhuang 78e8780
With trailing whitespace trimmed
janicewhuang 3af0a87
Make method simpler and clearer
janicewhuang 6e5c839
Change variable names to be more descriptive
janicewhuang cf92207
Added new hash to make things less weird
janicewhuang 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 |
---|---|---|
@@ -1,34 +1,130 @@ | ||
######################################################## | ||
# Step 1: Establish the layers | ||
ride_share = { | ||
DR0001: [ | ||
{ | ||
date: "3rd Feb 2016", | ||
rider: "RD0003", | ||
cost: 10, | ||
rating: 3 | ||
}, | ||
{ | ||
date: "3rd Feb 2016", | ||
rider: "RD0015", | ||
cost: 30, | ||
rating: 4 | ||
}, | ||
{ | ||
date: "5th Feb 2016", | ||
rider: "RD0003", | ||
cost: 45, | ||
rating: 2 | ||
} | ||
], | ||
DR0002: [ | ||
{ | ||
date: "3rd Feb 2016", | ||
rider: "RD0073", | ||
cost: 25, | ||
rating: 5 | ||
}, | ||
{ | ||
date: "4th Feb 2016", | ||
rider: "RD0013", | ||
cost: 15, | ||
rating: 1 | ||
}, | ||
{ | ||
date: "5th Feb 2016", | ||
rider: "RD0066", | ||
cost: 35, | ||
rating: 3 | ||
} | ||
], | ||
DR0003: [ | ||
{ | ||
date: "4th Feb 2016", | ||
rider: "RD0066", | ||
cost: 5, | ||
rating: 5 | ||
}, | ||
{ | ||
date: "5th Feb 2016", | ||
rider: "RD0003", | ||
cost: 50, | ||
rating: 2 | ||
} | ||
], | ||
DR0004: [ | ||
{ | ||
date: "3rd Feb 2016", | ||
rider: "RD0022", | ||
cost: 5, | ||
rating: 5 | ||
}, | ||
{ | ||
date: "4th Feb 2016", | ||
rider: "RD0022", | ||
cost: 10, | ||
rating: 4 | ||
}, | ||
{ | ||
date: "5th Feb 2016", | ||
rider: "RD0073", | ||
cost: 20, | ||
rating: 5 | ||
} | ||
] | ||
} | ||
|
||
# In this section of the file, as a series of comments, | ||
# create a list of the layers you identify. | ||
# Which layers are nested in each other? | ||
# Which layers of data "have" within it a different layer? | ||
# Which layers are "next" to each other? | ||
new_data = Hash.new | ||
|
||
######################################################## | ||
# Step 2: Assign a data structure to each layer | ||
def find_driver_with_max (drivers, criteria) | ||
winner = nil | ||
winning_amount = 0 | ||
drivers.each do |driver, data| | ||
amount = data[criteria] | ||
if amount > winning_amount | ||
winning_amount = amount | ||
winner = driver | ||
end | ||
# This doesn't catch ties! | ||
end | ||
return winner | ||
end | ||
|
||
# Copy your list from above, and in this section | ||
# determine what data structure each layer should have | ||
ride_share.each do |driver, rides| | ||
# Make cost array for calculating amount made by each driver | ||
cost_array = rides.map {|ride| ride[:cost]} | ||
# Make rating array for calculating average rating for each driver | ||
rating_array = rides.map {|ride| ride[:rating]} | ||
average_rating = rating_array.sum / rides.length.to_f | ||
|
||
# Calculate most lucrative day (must combine dates first) | ||
combine_repeat_dates = Hash.new | ||
rides.each do |ride| | ||
if combine_repeat_dates.has_key?(ride[:date]) | ||
combine_repeat_dates[ride[:date]] += (ride[:cost]) | ||
else | ||
combine_repeat_dates[ride[:date]] = (ride[:cost]) | ||
end | ||
end | ||
most_made_in_a_day = combine_repeat_dates.values.max | ||
most_lucrative_date = combine_repeat_dates.key(most_made_in_a_day) | ||
|
||
# Store new data in a hash of hashes | ||
new_data[driver] = { | ||
total_moolah: cost_array.sum, | ||
average_rating: average_rating | ||
} | ||
|
||
# Output info for each driver | ||
puts "Driver #{driver.slice(5)} has given #{rides.length} rides and earned an average rating of #{average_rating}. | ||
They made $#{cost_array.sum} in total. Their most lucrative day was #{most_lucrative_date} on which they made $#{most_made_in_a_day}." | ||
end | ||
|
||
######################################################## | ||
# Step 3: Make the data structure! | ||
# Determine which driver made the most money and which had the highest avg rating | ||
richest_driver = find_driver_with_max(new_data, :total_moolah) | ||
best_driver = find_driver_with_max(new_data, :average_rating) | ||
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 use of helper methods here! |
||
|
||
# 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" | ||
|
||
######################################################## | ||
# Step 4: Total Driver's Earnings and Number of Rides | ||
|
||
# Use an iteration blocks to print the following answers: | ||
# - the number of rides each driver has given | ||
# - the total amount of money each driver has made | ||
# - the average rating for each driver | ||
# - Which driver made the most money? | ||
# - Which driver has the highest average rating? | ||
# Output overall stats info | ||
puts "The driver who made the most money is Driver #{richest_driver.slice(5)}!" | ||
puts "The driver with the highest average rating is Driver #{best_driver.slice(5)}!" |
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.
Moolah, nice!