Skip to content

TeamSmil3y/hackaburg_backend

Repository files navigation

api.HubHopper.app

Hackaburg-Project backend

SQL Database

Located in: main/models.py

Tables

User

  • id (uuid)
  • email (string)
  • gender (string["M"/"F"/"D"])
  • adress (string)
  • points (integer)
  • latitude (float)
  • longitude (float)
  • company (foreignKey->Company)

Company

  • id (uuid)
  • name (string)
  • adress (string)
  • hub (foreignKey->Hub)
  • workload (string[comma-seperated integers])

Hub

  • id (uuid)
  • latitude (float)
  • longitude (float)

Ride

  • id (uuid)
  • driver (foreignKey->User)
  • source_hub (foreignKey->Hub))
  • destination_time (datetime)
  • destination_hub (foreignKey->Hub)
  • passengers (m2n through Ride2Passengers)
  • is_full (bool)
  • points (int)

Ride2Passengers

  • ride (foreignKey->Ride)
  • passenger (foreignKey->User)
  • source_hub (foreignKey->Hub)

Dataset // Pseudodata

Located in: main/dataset/...

Data imports

We imported people-with-companies.csv and ratisbona-companies.csv of the given Dataset. The script main/dataset/import_data.py imports these two csv-sheets into the Database.

Pseudodata

Because we needed data about the usual workload of offices/hubs, we created pseudodata for every weekday and every hour for all companies. The data is based on the function

with some additional randomized parameters.

Hub Optimization

Located in: main/dataset/hub_optimizer.py

The very dense located Hubs get clustered by a density-based clustering algorithm (DBSCAN), implemented using scikit-learn. Hubs which distance is below a certain threshold are getting clustered, and all old Hubs get replaced by a new Hub whose coordinates are the mean values of all the old ones per cluster.

Utils

Ride Manager

Located in: main/ride_manager.py

get_ride(id), get_all_rides(), join_ride(ride, user) and get_hub(id) are simple shortcut functions.

find_relevant_rides(source_hub, destination_hub) Where source_hub and destination_hub are objects with the attributes latitude and longitude (float values) (e.g. 2 Hub objects). Relevant rides for a searching user are

  • every ride with the same destination
  • which comes from the same direction
    • The directions are measured in the angle the vectors of the driver to the destination and the passenger to the destination, and it only sees rides as eligible, if the angle i below a certain threshold. The threshold is dependent from the distance between the passenger and the destination, so when its nearer to the destination the angle may be greater, and if the distance is greater, the angle will approach roundabout 45°. The equation is threshold = (180° - 45°)*e^(-dist(passenger; destination)) + 45°

Ride Workload Calc

Located in: main/ride_workload_calc.py

get_hub_workload(hub: Hub, day: int, hour: int) returns Integer [in %], which is the average percentage workload for the given time and weekday. The points have the following constraints:

points ~ 1/workload
points ~ number_passengers

calc_points_warning(ride: Ride) returns two booleans, the first one is if the hub workload is exceptionally high, the second one is if the office workload is exceptionally high.

get_hub_workload(hub: Hub, day: int, hour: int) adds all office workloads of the offices assigned to the hubs and returns the sum as a hub workload.

calc_points(ride: Ride) Returns points as integer,

View Utils

Located in: main/view_utils.py

@http_get_only decorator (UNUSED) Only allow GET-requests

@http_post_only decorator (UNUSED) Only allow POST-requests

@http_post_required_params(params: list) decorator Require all in params listed POST parameters

Routes

Located in: main/routed.py

Using the google Maps Routed API (route matrix computation). The function get_route_duration(origins, destination) returns the duration of the route in seconds, where origins is a list of objects with the attributes latitudeand longitude (e.g. a list of Hubs), and destination is an object with the attributes latitudeand longitude (e.g. a Hub).

Update Manager

Located in: main/update_manager.py

Global events Dictionary

Views // Endpoints

Located in: main/views.py

The Views are django-rest-api Endpoints (function based views).

Endpoint /login/ user_login(request) Authenticate the user.

Endpoint /logout/ user_logout(request) Authenticate the user.

Endpoint /create_ride/ create_ride(request) POST source_hub_id and destination_hub_id to add new ride. RESPONSE: ride_obj[ Obj ], low_points_warning[ Bool ], company_low_points[ Bool ]

Endpoint /cancel_ride/ cancel_ride(request) POST ride_id of the ride to get cancelled.

Endpoint /request_join_ride/ request_join_ride(request) POST ride_id to join the ride. RESPONSE: ride_obj[ Obj ], low_points_warning[ Bool ], company_low_points[ Bool ]

Endpoint /accept_join_ride/ accept_join_request(request) POST ride_id of the joined ride and passenger_id of the joining passenger. RESPONSE: void

Endpoint /finish_ride/ finish_ride(request) POST ride_id; will calculate and book the points RESPONSE: void

Endpoint /find_rides/ find_rides(request) POST source_id_hub and destination_hub_id to find relevant rides using the `find_relevant_rides(source_hub, destination_hub) Util to find relevant rides. RESPONSE: rides

Endpoint /update/ update(request) GET RESPONSE: update (see Update Manager)

Endpoint /get_hubs/ get_hubs() GET RESPONSE hubs (list of objects)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published