Git Product home page Git Product logo

elevator's Introduction

Elevators

A backend server for a centralized elevator system.

Build Instructions

Dependencies

This is a packaged program and requires docker and docker-compose to be installed along with access to docker hub to pull images.

Installation

Run the following commands in the directory with Dockerfile to build the server. It may take 3-5 mins on first run. Depending on your operating system you may or may not need to use sudo.

sudo docker compose build

Run the following command to start the server.

sudo docker compose up

Known issue: The first time running sudo docker compose up after build might cause an error in the db connection. Try shutting it down with Ctrl+c, sudo docker compose down and then run sudo docker compose up again. This should work for the time being.

Uninstall

After you are done run the following command to uninstall the built containers

docker compose down

Also check for any unwanted base images and remove them

sudo docker images

sudo docker rmi -f <image-id-here>

API Documentation

In addition to the requested API's, I have added 2 new API's for added functionality. I may have also merged some requested API with similar objectives, while maintaining its intended purpose. Please note, not passing the parameters may result in errors although most cases have validations. Some parameters have hard limits and can be modifed in the constants.py file.

Buildings

The program assumes there are buildings with a set amount of floors and elevators.

http://0.0.0.0:8080/elevator/building/
  • POST Creates a building and it's elevators in the database. It requires the following parameters:

    • name: Name of the building. Duplicates are allowed
    • floors: Number of max floors in the building. Hard limit: 60.
    • elevators: Number of elevators to be created. Hard limit: 10.
  • GET Fetch info about a building and it's elevators.

    • id: Id of the building.

Elevators

Various elevator related operations make use of this api.

http://0.0.0.0:8080/elevator/elevator/
  • POST Adds destination to an elevator. This API assumes the client has pushed the button on a floor, and has a destination floor in mind. When executed, the program will select an appropriate elevator, and that will have assumed to have arrived where the client called, with the clients destination added to its list of destinations. It will need to move using the move api discussed later.

    • building_id: Id of the building at which the client is at.
    • called_at: The floor at which the client is at.
    • dest: The destination floor of the client.
  • GET Fetches the movement status (going up/down or stopped)of an elevator and the next floor it will arrive at.

    • id: The id of the elevator.
  • PUT Updates an elevator's operational status (maintainence/malfunction) and its door (open/closed).

    • id: Id of the elevator
    • operational: (optional) 'yes' or 'no'
    • door: (optional) 'open' or 'close'.

Move

Functionalities for elevator's movement

http://0.0.0.0:8080/elevator/move/
  • POST Moves all the elevators by 1 step in a building.

    • building_id: Id of the building to simulate elevator movement

Elevator Logs

Probably needed a better word, but here logs mean the list of destinations of an elevator.

http://0.0.0.0:8080/elevator/logs/
  • GET Fetches all requests for a give elevator.

    • id: Id of the elevator.

Extras: Introspection

For a closer view of what's happening, open a new window while the server is running.

sudo docker ps

The above command will show two containers running, one of the main django app and the other of postgres. In order to access bash use the following command:

sudo docker exec -it <name-or-id-of-image> bash

In the postgres container use the following to access the database with password postgres:

psql -h db -U postgres

elevator's People

Contributors

farzaanshaikh avatar

Watchers

 avatar

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.