Giter VIP home page Giter VIP logo

closest-points's Introduction

Closest Points

Django application with an API that receives a set of points on a grid as semicolon separated values. And then it finds the points that are closest to each other. Store the received set of points and the closest points on a DB.

How To Run The Project

This assumes that you are running on any *nix environment and have Python 3.10+ and git installed in your local machine.

  1. Clone the repository
$ git clone [email protected]:ageeknamedslickback/closest-points.git
$ cd closest-points
  1. Create and activate a virtual environment to run your code
$ python3 -m venv <name of your venv>
$ source <name of your venv>/bin/activate
  1. Install dependancies
$ pip3 install -r requirements.txt
  1. Create an env.sh file and add the following
export SECRET_KEY="<your secret key>"
export DEBUG="true"
  1. Remeber to source your environment variables
$ source env.sh
  1. Run migrations (code uses SQLite thus no further configs) and the server
$ python3 manage.py migrate
$ python3 manage.py runserver

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
May 18, 2023 - 21:47:51
Django version 4.2.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

How To Test The Project

$ tox -r

Calculate Closest Points API

Create

Create
Path Method Description
/api/v1/closest-points POST Calculates and store a set of points and the closest points in the set

Payload

{
    "points_set": "2,2;-1,30;20,11;4,5"
}

Response (Status: 201)

{
    "points_set": "2,2;-1,30;20,11;4,5",
    "closest_points": "2,2;4,5"
}

Example

curl --location 'http://127.0.0.1:8000/api/v1/closest-points/' \
--header 'Content-Type: application/json' \
--data '{
    "points_set": "2,3;4,5;6,7"
}'

List

List
Path Method Description
/api/v1/closest-points GET Gets all the stored point sets and their closes points

Response (Status: 200)

[
    {
        "points_set": "2,2;-1,30;20,11;4,5",
        "closest_points": "2,2;4,5"
    }
]

Example

curl --location 'http://127.0.0.1:8000/api/v1/closest-points/' \
--header 'Content-Type: application/json'

Admin

You have the ability to see the data in the database using Django's Admin interface.

  1. Create a super user
$ python3 manage.py createsuperuser

Username (leave blank to use 'dumbledore'): stewie
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.
  1. Visit the admin page /admin and login using the above created credentials

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.