Giter Club home page Giter Club logo

zbce_api's Introduction

ZBCE API

Code style: black

This is a proof-of-concept API repository that allows users to store waste related metrics such as bin fullness, waste weight, bin usage, and waste images. Thank you to everyone who contributed! πŸ™Œ

GitHub Contributors Image

πŸ“” Table of Contents

Table of contents generated with markdown-toc

πŸ“° Deployment

If you have the Prerequisites listed below you can fully deploy this project. Since we use an ORM (Object-relational Mapping), you can use different SQL databases such as PostgreSQL or MySQL. If you only wish to just work on a development version, please refer to the Development section below.

Prerequisites

Deployment Guides

If you're ready to deploy please follow this deployment guide.

The deployment guide has instructions for the following:

  • Self-Hosted LAMP (Linux, Apache, MySQL, Python)
  • Self-Hosted LUMP (Linux, Uvicorn, PostgreSQL, Python)
  • PythonAnywhere Deployment

πŸ”¨ Development

This section is for setting up the development environment only, which takes less steps and does not require Ubuntu. However, development should not be used in a production environment. For a more deployed solution, please refer to the Deployment section above.

This is the basic outline for setting up your development environment:

  1. Cloning Repo in Workspace
  2. Setting up Python
  3. Installing MySQL
  4. Creating a '.env' file
  5. Creating Tables in Database
  6. Running the Server

Cloning ZBCE Repository

Following the instructions listed, you will be able to clone the ZBCE Repository; however, if you would like a more thorough guide/step-by-step, visit the GitHub Docs guide for cloning a repository: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository.

  1. Open an empty folder (or the folder you would like to clone the repo into) and navigate to that folder using a terminal
  2. In your terminal, type in git clone add a space then paste https://github.com/zotbins/zbce_api.git (Note: you can also find the repo's HTTP URL yourself by clicking the green "Code" button on the top right corner of the ZBCE repo)
  3. Run the command

After these steps, you should be able to access the ZBCE repo from your computer.

Setting up Python

  1. Download the appropriate Python version for your OS from https://www.python.org/downloads/
  2. Unzip the python file and follow the Python's setup instructions given

Once Python is downloaded on your device, you will need to create a virtual environment. For a more in depth explanation of creating a virtual Python environment, visit https://docs.python.org/3/tutorial/venv.html

  1. In your terminal type and run python3 -m venv venv
  2. Activate the virtual environment For Windows type and run venv\Scripts\activate.bat For MacOS or Linux type and run source venv/bin/activate
  3. Install packages within the virtual environment with pip install -r requirements.txt

Installing MySQL

  1. Download the MySQL workbench and server DB for your OS using https://dev.mysql.com/downloads/workbench/
  2. Unzip the msi files and follow the setup instructions as given

Once MySQL is installed (workbench and server), you will have to connect to the ZBCE Database.

  1. Open MySQL and β€˜Start MySQL Server’
  2. Open MySQLWorkbench
  3. Create a new MySQL Connection Connection Name: zotbinsCE Hostname: 127.0.0.1 Port: 3306 Username: root Hit ok and connect to this server
  4. Create a new SQL tab:
  5. Run this query once to create the database (click on lightning bolt to run): CREATE DATABASE zotbinsCE;

Creating a '.env' file

  1. Create an .env file in the same directory
  2. Input this into the .env file and change the parameters to match your username and password
    # change this to specify your MySQL Database
    SQLALCHEMY_DATABASE_URI=mysql+pymysql://YOUR_MYSQL_USERNAME_HERE:YOUR_MYSQL_PASSWORD_HERE@localhost/zotbinsCE
    
    # this will be used for your flask app, change the following to a secure secret key
    SECRET_KEY=YOUR_HARD_TO_GUESSS_STRING
    
    # change this to specify where you want the image files to be uploaded to
    # for your upload folder make sure you change the permissions so anyone can modify it using `chmod 777`
    UPLOAD_FOLDER=YOUR_UPLOAD_FOLDER_PATH
    
    # this is the base url used for the unit tests
    BASE_URL="http://127.0.0.1" # replace with your server name
  3. Save your changes

Creating Tables in Database

  1. Create the tables in your database by running python create_tables.py
  2. If set up successfully, you should see new tables added in mySQL Workbench

Running the Server

  1. Type and run python app.py into your terminal
  2. Check where to access your API by looking at β€œRunning on” section on the command line
  3. Use Postman for further tests if desired

Congratulations you successfully set up your development environment! πŸ₯³

πŸ“š Database Interface Tool

The database interface tool is the python file called db_interface_tool.py that lets users interact with a simple command line interface to drop and recreate tables. It also lets users add bins to the Bin Info table in the database as seen in the database schema image below.

Database Schema

Run the script to use the tool:

# You need to make sure that either your development or deployment environment is already setup
# make sure you activate your virtual environment first
source venv/bin/activate

# run script
python db_interface_tool.py

🀝 Contributing

Here are some following ways you can contribute:

  • Make a pull request!
  • Join our Discord server and contribute to our growing community
  • Submit bugs by opening an issue on our Github. Please make sure that bugs are reported in detail and is reproducible.
  • Write some documentation for a repository and we can add it to our GitHub Wiki Page
  • Look for open issues on our repositories
  • Suggest new features in our Discord Server
  • Contribute to our crowd-sourcing projects. Occasionally, we will have certain projects that require crowd-sourced data, and would love people to help.
  • Submit user feedback through feedback forms or polls in our Discord community
  • Lookout for more requests for help on our Discord server

zbce_api's People

Contributors

okyang avatar patrickanguyen avatar aishwaryabh avatar gracechoe avatar jyue86 avatar

Stargazers

 avatar  avatar

Watchers

Primal Pappachan avatar James Cloos avatar  avatar

Forkers

patrickanguyen

zbce_api's Issues

Deprecate zbce_api Repo and Transition to Adafruit.io

This project was just a proof of concept repository. We want to transition to a using an MQTT broker. There were multiple options, but we found if we wanted this waste management concept to be easily adopted Adafruit.io seems to be a good option. Though there are still some downsides with Adafruit.io, it is still simple enough to quickly implement this solution.

GET API Usage Count w/ Start Timestamp & End TimeStamp & Duration

Issuehunt badges

Request the number of times a bin when used per time duration (hour, half hour, day), etc.

For example, a developer may want to request the number times a bin was used every hour. The response for this GET request would return a JSON object with one column for timestamps representing each hour and a second column for the number of times the bin was used.

Hour Usage
YYYY-MM-DD HH:00:00 5
YYYY-MM-DD HH:00:00 5
YYYY-MM-DD HH:00:00 5

IssueHunt Summary

Backers (Total: $0.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips

Improve Documentation ZBCE API

Setup instructions on how to set up the development environment

  • Use the onboarding guide as a reference.

Update API documentation

You can roughly use this as an example

Make sure every endpoint has these fields:

  • Description of endpoint
GET /weight/ gets the weight sensor data between the start and end timestamps
  • Parameters with a description and example
Parameter Description Example
bin_id Unique ID of bin ZBin1
  • Response Code (All possible HTTP status codes and what they mean)
POST /weight/
Code Description
201 - Weight data was successfully added 
400 - Invalid bin_id 
  • Example Responses based on HTTP status codes

Example:
200 Successful Response

[
{
"weight": 1923, 
"blah": "blah"
}
]

400 Bad Request

{
"message": "salkdjfklsf"
}

API Requirements Analysis

Brainstorming what specific APIs could be created to provide useful data analytics. This will be the start of the discussion thread.

Add barcode endpoints

Web & Mobile requested an endpoint where they can input a barcode and it will return the name of the product and the bin where it belongs. We have been provided an XLSX file of over 12,000 different barcodes, so it will probably be smart to make some sort of Python script to add all of the barcodes to our database.

Endpoint: GET /barcode/{barcode}

HTTP Status Code: 200
Barcode is in the database and is successfully found

{
  "barcode" : 647669926366,
  "item_info" : "1016038 - BISCOTTI CHOCOLATE RASPBERRY",
  "waste_bin": "landfill"
}

HTTP Status Code: 404
Barcode is not in the database

{
  "message": "Barcode not found"
}

Endpoint: POST /barcode/

There should never be any duplicate barcodes in the database

Example Body:

  {
    "barcode" : 647669926366,
    "item_info" : "1016038 - BISCOTTI CHOCOLATE RASPBERRY",
    "waste_bin": "landfill"
  }

HTTP Status Code: 201
Barcode is unique and has been added to the database

HTTP Status Code: 409 or 400 or 200 (not sure what the right status code should be)
Barcode already exists in the database and has not been added

Database interface tool

Create a simple command line interface for a user to drop and recreate tables and also add new bins to the database.

POST API Image

Instead of using the IP address to fetch the bin id. use the image file name to fetch the bin id.

Database Schema Design

Designing the ZBCE API database schema. Discussions thread will start here. Feel free to leave a comment!

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.