Skip to content

Commit

Permalink
40 readme (#41)
Browse files Browse the repository at this point in the history
* start on readme

* set default locale for money

* Refactor amount computation to account for only amounts over bonus cliff

* Update readme
  • Loading branch information
mikeheft authored Jul 8, 2024
1 parent 7822f98 commit 684ae93
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 19 deletions.
195 changes: 183 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,195 @@
![alt text](logo_2x.png)
# README

This README would normally document whatever steps are necessary to get the
application up and running.
# RouteRater

Things you may want to cover:
[ApiReview](https://docs.google.com/document/d/1EIruijeCCnIcu7I0AWO1ic397ll4yv2Fh5NWU4cgFlY/edit#heading=h.mqfjv3fbg3fa)

* Ruby version
> In order to attract and retain Care Drivers we need to ensure that they are able to maximize their profits on any given day
* System dependencies
## Prequisites
- `ruby 3.3.0`
- `rails 7.1.3.4`
- `postgres 16.1`

* Configuration
## Usage
### Setup
_Be sure to get the environment variables from Marlene. You will need the `GOOGLE_API_KEY` to geocode the routes_

* Database creation
- Clone repo: `git clone git@github.com:mikeheft/route_rater.git`
- Cd into directory: `cd route_rater`
- Install dependencies: `bundle isntall`
- Setup DataBase: `bundle exec rails db:create db:migrate db:seed`
- Run test suite: `bundle exec rspec`
- Start the app: `./app_start.sh`
- This will start the redis server in daemonize mode, `redis-server --daemonize yes` and then the rails server. The default port is `3000` but you may still configure it as needed with the same option of `-p <PORT NUMBER>`

* Database initialization
## API

* How to run the test suite
The current flow of this application is based on a list of drivers (`/drivers`), where you may see the rides available for a driver to select (`/drivers/:driver_id/selectable_rides`). A ride is deemed selectable when there is no driver attached.

* Services (job queues, cache servers, search engines, etc.)
For the sake of speed the Drivers, Addresses, and Rides are all created via the seeds file. As the parameters of the assignment are to display a list of rides for a given driver we do not have the functionality to create more records, or any additional functionality.

* Deployment instructions
To see the endpoints in action, after starting the rails server with `./app_start.sh`, navigate to `http://localhost:3000/drivers` to view the drivers or `http://localhost:3000/drivers/:driver_id/selectable_rides` to view the ranked rides

* ...
In order to more easily show API pagination, the default pagination params are set to a limit of 2 and offset of 0. To see the next set of records, simply add one to the offset, e.g., `/drivers?limit=2&offset=1`.

### Drivers
This endpoint shows all 'registered' drivers.

```json
// GET /drivers
{
"data": [
{
"id": "21",
"type": "driver",
"attributes": {
"id": 21,
"full_name": "Elina Shields"
},
"relationships": {
"current_address": {
"data": {
"id": "40",
"type": "address"
}
}
}
},
{
"id": "22",
"type": "driver",
"attributes": {
"id": 22,
"full_name": "Tanja Marquardt"
},
"relationships": {
"current_address": {
"data": {
"id": "41",
"type": "address"
}
}
}
}
]
}
```

### Rides
The type for these are defined as `"pre-ride"` as they are what has been 'scheduled' and waiting for a driver to select. My thoughts on this are that once a driver selects a ride, that ride will have all of the corresponding data updated, e.g., duration, distance, commute_duration, driver_id.

The reasoning for this is because the `commute_duration` and `ride duration` are variable depending on the driver looking at the available rides and the durations can change depending on traffic.

The selectable rides are scoped to a pre determined 'radius' that is set on Driver creation. This is outlined in the [ApiReview](https://docs.google.com/document/d/1EIruijeCCnIcu7I0AWO1ic397ll4yv2Fh5NWU4cgFlY/edit#heading=h.mqfjv3fbg3fa).

```json
// GET /drivers/:driver_id/selectable_rides
{
"data": [
{
"id": "81",
"type": "pre-ride",
"attributes": {
"distance": "43 feet",
"duration": "3 minutes",
"commute_duration": "3 minutes",
"ride_earnings": "$12.00"
},
"relationships": {
"from_address": {
"data": {
"id": "46",
"type": "address"
}
},
"to_address": {
"data": {
"id": "51",
"type": "address"
}
}
}
},
{
"id": "60",
"type": "pre-ride",
"attributes": {
"distance": "8.64 miles",
"duration": "14 minutes",
"commute_duration": "1 minute",
"ride_earnings": "$24.95"
},
"relationships": {
"from_address": {
"data": {
"id": "42",
"type": "address"
}
},
"to_address": {
"data": {
"id": "49",
"type": "address"
}
}
}
}
],
"included": [
{
"id": "46",
"type": "address",
"attributes": {
"id": 46,
"line_1": "1024 S Lemay Ave",
"line_2": null,
"city": "Fort Collins",
"state": "Co",
"zip_code": "80524",
"full_address": "1024 S Lemay Ave, Fort Collins, Co, 80524"
}
},
{
"id": "51",
"type": "address",
"attributes": {
"id": 51,
"line_1": "6609 Desert Willow Way",
"line_2": "Unit 1",
"city": "Fort Collins",
"state": "Co",
"zip_code": "80525",
"full_address": "6609 Desert Willow Way, Unit 1, Fort Collins, Co, 80525"
}
},
{
"id": "42",
"type": "address",
"attributes": {
"id": 42,
"line_1": "2315 E Harmony Rd Suite 110",
"line_2": null,
"city": "Fort Collins",
"state": "Co",
"zip_code": "80528",
"full_address": "2315 E Harmony Rd Suite 110, Fort Collins, Co, 80528"
}
},
{
"id": "49",
"type": "address",
"attributes": {
"id": 49,
"line_1": "3397 Wagon Trail Rd",
"line_2": null,
"city": "Fort Collins",
"state": "Co",
"zip_code": "80524",
"full_address": "3397 Wagon Trail Rd, Fort Collins, Co, 80524"
}
}
]
}
```
4 changes: 2 additions & 2 deletions config/initializers/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#
# set to BigDecimal::ROUND_HALF_EVEN by default
#
# config.rounding_mode = BigDecimal::ROUND_HALF_UP
config.rounding_mode = BigDecimal::ROUND_HALF_UP

# Set default money format globally.
# Default value is nil meaning "ignore this option".
Expand All @@ -85,7 +85,7 @@

# If you would like to use I18n localization (formatting depends on the
# locale):
# config.locale_backend = :i18n
config.locale_backend = :i18n
#
# Example (using default localization from rails-i18n):
#
Expand Down
14 changes: 10 additions & 4 deletions lib/rides/commands/compute_amount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ def call(ride:)

private def compute_distance_bonus(distance_meters)
distance_in_miles = convert_distance_to_miles(distance_meters)

amount = distance_in_miles > MILEAGE_BONUS_CLIFF ? MILEAGE_BONUS_AMOUNT * distance_in_miles : 0
amount = if distance_in_miles > MILEAGE_BONUS_CLIFF
MILEAGE_BONUS_AMOUNT * (distance_in_miles - MILEAGE_BONUS_CLIFF)
else
0
end
Money.new(amount)
end

private def compute_duration_bonus(duration)
duration_in_hours = convert_duration_to_hours(duration)

amount = duration_in_hours > DURATION_BONUS_CLIFF ? DURATION_BONUS_AMOUNT * duration_in_hours : 0
amount = if duration_in_hours > DURATION_BONUS_CLIFF
DURATION_BONUS_AMOUNT * (duration_in_hours - DURATION_BONUS_CLIFF)
else
0
end
Money.new(amount)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/rides/commands/compute_amount_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
let(:ride) { OpenStruct.new(duration:, distance_meters:) }
it "computes the amount" do
result = subject
expect(result.format).to eq("$105.46")
expect(result.format).to eq("$97.96")
end
end
end

0 comments on commit 684ae93

Please sign in to comment.