Skip to content
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

Naheed & Dionisia's Ride Share Edges #16

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

larachan15
Copy link

@larachan15 larachan15 commented Sep 1, 2018

OO Ride Share

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer Instructor Feedback
Describe a design decision you had to make when working on this project. What options were you considering? What helped you make your final decision? We realized that sequence mattered for certain tests to pass. For instance in the trip_dispatcher file, we created the load_drivers definition under load_users because it felt logical to group users and drivers in the same area. However, then we had to move @trips below @drivers in the initialize definition because otherwise we had errors in our test code.
Describe any examples of composition that you encountered in this project, if any I think we used composition when we made the module RideShare. By using the module, we were able to call functions in other classes. By composition we mean a has-a or has-many relationship. Examples in this project include "a TripDispatcher has-many Drivers, Passengers and Trips", "a Driver has-many Trips", "a Trip has-a Driver".
Describe the relationship between User and Driver User is the superclass of Driver. Driver inherited the attributes of User, plus had additional one such as driven_trips and status.
Describe a nominal test that you wrote for this assignment. We wrote a test to check if the total costs for all rides per user was calculated correctly.
Describe an edge case test that you wrote for this assignment We wrote a test to check the average rating returned zero if the driven has not driven any trips.
Describe a concept that you/your pair gained more clarity on as you worked on this assignment We started to understand how all the files related to each other better and how to call the methods in each of the classes. Also, we started to understand how the driver file related to users and trips files.
What are two discussion points that you and your pair discussed when giving/receiving feedback from each other that you would be willing to share? We both like giving and receiving upfront feedback from each other. Also, we both had different levels of understanding in this project that helped us each figure out different portions, and then we were able to explain our understanding to the other.

@droberts-sea
Copy link

Ride Share

What We're Looking For

Feature Feedback
Baseline
Used Git Regularly yes
Answer comprehension questions yes - see feedback above
Wave 1
Appropriate use of Ruby's Date yes
Trip has a helper method to calculate duration yes
User (passenger) has a method to calculate total cost of all trips yes
Tests for wave 1 missing some edge cases - see inline
Wave 2
Driver inherits from User yes
Driver has add_driven_trip method yes
Driver has method to calculate average rating yes
Driver has method to calculate net expenditures and it uses super yes
Driver has a method to calculate total revenue yes
Tests for wave 2 yes
Wave 3
TripDispatcher has a new method to create trips yes
creating a trip in TripDispatcher relies on methods in Driver and User (passenger) to modify their own attributes no (driver status is set directly)
Complex logic was correctly implemented yes
Tests for request_trip yes
Methods from wave 1 and 2 handle incomplete trips sort of - see inline
Tests for wave 1 and 2 methods with incomplete trips no
Wave 4 (Optional)
TripDispatcher now assigns trips to either the newest driver (no trips), or the driver who has not driven in the longest time yes
Appropriate helper methods were made to help with complex logic yes
Tests for wave 4 yes - great work!
Overall

Great job overall! I'm very happy with the code you've written, and impressed by your work on the optionals.

At the risk of raining on the parade, I do want to call out that going back and working on previous projects is not always the best use of time, and I hope that you haven't let your Hotel implementations slip in order to put in extra effort here.

There are a few places where things could be cleaned up or where test coverage could be improved that I've tried to call out inline, but this is generally a very solid submission. Keep up the hard work!


def net_expenditures
return super - total_revenue
end

Choose a reason for hiding this comment

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

Good use of super here!

cost_array = []
@trips.each do |trip|
if trip.cost == nil
raise ArgumentError, "Trip is in progress, no cost"

Choose a reason for hiding this comment

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

I don't know that raising an ArgumentError is the right course of action here - you could imagine a user wanting to look up their net expenditures while on a trip, for example. Instead I would probably omit incomplete trips:

trips.each do |trip|
  if trip.cost.nil?
    next
  end
  # ... add to the total ...
end

Or even better, you could write a helper method that returns a list of complete trips:

def completed_trips
  return @trips.reject { |t| t.end_time.nil? }
end

def net_expenditures
  completed_trips.each do |trip|
    # ... same logic as before ...
  end
end

def average_rating
total_ratings = 0
@driven_trips.each do |trip|
total_ratings += trip.rating

Choose a reason for hiding this comment

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

All these driver methods will fail for incomplete trips!

it 'calculates total cost of all rides per user' do
@user.trips.each do |trip|
expect(@user.net_expenditures).must_equal 80
end

Choose a reason for hiding this comment

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

For both of these methods, what if the user has no trips? What if they have an incomplete trip?

it "returns zero if no driven trips" do
driver = RideShare::Driver.new(id: 54, name: "Rogers Bartell IV",
vin: "1C9EVBRM0YBC564DZ")
expect(driver.average_rating).must_equal 0

Choose a reason for hiding this comment

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

Good job catching this edge case.

def assign_driver(passenger_id)
# iterates through the drivers to select and return available drivers and drivers who are not driving themselves
available_drivers = @drivers.select do |driver|
if driver.status == :AVAILABLE && driver.id != passenger_id

Choose a reason for hiding this comment

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

I like that you broke this logic out as a separate method! Good instincts.

available_drivers.each do |driver|
# This assumes that driven_trips are in chronological order
end_time = driver.driven_trips.last.end_time
if end_time < furthest_date

Choose a reason for hiding this comment

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

That might be a big assumption.

# if there is an available driver, changes their status
chosen_driver.status = :UNAVAILABLE
return chosen_driver
end

Choose a reason for hiding this comment

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

Aha, here's where you set the status. I would probably not do this yet - what if something goes wrong in trying to create the trip? Then the driver would be unavailable but not actually have an incomplete trip.

# iterates through the available_drivers to see if there is a driver that has not given any trips.
chosen_driver = available_drivers.find do |driver|
driver.driven_trips.empty?
end

Choose a reason for hiding this comment

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

Good use of enumerables throughout this method!

raise ArgumentError, "Trip still in progress, no revenue"
else
revenue = (trip.cost - 1.65) * 0.8
income += revenue

Choose a reason for hiding this comment

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

This code would be a little more readable if the two magic numbers (0.8 and 1.65) were stored in constants, maybe something like DRIVER_CUT and FEE.

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.

3 participants