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
Time - Angela #44
Open
angethuy
wants to merge
1
commit into
Ada-C13:master
Choose a base branch
from
angethuy: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
Time - Angela #44
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,151 @@ | ||
# RIDESHARE | ||
# Calculates statistics of rideshare data. | ||
|
||
drivers = { | ||
DR0001: [ | ||
{ | ||
"3rd Feb 2016": [ | ||
{ | ||
cost: 10, | ||
rider_id: "RD0003", | ||
rating: 3, | ||
}, | ||
{ | ||
cost: 30, | ||
rider_id: "RD0015", | ||
rating: 4, | ||
}, | ||
], | ||
}, | ||
{ | ||
"5th Feb 2016": [ | ||
{ | ||
cost: 45, | ||
rider_id: "RD0003", | ||
rating: 2, | ||
}, | ||
], | ||
}, | ||
], | ||
DR0002: [ | ||
{ | ||
"3rd Feb 2016": [ | ||
{ | ||
cost: 25, | ||
rider_id: "RD0073", | ||
rating: 5, | ||
}, | ||
], | ||
}, | ||
{ | ||
"4th Feb 2016": [ | ||
{ | ||
cost: 15, | ||
rider_id: "RD0013", | ||
rating: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
"5th Feb 2016": [ | ||
{ | ||
cost: 35, | ||
rider_id: "RD0066", | ||
rating: 3, | ||
}, | ||
], | ||
}, | ||
], | ||
DR0003: [ | ||
{ | ||
"4th Feb 2016": [ | ||
{ | ||
cost: 5, | ||
rider_id: "RD0066", | ||
rating: 5, | ||
}, | ||
], | ||
}, | ||
{ | ||
"5th Feb 2016": [ | ||
{ | ||
cost: 50, | ||
rider_id: "RD0003", | ||
rating: 2, | ||
}, | ||
], | ||
}, | ||
], | ||
DR0004: [ | ||
{ | ||
"3rd Feb 2016": [ | ||
{ | ||
cost: 5, | ||
rider_id: "RD0022", | ||
rating: 5 | ||
}, | ||
], | ||
}, | ||
{ | ||
"4th Feb 2016": [ | ||
{ | ||
cost: 10, | ||
rider_id: "RD0022", | ||
rating: 4 | ||
}, | ||
], | ||
}, | ||
{ | ||
"5th Feb 2016": [ | ||
{ | ||
cost: 20, | ||
rider_id: "RD0073", | ||
rating: 5, | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
|
||
highest_earner = { | ||
driver: "", | ||
amount_earned: 0, | ||
} | ||
|
||
highest_rated = { | ||
driver: "", | ||
rating: 0, | ||
} | ||
|
||
puts "STATS PER DRIVER\n**********\n\n" | ||
drivers.each do | driver, workdays | | ||
puts "#{driver} stats:" | ||
|
||
# The number of rides each driver has given | ||
ride_count = workdays.sum { |dates, rides| dates.sum { | date, rides | rides.count } } | ||
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 a block with This is equivalent to doing: ride_count = workdays.map { |dates, rides| dates.sum { | date, rides | rides.count } }.sum |
||
puts "Number of rides given: #{ride_count}" | ||
|
||
# The total amount of money each driver has made | ||
money_earned = workdays.sum { |dates, rides| dates.sum { | date, rides | rides.sum { |ride| ride[:cost] } } } | ||
puts "Total earned: $#{money_earned}" | ||
if money_earned > highest_earner[:amount_earned] | ||
highest_earner[:driver] = driver | ||
highest_earner[:amount_earned] = money_earned | ||
end | ||
|
||
# Average rating | ||
total_ratings = workdays.sum { |dates, rides| dates.sum { | date, rides | rides.sum { |ride| ride[:rating] } } } | ||
average_rating = (total_ratings.to_f/ride_count.to_f).round(2) | ||
puts "Average rating: #{average_rating}" | ||
if average_rating > highest_rated[:rating] | ||
highest_rated[:driver] = driver | ||
highest_rated[:rating] = average_rating | ||
end | ||
puts "\n" | ||
end | ||
|
||
# Which driver made the most money? | ||
puts "\nHighest earner: #{highest_earner[:driver]}" | ||
|
||
# Which driver has the highest average rating? | ||
puts "Highest rated: #{highest_rated[:driver]}" |
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.
One note about a confusing point of Ruby. Even if you use quotes if you use the
"key": value
syntax instead of the"key" => value
the key will wind up a symbol.Note the
:
before the quotes in the output.(Yes, symbols can have spaces, you just need to use quotes after the
:
.)