Skip to content

Space - Shonda & Diana#9

Open
dnguye2 wants to merge 15 commits intoAda-C13:masterfrom
dnguye2:master
Open

Space - Shonda & Diana#9
dnguye2 wants to merge 15 commits intoAda-C13:masterfrom
dnguye2:master

Conversation

@dnguye2
Copy link

@dnguye2 dnguye2 commented Feb 28, 2020

Assignment Submission: OO Ride Share

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Question Answer
How did getting up to speed on the existing codebase go? If it went well, what worked? If it didn't go well, what will you do differently next time? The first day, it was very overwhelming to understand what was going on. Using pry helped to understand how the codebase worked. Next time, it would be helpful to look at every file and also examine the tests. This would have expedited understanding of the codebase.
What inheritance relations exist between classes? Within the trip dispatcher, which is the holder, csv_record was the super class of the following sub classes which had inheritance from csv_record: drivers, passengers, and trips.
What composition relations exist between classes? The driver class and the passenger class has a trip.
Describe a decision you had to make when working on this project. What options were you considering? What helped you make your final decision? For the net expenditures method, we had to handle when the @trips array was nil. We were trying to decide to use a nil? which didn't work at first. Then we realized we had use .empty? because nil? refers nothing whereas @trips had an empty array which is not nil. This led us to realize .empty? was the best choice because it covered the case we were looking for.
Give an example of a template method that you implemented for this assignment For the driver class, the template method we created and used was def self.from_csv(record).
Give an example of a nominal test that you wrote for this assignment For the passenger net_expenditures method, we wrote a nominal test for it "returns the correct total amount of money that a passenger has spent"
Give an example of an edge case test that you wrote for this assignment For the driver average_rating we wrote an edge case test for it "returns zero if no driven trips" do and it "returns 0 if trip costs <= $1.65" do
What is a concept that you gained more clarity on as you worked on this assignment We got more clarity on how classes function in relation to each other. And as a whole, object oriented programming and design. In addition, we gained more clarity on handling nil cases.

@kaidamasaki
Copy link

OO Ride Share

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
The code demonstrates individual learning about Time and the responsibility of Trip.from_csv, and uses Time.parse in Trip.from_csv Somewhat.
The code demonstrates breaking out complex logic in helper methods, such as making a helper method in Trip to calculate duration ✔️
There are tests for the nominal cases for the Passenger#net_expenditures and Passenger#total_time_spent ✔️
There is at least one edge case test for either Passenger#net_expenditures or Passenger#total_time_spent testing if the passenger has no trips ✔️
Practices inheritance. Driver inherits from CsvRecord, and implements from_csv ✔️
Employs problem-solving and implements Driver#average_rating and Driver#total_revenue ✔️
Implements the TripDispatcher#request_trip, which creates an instance of Trip with a driver and passenger, adds the new trip to @trips, and changes the status of the driver ✔️
Practices composition. In TripDispatcher#request_trip, the driver gets connected to the new trip, the passenger gets connected to the new trip ✔️
Practices git with at least 10 small commits and meaningful commit messages ✔️

Testing Requirements

Testing Requirement yes/no
There is reasonable test coverage for wave 1, and all wave 1 tests pass ✔️
There is reasonable test coverage for wave 2, and all wave 2 tests pass ✔️
Wave 3: Tests in wave 1 and wave 2 explicitly test that only completed trips should be calculated (and ignore in-progress trips)
There is reasonable test coverage for TripDispatcher#request_trip, and all tests pass ✔️

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 8+ in Code Review && 3+ in Functional Requirements ✔️
Yellow (Approaches Standards) 6+ in Code Review && 2+ in Functional Requirements
Red (Not at Standard) 0-5 in Code Review or 0,1 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation (See comments.)
Elegant/Clever
Descriptive/Readable
Concise
Logical/Organized

Copy link

@kaidamasaki kaidamasaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Here are some tips for how you can clean up your code. 😄

@status = status.to_sym
@trips = trips || []

vin_pattern = /^[A-Z0-9]{17}$/i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular expressions! 🎉


vin_pattern = /^[A-Z0-9]{17}$/i
if (vin_pattern =~ @vin) == nil
raise ArgumentError, "Invalid VIN"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's helpful to include the bad argument in the message for your ArgumentErrors:

Suggested change
raise ArgumentError, "Invalid VIN"
raise ArgumentError, "Invalid VIN: #{@vin}"

@trips << trip
end

def change_status

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name change_status is misleading since it just sets the status to :UNAVAILABLE.

Suggested change
def change_status
def make_unavailable

Comment on lines +46 to +48
else
(trip.rating).to_f
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation:

Suggested change
else
(trip.rating).to_f
end
else
(trip.rating).to_f
end

Comment on lines +52 to +53
cost = ((average_rating).inject(:+))/((average_rating.length) - nil_cases)
return cost

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a lot of extra parenthesis and can directly return the result of this computation, also inject(:+) is the same as sum):

Suggested change
cost = ((average_rating).inject(:+))/((average_rating.length) - nil_cases)
return cost
return average_rating.sum / (average_rating.length - nil_cases)

Remember, . has higher precedence than arithmetic.

Comment on lines +117 to +122
@passenger = RideShare::Passenger.new(
id: 9,
name: "Merl Glover III",
phone_number: "1-602-620-2330 x3723",
trips: []
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation:

Suggested change
@passenger = RideShare::Passenger.new(
id: 9,
name: "Merl Glover III",
phone_number: "1-602-620-2330 x3723",
trips: []
)
@passenger = RideShare::Passenger.new(
id: 9,
name: "Merl Glover III",
phone_number: "1-602-620-2330 x3723",
trips: []
)


# 1.1 #4 instance method of duration of trip
def duration
return (Time.parse(@end_time) - Time.parse(@start_time)).to_i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're already parsing the time in from_csv so this is redundant.

Comment on lines +136 to +137
start_time: "#{Time.now - 60 * 60}",
end_time: "#{Time.now + 60 * 60}",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just pass Time objects into the test.

Suggested change
start_time: "#{Time.now - 60 * 60}",
end_time: "#{Time.now + 60 * 60}",
start_time: Time.now - 60 * 60,
end_time: Time.now + 60 * 60,


# handles case when there are no available drivers
if @drivers.find {|driver| driver.status == :AVAILABLE}.nil?
raise ArgumentError.new("No available drivers.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an issue with the arguments here. You should use a custom error class here.

For example at the top of the file you can define:

  class NoDriverError < StandardError
  end

And then:

Suggested change
raise ArgumentError.new("No available drivers.")
raise NoDriverError.new("No available drivers.")

@driver.change_status

@trip_data = {
id: @trips.last.id + 1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of last here to assign a unique id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants