Giter Site home page Giter Site logo

hungtranphamminh / software_engineering_uwc2.0_project Goto Github PK

View Code? Open in Web Editor NEW

This project forked from duyvt6663/urban-waste-management-system

0.0 0.0 0.0 2.13 MB

Urban waste collection aid

License: MIT License

Shell 0.02% JavaScript 80.89% Python 5.79% CSS 0.15% HTML 0.72% SCSS 12.44%

software_engineering_uwc2.0_project's Introduction

UWC_backend_new

Setup MySQL

Take scripts in the "MySQL Scripts" folder of the repo and run in MySQL workbench/MySQL Shell to create a db, according to the following order:

Schema.sql
Procedure.sql
Trigger.sql
Insert.sql

Setup OSRM

Download Docker.
Download OpenStreetMap extracts for Vietnam from Geofabrik:

wget https://download.geofabrik.de/asia/vietnam-latest.osm.pbf

Pre-process the extract with the car profile and start a routing engine HTTP server on port 5000

Store the file within a local directory "${PWD}" self defined.

docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/vietnam-latest.osm.pbf

The flag -v "${PWD}:/data" creates the directory /data inside the docker container and makes the current working directory "${PWD}" available there. The file /data/vietnam-latest.osm.pbf inside the container is referring to "${PWD}/vietnam-latest.osm.pbf" on the host. The run may take a wild amount of time and possibly return error. Then:

docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/vietnam-latest.osrm
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/vietnam-latest.osrm

Note that vietnam-latest.osrm has a different file extension.

docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/vietnam-latest.osrm

Make requests against the HTTP server to test:

curl "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true"

Setup environment

Clone project from github.
Config manually the DATABASE_CREDENTIALS section in the uwc_backend/settings.py. Change the password to fit your MySQL account.

DATABASE_CREDENTIALS = {
    'user':'root',
    'password':'${YOUR_PASSWORD}',
    'host':'127.0.0.1',
    'database': 'uwc_2.0'
}

create virtual environment

Create new virtualenvironment inside project folder and activate it.

virtualenv env
.\env\scripts\activate

Install all dependencies

pip install -r requirements.txt

Now try to run the local server

python manage.py runserver 

APIs

1. User apis set

all urls in this section begin with http://127.0.0.1:8000/

a. authenticate

accounts/auth/

POST: User provides username and password of a backofficer account stored in the db, not the MySQL account, in request body and receives in turn access token.

accounts/auth/refresh/

POST: Provide refresh token and receive new access token.
Both of the above requests returns the following response payload:

{
    "refresh": "jwt_refresh",
    "access": "jwt_access",
    "user": {
        "user_fields": "values"
    }
}

b. user apis set

***

accounts/employee/

GET: Return all employees working under back officer with request.user['id'].
POSt: User includes these fields in request body: username, password, name, address, gender, phone, email, role, salary, birth,. Example payload:

{
    "username": "____",
    "password": "____",
    "name": "____",
    "address": "____",
    "gender": "male/female",
    "phone": "____",
    "email": "____",
    "role": 1,
    "salary": 6000000,
    "birth": "YYYY-MM-DD",
}

***

accounts/employee/id/

GET: Return an employee detail
PUT: User updates an employee by including these fields in request body: name, address, birth, gender, phone, email, manager_id, vehicle_id, start_date, radius, mcp_id, route_id, is_working, role, salary,. Example payload:

{
    "name": "____",
    "address": "____",
    "birth": "YYYY-MM-DD",
    "gender": "male/female",
    "phone": "____",
    "email": "____",
    "manager_id": null,
    "vehicle_id": 23,
    "startdate": "YYYY-MM-DD",
    "radius": 324,
    "mcp_id": 3,
    "route_id": null,
    "is_working": null,
    "role": 1,
    "salary": 6000000
}

DELETE: Delete an employee data with id.

accounts/employee/id/schedule

POST: User creates a workshift for employee with id by including these fields in request body: start_time, end_time, weekday. Example payload:

{
    "start_time": "12:00:00",
    "end_time": "14:00:00",
    "weekday": "Mon/Tue/Wed/Thur/Fri/Sat/Sun"
}

***

accounts/employee/emp_id/schedule/shift_id

GET: Return a workshift with shift_id of employee emp_id.
DELETE: Delete a workshift with shift_id of employee emp_id.

c. map and route

***

map/

GET: Return all MCPs managed by the backofficer on map and their details.

***

map/route/

GET: Return all current routes in the db, excluding their layout (MCPs).
POST: User provides to request body a list of MCPs, each with these attributes: MCP_id, longtitude, latitude. Example payload:

[
    {
        "MCP_id": 7,
        "longtitude": 106.6662570,
        "latitude": 10.7769350
    },
    {
        "MCP_id": 8,
        "longtitude": 106.6634590,
        "latitude": 10.7828160
    }
]

Server returns MCPs with orders.

***

map/route/id

GET: Return the layout of route with id.
PUT: User provides to request body a list of MCPs specified above with the same payload format. Server update layout of the route with id and returns MCPs with new orders.
DELETE: Delete route with id.

***

map/route/id/optimize

GET: Return the optimized layout of a route that trims off MCPs with less thanf 15% load. Orders also are provided.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.