From 845cb2f5b7fd3703b87926c976cd5e66025b3e2c Mon Sep 17 00:00:00 2001 From: Bailey Stoodley <46545443+BaileyS03@users.noreply.github.com> Date: Fri, 24 May 2024 06:18:09 +0000 Subject: [PATCH 1/7] Fixed output format --- application/app/views/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/app/views/routes.py b/application/app/views/routes.py index f7792e61..9ddc6672 100644 --- a/application/app/views/routes.py +++ b/application/app/views/routes.py @@ -317,7 +317,7 @@ def post(self): trip_query = db.session.execute(db.select(Trip).filter_by(id=contents.get("trip_id"))).scalars().first() if trip_query: ans = [trip.id for trip in trip_query.trip_requests] - return make_response(f"Accepted trip requests are: {ans}", 200) + return make_response({"accepted trips": ans}, 200) else: return make_response(f"This is not a valid trip id.", 400) else: From a3d3b9c63e4f1ec87b0106daf6e64e875932bb39 Mon Sep 17 00:00:00 2001 From: Mohamad Dabboussi <114811082+Mohamad11Dab@users.noreply.github.com> Date: Fri, 24 May 2024 18:34:47 +1000 Subject: [PATCH 2/7] Update temp --- model/adrs/temp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/model/adrs/temp b/model/adrs/temp index 8a81b753..353b8da5 100644 --- a/model/adrs/temp +++ b/model/adrs/temp @@ -221,3 +221,38 @@ Dependence on community support and updates for new features and optimizations. Negative: Potentially higher learning curve for developers not familiar with geospatial databases. Increased complexity in database management due to the advanced features and functions of PostGIS. +------------------------------------------------------------------------------------------------------------------ +Title: Adoption of Self-Hosted Nominatim API for Geocoding +Date: 24/05/2024 +Status: Superseded + +Summary: +This ADR revises our previous decision to use the Nominatim API as an external service by transitioning to a self-hosted solution on an EC2 instance. This shift will provide us with greater control over the geocoding process and data, enhancing our ability to customize and optimize the service for our specific needs in the ride-sharing application. + +Context: +As our application's scale and complexity grow, so does the need for more controlled and reliable geocoding services. Self-hosting allows us to manage the geocoding data directly, offering better customization and potentially improved performance. + +Decision: +We will deploy the Nominatim API on an Amazon EC2 instance to handle our application's geocoding needs. This approach will give us full control over the geocoding process, including data management, updates, and system configuration. + +Rationale for Self-Hosting: +Although previously deemed impractical for a smaller scale project, our evolving requirements and growth prospects justify the investment in self-hosting. The decision is driven by: + +Increased need for customization and control over the geocoding data. +Potential cost savings in the long term with increased usage. +Elimination of reliance on external API's availability and performance constraints. +Consequences: + +Positive: + +Full control over the geocoding process allows for tailored configurations and optimizations. +Direct access to manage and update the data as needed without waiting for third-party updates. +Potentially better performance and reliability by optimizing server resources and configurations. +Neutral: + +Increased initial setup and maintenance efforts required. +Need for in-house expertise to manage and operate the geocoding server effectively. +Negative: + +Higher upfront costs for server setup and ongoing operational expenses. +Increased responsibility for ensuring high availability and data integrity, which could require additional resources and planning. From ed63f648bc4456708f3af97d9ae5fdc6c8856c59 Mon Sep 17 00:00:00 2001 From: Henry Batt <37820016+henrybatt@users.noreply.github.com> Date: Sat, 25 May 2024 04:48:37 +0000 Subject: [PATCH 3/7] Planning for final API push --- application/app/views/routes.py | 22 +++++++++++++++++++++- application/docker-compose.yml | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/application/app/views/routes.py b/application/app/views/routes.py index 9ddc6672..1e3d36b4 100644 --- a/application/app/views/routes.py +++ b/application/app/views/routes.py @@ -360,7 +360,7 @@ def post(self): class Test(Resource): def get(self): - result = distance_query( -123.4194, 37.7749, 90) + result = distance_query(-123.4194, 37.7749, 90) worked = link_trip_request_to_trip("a5cade10-3b8b-4ff2-80db-eab01946e4c8", "735eb991-1c24-4108-896d-0f08c32eb226") worked2 = link_trip_request_to_trip("a5cade10-3b8b-4ff2-80db-eab01946e4c8", "50eb1230-8e50-4ec9-93ac-179121c254a1") @@ -384,4 +384,24 @@ def get(self): api.add_resource(GetNearbyTripRequests, "/trip/get/pending_nearby") api.add_resource(GetApprovedTripRequests, "/trip/get/approved") api.add_resource(ApproveRequest, "/trip/post/approved") + +### trip/get_route_pos +### trip id --> list of lat/long + start time of trip + name of passanger (sort them based on distance chains) + +# { +# "time": start_time, +# "passanger": [ +# { "lat" +# "long" +# "name" +# "pickup or dropoff" +# } +# ,{ + +# } +# ] +# } + +###### + api.add_resource(Test, "/test") diff --git a/application/docker-compose.yml b/application/docker-compose.yml index 50d5c756..7d42e532 100644 --- a/application/docker-compose.yml +++ b/application/docker-compose.yml @@ -29,6 +29,7 @@ services: environment: CELERY_BROKER_URL: redis://redis:6379 SQLALCHEMY_DATABASE_URI: postgresql+psycopg://administrator:verySecretPassword@database:5432/ride + # ROUTING_API_URL: trwst.com command: celery --app tasks.celery_app worker --loglevel=info -Q matching.fifo --uid=nobody --gid=nogroup depends_on: - redis From f8c64bd4873b842bc29bab56fc10f421a7e3e914 Mon Sep 17 00:00:00 2001 From: Bailey Stoodley <46545443+BaileyS03@users.noreply.github.com> Date: Sat, 25 May 2024 05:58:12 +0000 Subject: [PATCH 4/7] Take only x trip requests to user update --- application/app/views/helpers/helpers.py | 5 ++++- application/app/views/routes.py | 2 +- endpoint.http | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/application/app/views/helpers/helpers.py b/application/app/views/helpers/helpers.py index 136c4f80..791bf8b4 100644 --- a/application/app/views/helpers/helpers.py +++ b/application/app/views/helpers/helpers.py @@ -81,7 +81,7 @@ def haversine(lon1, lat1, lon2, lat2): distance = radius_earth_km * c return distance -def distance_query(set_long, set_lat, distance): +def distance_query(set_long, set_lat, distance, offers): nearby_requests = [] ## Only search for PENDING to reduce search space trip_requests = db.session.execute(db.select(TripRequest).filter_by(status='PENDING').order_by(TripRequest.requested_time)).scalars().all() @@ -95,6 +95,9 @@ def distance_query(set_long, set_lat, distance): if abs(dist) <= distance: nearby_requests.append(request) + + if len(nearby_requests) == offers: + break return [trip.to_dict() for trip in trip_requests] diff --git a/application/app/views/routes.py b/application/app/views/routes.py index 1e3d36b4..18eab776 100644 --- a/application/app/views/routes.py +++ b/application/app/views/routes.py @@ -304,7 +304,7 @@ def post(self): else: willing_distance_to_travel = trip.distance_addition / trip.driver.car.max_available_seats - choices = distance_query(start_point.x, start_point.y, willing_distance_to_travel) + choices = distance_query(start_point.x, start_point.y, willing_distance_to_travel, 2 * seats_remaining) return make_response(choices, 200) diff --git a/endpoint.http b/endpoint.http index 371a4431..e57e1f46 100644 --- a/endpoint.http +++ b/endpoint.http @@ -148,7 +148,7 @@ Content-Type: application/json { "username": "jDoe12", "trip_request_id": "0789e17c-0b53-4d1f-ba91-c381b28ef9dd", - "trip_id": "c84fbfc3-3d2f-4f3f-a3ff-15286d31c51c" + "trip_id": "0789e17c-0b53-4d1f-ba91-c381b28ef9dd" } ### GET THE TEST From 39216fd5eb64c72149953d22b7377f4502e4da32 Mon Sep 17 00:00:00 2001 From: Bailey Stoodley <46545443+BaileyS03@users.noreply.github.com> Date: Sat, 25 May 2024 06:00:11 +0000 Subject: [PATCH 5/7] Testing commit --- application/app/views/routes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/app/views/routes.py b/application/app/views/routes.py index 18eab776..997c20ef 100644 --- a/application/app/views/routes.py +++ b/application/app/views/routes.py @@ -304,7 +304,10 @@ def post(self): else: willing_distance_to_travel = trip.distance_addition / trip.driver.car.max_available_seats - choices = distance_query(start_point.x, start_point.y, willing_distance_to_travel, 2 * seats_remaining) + if (seats_remaining): + choices = distance_query(start_point.x, start_point.y, willing_distance_to_travel, (2 * seats_remaining)) + else: + choices = [] return make_response(choices, 200) From 450913aab54e65cfaf368a8932068e7e1d5176fb Mon Sep 17 00:00:00 2001 From: Bailey Stoodley <46545443+BaileyS03@users.noreply.github.com> Date: Sat, 25 May 2024 06:01:26 +0000 Subject: [PATCH 6/7] Testing commit of the only suggesting x trip requests --- application/app/views/helpers/helpers.py | 1 + application/app/views/routes.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/application/app/views/helpers/helpers.py b/application/app/views/helpers/helpers.py index 791bf8b4..39c7c902 100644 --- a/application/app/views/helpers/helpers.py +++ b/application/app/views/helpers/helpers.py @@ -102,6 +102,7 @@ def distance_query(set_long, set_lat, distance, offers): return [trip.to_dict() for trip in trip_requests] + def link_trip_request_to_trip(trip_id: str, trip_request_id: str) -> bool: trip = db.session.execute(db.select(Trip).filter_by(id=trip_id)).scalars().first() trip_req = db.session.execute(db.select(TripRequest).filter_by(id=trip_request_id)).scalars().first() diff --git a/application/app/views/routes.py b/application/app/views/routes.py index 997c20ef..b6c298e9 100644 --- a/application/app/views/routes.py +++ b/application/app/views/routes.py @@ -310,7 +310,6 @@ def post(self): choices = [] return make_response(choices, 200) - class GetApprovedTripRequests(Resource): def post(self): contents = nearby_trip_requests_parser.parse_args() From 1b29537eff67944cc5efd70633133ec8f80625c3 Mon Sep 17 00:00:00 2001 From: Bailey Stoodley <46545443+BaileyS03@users.noreply.github.com> Date: Sun, 26 May 2024 23:18:01 +0000 Subject: [PATCH 7/7] Added new end point --- application/app/views/helpers/helpers.py | 1 - application/app/views/routes.py | 39 ++++++++++++++++++ endpoint.http | 50 ++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/application/app/views/helpers/helpers.py b/application/app/views/helpers/helpers.py index 39c7c902..ca28108e 100644 --- a/application/app/views/helpers/helpers.py +++ b/application/app/views/helpers/helpers.py @@ -88,7 +88,6 @@ def distance_query(set_long, set_lat, distance, offers): for request in trip_requests: start_point = to_shape(request.pickup_location) - end_point = to_shape(request.dropoff_location) # Calculate distance between set point and pickup location of the request dist = haversine(start_point.x, start_point.y, set_long, set_lat) diff --git a/application/app/views/routes.py b/application/app/views/routes.py index b6c298e9..42524cb5 100644 --- a/application/app/views/routes.py +++ b/application/app/views/routes.py @@ -297,6 +297,8 @@ def post(self): return make_response("There is no trip under this ID.", 400) start_point = to_shape(trip.start_location) willing_distance_to_travel = trip.seats_remaining + seats_remaining = trip.seats_remaining + if trip.seats_remaining is not None: if trip.seats_remaining == 0: return make_response([], 200) @@ -372,6 +374,41 @@ def get(self): return make_response("Num trip requests" + str(len(trip.trip_requests)), 205) # return make_response(f"distance = {result}", 200) + +class GetTripPositions(Resource): + def post(self): + contents = nearby_trip_requests_parser.parse_args() + trip = db.session.execute(db.select(Trip).filter_by(id=contents.get("trip_id"))).scalars().first() + if trip is None: + return make_response("There is no trip with this id.", 200) + + start_point = to_shape(trip.start_location) + passengers = trip.trip_requests + # Sort passengers by the Haversine distance from the start point + sorted_passengers = sorted( + passengers, + key=lambda p: haversine( + start_point.x, start_point.y, + to_shape(p.pickup_location).x, to_shape(p.pickup_location).y + ) + ) + + # Construct the response + response = { + "trip_time": trip.start_time, + "passengers": [ + { + "lat": to_shape(p.pickup_location).y, + "long": to_shape(p.pickup_location).x, + "name": p.passenger.user[0].name, + "pickup": p.start_address + } + for p in sorted_passengers + ] + } + + return make_response(response, 200) + ### Resources for methods that have POST and specific get methods ### api.add_resource(Health, "/health") api.add_resource(CreateDriver, "/driver/create") @@ -386,6 +423,8 @@ def get(self): api.add_resource(GetNearbyTripRequests, "/trip/get/pending_nearby") api.add_resource(GetApprovedTripRequests, "/trip/get/approved") api.add_resource(ApproveRequest, "/trip/post/approved") +api.add_resource(GetTripPositions, "/trip/get_route_positions") + ### trip/get_route_pos ### trip id --> list of lat/long + start time of trip + name of passanger (sort them based on distance chains) diff --git a/endpoint.http b/endpoint.http index e57e1f46..29a154f2 100644 --- a/endpoint.http +++ b/endpoint.http @@ -26,6 +26,19 @@ Content-Type: application/json "email": "john.doe1@example.com" } +### Create a passenger for Bailey +POST {{baseUrl}}/passenger/create +Content-Type: application/json + +{ + "username": "Bailey45", + "password": "53%32", + "name": "Bailey Doe", + "phone_number": "47383926", + "email": "Bails.doe1@example.com" +} + + ### Get a user by username POST {{baseUrl}}/profile Content-Type: application/json @@ -106,6 +119,19 @@ Content-Type: application/json "pickup_window_end": "2024-05-10T08:00:00" } +### Add trip request +POST {{baseUrl}}/trip_request/create +Content-Type: application/json + +{ + "username": "Bailey45", + "requested_time": "2024-05-10T08:01:00", + "pickup_location": {"latitude": 37.7749, "longitude": -123.4193, "address": "123 street road, brisbane, qld"}, + "dropoff_location": {"latitude": 37.7749, "longitude": -123.4193, "address": "125 street road, brisbane, qld"}, + "pickup_window_start": "2024-05-10T07:31:00", + "pickup_window_end": "2024-05-10T08:00:00" +} + ### Get all trip requests for a user POST {{baseUrl}}/trip_requests/get/all Content-Type: application/json @@ -114,6 +140,15 @@ Content-Type: application/json "username": "jDoe12" } +### Get all trip requests for a user +POST {{baseUrl}}/trip_requests/get/all +Content-Type: application/json + +{ + "username": "Bailey45" +} + + ### Get all PENDING trip requests for a user POST {{baseUrl}}/trip_requests/get/pending Content-Type: application/json @@ -147,9 +182,18 @@ Content-Type: application/json { "username": "jDoe12", - "trip_request_id": "0789e17c-0b53-4d1f-ba91-c381b28ef9dd", - "trip_id": "0789e17c-0b53-4d1f-ba91-c381b28ef9dd" + "trip_request_id": "e7f8fc4b-8cca-4ca0-97d1-725a4cefe4fd", + "trip_id": "c84fbfc3-3d2f-4f3f-a3ff-15286d31c51c" } ### GET THE TEST -GET {{baseUrl}}/test \ No newline at end of file +GET {{baseUrl}}/test + +### GET NEW END POINT POSITIONING ALONG ROUTES +POST {{baseUrl}}/trip/get_route_positions +Content-Type: application/json + +{ + "trip_id": "c84fbfc3-3d2f-4f3f-a3ff-15286d31c51c", + "username": "jDoe12" +} \ No newline at end of file