forked from AdaGold/oo-ride-share
-
Notifications
You must be signed in to change notification settings - Fork 29
Jessica and Kate - Time #13
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
Catherina87
wants to merge
17
commits into
Ada-C13:master
Choose a base branch
from
Catherina87: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
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8c88f66
Added time.parse to the method and tested it
Catherina87 e2fac08
Added calculate_duration method to the Trip class and test.
Catherina87 661f275
added net_expenditures to Passenger.rb and testing.
Catherina87 21ed897
added total_time_spent method to Passenger.rb and testing.
Catherina87 8033c12
Created class Driver.
Catherina87 74e7ba7
Updated all files to include driver or driver_id.
Catherina87 df6e438
added add_trip to driver.rb
Catherina87 d334974
wrote add_trip method for Driver.rb and connected all trips
Catherina87 7ccc2d6
wrote average_rating method for Driver.rb
Catherina87 01cf637
added total_revenue method to Driver.rb and testing
Catherina87 166a642
Updated Driver class
Catherina87 115eb12
added request_trip method to TripDispatch.rb
Catherina87 7bd3bf8
Added test for valid passenger_id in request_trip.
Catherina87 9e020b1
added more testing (green) for request_trip
Catherina87 76f0f78
more testing for in-progress trips.
Catherina87 c828095
added test for if no available drivers are available
Catherina87 b946ffe
Updated request_trip for wave 4 optional.
Catherina87 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| source 'http://rubygems.org' | ||
|
|
||
| ruby '2.5.5' | ||
| ruby '2.6.5' | ||
|
|
||
| gem 'rake' | ||
|
|
||
|
|
||
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,34 @@ | ||
| GEM | ||
| remote: http://rubygems.org/ | ||
| specs: | ||
| ansi (1.5.0) | ||
| awesome_print (1.8.0) | ||
| builder (3.2.4) | ||
| csv (3.1.2) | ||
| minitest (5.14.0) | ||
| minitest-reporters (1.4.2) | ||
| ansi | ||
| builder | ||
| minitest (>= 5.0) | ||
| ruby-progressbar | ||
| minitest-skip (0.0.1) | ||
| minitest (~> 5.0) | ||
| rake (13.0.1) | ||
| ruby-progressbar (1.10.1) | ||
|
|
||
| PLATFORMS | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| awesome_print | ||
| csv | ||
| minitest | ||
| minitest-reporters | ||
| minitest-skip | ||
| rake | ||
|
|
||
| RUBY VERSION | ||
| ruby 2.6.5p114 | ||
|
|
||
| BUNDLED WITH | ||
| 2.1.4 |
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,82 @@ | ||
| require_relative 'csv_record' | ||
|
|
||
| module RideShare | ||
| class Driver < CsvRecord | ||
|
|
||
| attr_reader :id, :name, :vin, :status, :trips | ||
|
|
||
| def initialize(id:, name:, vin:, status: :AVAILABLE, trips: nil) | ||
| super(id) | ||
|
|
||
| @name = name | ||
| @vin = vin | ||
|
|
||
| if @vin.to_s.length != 17 | ||
| raise ArgumentError.new("Wrong length of vin!") | ||
| end | ||
|
|
||
| @status = status.to_sym | ||
|
|
||
| if ![:AVAILABLE, :UNAVAILABLE].include?@status.upcase.to_sym | ||
| raise ArgumentError.new("Invalid status.") | ||
| end | ||
|
|
||
| @trips = [] || trips | ||
| end | ||
|
|
||
| def self.from_csv(record) | ||
| return new( | ||
| id: record[:id], | ||
| name: record[:name], | ||
| vin: record[:vin], | ||
| status: record[:status] | ||
| ) | ||
| end | ||
|
|
||
| def add_trip(trip) | ||
| @trips << trip | ||
| end | ||
|
|
||
| def average_rating | ||
| sum_of_ratings = 0.0 | ||
| trips_in_progress = 0 | ||
| return 0 if @trips.length == 0 | ||
|
|
||
| @trips.each do |trip| | ||
| if trip.end_time != nil | ||
| sum_of_ratings += trip.rating | ||
| else | ||
| trips_in_progress += 1 | ||
| end | ||
| end | ||
|
|
||
| return (sum_of_ratings / (@trips.length - trips_in_progress)) | ||
| end | ||
|
|
||
| def total_revenue | ||
| return 0.0 if @trips.length == 0 | ||
|
|
||
| sum_of_trip_costs = 0.0 | ||
|
|
||
| @trips.each do |trip| | ||
| if trip.end_time != nil | ||
| if trip.cost < 1.65 | ||
| net_trip = trip.cost | ||
| else | ||
| net_trip = trip.cost - 1.65 | ||
| end | ||
|
|
||
| sum_of_trip_costs += net_trip | ||
| end | ||
| end | ||
|
|
||
| return (sum_of_trip_costs * 0.80) | ||
| end | ||
|
|
||
| def update_status(trip) | ||
| add_trip(trip) | ||
| @status = :UNAVAILABLE | ||
| end | ||
|
|
||
| end | ||
| end |
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
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
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
Oops, something went wrong.
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.
Great use of enumerable method
.sort_by!