forked from AdaGold/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 48
time_lola #46
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
ubeninja77
wants to merge
2
commits into
Ada-C13:master
Choose a base branch
from
ubeninja77: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_lola #46
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 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,116 @@ | ||
| Hash.new | ||
| drivers_data = { | ||
| DR0001: [ | ||
| {date: "3rd Feb 2016", | ||
| rider_id: "RD0003", | ||
| cost: 10, | ||
| rating: 3}, | ||
| {date: "3rd Feb 2016", | ||
| rider_id: "RD0015", | ||
| cost: 30, | ||
| rating: 4}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0003", | ||
| cost: 45, | ||
| rating: 1} | ||
| ], | ||
| DR0002: [ | ||
| {date: "3rd Feb 2016", | ||
| rider_id: "RD0073", | ||
| cost: 25, | ||
| rating: 5}, | ||
| {date: "4th Feb 2016", | ||
| rider_id: "RD0013", | ||
| cost: 15, | ||
| rating: 1}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0066", | ||
| cost: 35, | ||
| rating: 3} | ||
| ], | ||
| DR0003: [ | ||
| {date: "4th Feb 2016", | ||
| rider_id: "RD0066", | ||
| cost: 5, | ||
| rating: 5}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0003", | ||
| cost: 50, | ||
| rating: 2} | ||
| ], | ||
| DR0004: [ | ||
| {date: "4th Feb 2016", | ||
| rider_id: "RD0022", | ||
| cost: 5, | ||
| rating: 5}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0022", | ||
| cost: 10, | ||
| rating: 4}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0073", | ||
| cost: 20, | ||
| rating: 5} | ||
| ] | ||
| } | ||
|
|
||
|
|
||
|
|
||
| # 1. The number of rides each driver has given | ||
| drivers_data.each do |driver_id, trips| | ||
| puts "Driver #{driver_id}'s total trips: #{trips.length}" | ||
| end | ||
|
|
||
| # 2. The total amount of money each driver has made | ||
| drivers_data.each do |driver_id, trips| | ||
| total = 0 | ||
| trips.each { |trip| | ||
| total += trip[:cost] | ||
| } | ||
| puts "Driver #{driver_id}'s total earnings: $#{total}" | ||
| # puts "$#{total} and #{driver_id}" | ||
| end | ||
|
|
||
| # 3. The average rating for each driver | ||
| drivers_data.each do |driver_id, trips| | ||
| ratings = 0 | ||
| trips.each { |trip| | ||
| ratings += trip[:rating] | ||
| } | ||
| avg_rating = ratings/trips.length | ||
| puts "Average rating for #{driver_id} is: #{avg_rating}" | ||
| end | ||
|
|
||
| # 4. Which driver made the most money? | ||
| most_earned = 0; | ||
| driver_info = 0; | ||
| drivers_data.each do |driver_id, trips| | ||
| total = 0 | ||
| trips.each { |trip| | ||
| total += trip[:cost] | ||
| } | ||
| if total > most_earned | ||
| most_earned = total; | ||
| driver_info = driver_id; | ||
| end | ||
| end | ||
|
|
||
| puts "#{driver_info} earned the most money, with a total of $#{most_earned}." | ||
|
|
||
| # 5. Calculate and display driver with the highest average rating | ||
| highest_avg_rating = 0; | ||
| driver_info = 0; | ||
| drivers_data.each do |driver_id, trips| | ||
| ratings = 0; | ||
|
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 should also use floating point math here. See above. |
||
| avg_rating = 0; | ||
| trips.each { |trip| | ||
| ratings += trip[:rating] | ||
| } | ||
| avg_rating = ratings/trips.length | ||
| if avg_rating > highest_avg_rating | ||
| highest_avg_rating = avg_rating; | ||
| driver_info = driver_id; | ||
| end | ||
| end | ||
|
|
||
| puts "#{driver_info} was rated the highest, with a average rating of #{highest_avg_rating}." | ||
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,116 @@ | ||
| Hash.new | ||
| drivers_data = { | ||
| DR0001: [ | ||
| {date: "3rd Feb 2016", | ||
| rider_id: "RD0003", | ||
| cost: 10, | ||
| rating: 3}, | ||
| {date: "3rd Feb 2016", | ||
| rider_id: "RD0015", | ||
| cost: 30, | ||
| rating: 4}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0003", | ||
| cost: 45, | ||
| rating: 1} | ||
| ], | ||
| DR0002: [ | ||
| {date: "3rd Feb 2016", | ||
| rider_id: "RD0073", | ||
| cost: 25, | ||
| rating: 5}, | ||
| {date: "4th Feb 2016", | ||
| rider_id: "RD0013", | ||
| cost: 15, | ||
| rating: 1}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0066", | ||
| cost: 35, | ||
| rating: 3} | ||
| ], | ||
| DR0003: [ | ||
| {date: "4th Feb 2016", | ||
| rider_id: "RD0066", | ||
| cost: 5, | ||
| rating: 5}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0003", | ||
| cost: 50, | ||
| rating: 2} | ||
| ], | ||
| DR0004: [ | ||
| {date: "4th Feb 2016", | ||
| rider_id: "RD0022", | ||
| cost: 5, | ||
| rating: 5}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0022", | ||
| cost: 10, | ||
| rating: 4}, | ||
| {date: "5th Feb 2016", | ||
| rider_id: "RD0073", | ||
| cost: 20, | ||
| rating: 5} | ||
| ] | ||
| } | ||
|
|
||
|
|
||
|
|
||
| # 1. The number of rides each driver has given | ||
| drivers_data.each do |driver_id, trips| | ||
| puts "Driver #{driver_id}'s total trips: #{trips.length}" | ||
| end | ||
|
|
||
| # 2. The total amount of money each driver has made | ||
| drivers_data.each do |driver_id, trips| | ||
| total = 0 | ||
| trips.each { |trip| | ||
| total += trip[:cost] | ||
| } | ||
| puts "Driver #{driver_id}'s total earnings: $#{total}" | ||
| # puts "$#{total} and #{driver_id}" | ||
| end | ||
|
|
||
| # 3. The average rating for each driver | ||
| drivers_data.each do |driver_id, trips| | ||
| ratings = 0 | ||
| trips.each { |trip| | ||
| ratings += trip[:rating] | ||
| } | ||
| avg_rating = ratings/trips.length | ||
| puts "Average rating for #{driver_id} is: #{avg_rating}" | ||
| end | ||
|
|
||
| # 4. Which driver made the most money? | ||
| most_earned = 0; | ||
| driver_info = 0; | ||
| drivers_data.each do |driver_id, trips| | ||
| total = 0 | ||
| trips.each { |trip| | ||
| total += trip[:cost] | ||
| } | ||
| if total > most_earned | ||
| most_earned = total; | ||
| driver_info = driver_id; | ||
| end | ||
| end | ||
|
|
||
| puts "#{driver_info} earned the most money, with a total of $#{most_earned}." | ||
|
|
||
| # 5. Calculate and display driver with the highest average rating | ||
| highest_avg_rating = 0; | ||
| driver_info = 0; | ||
| drivers_data.each do |driver_id, trips| | ||
| ratings = 0; | ||
| avg_rating = 0; | ||
| trips.each { |trip| | ||
| ratings += trip[:rating] | ||
| } | ||
| avg_rating = ratings/trips.length | ||
| if avg_rating > highest_avg_rating | ||
| highest_avg_rating = avg_rating; | ||
| driver_info = driver_id; | ||
| end | ||
| end | ||
|
|
||
| puts "#{driver_info} was rated the highest, with a average rating of #{highest_avg_rating}." |
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.
Ratings need to use floating point math since we're planning to get an average and want things like 4.67 as an answer.
Because of the way Ruby converts things if you have one floating point value everything winds up floating point so if you start with
0.0you should get the correct math. (Though note that with floating point math you will want toroundbefore you display things.)