GithubHelp home page GithubHelp logo

klemmari1 / parkkihubi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from city-of-helsinki/parkkihubi

0.0 1.0 0.0 916 KB

Django-based REST API for processing parking data

License: MIT License

Python 83.52% Shell 0.58% HTML 0.35% TypeScript 15.12% CSS 0.22% Dockerfile 0.21%

parkkihubi's Introduction

Build status codecov Requirements

Parking hub

Django-based REST API for processing parking data.

Requirements

  • Python 3.x
  • PostgreSQL + PostGIS

Development

Install required system packages

PostgreSQL

The recommended versions for postgresql and postgis are at least 9.4 and 2.2 respectively.

# Ubuntu 16.04
sudo apt-get install python3-dev libpq-dev postgresql postgis

GeoDjango extra packages

# Ubuntu 16.04
sudo apt-get install binutils libproj-dev gdal-bin

Creating a virtualenv

Create a Python 3.x virtualenv either using the traditional virtualenv tool or using the great virtualenvwrapper toolset. Assuming the former, once installed, simply do:

mkvirtualenv -p /usr/bin/python3 parkkihubi

The virtualenv will automatically activate. To activate it in the future, just do:

workon parkkihubi

Python requirements

Use pip-tools to install and maintain installed dependencies.

pip install -U pip  # pip-tools needs pip==6.1 or higher (!)
pip install pip-tools

Install requirements as follows

pip-sync requirements.txt requirements-dev.txt

Django configuration

Environment variables are used to customize configuration in parkkihubi/settings.py. If you wish to override any settings, you can place them in a local .env file which will automatically be sourced when Django imports the settings file.

Create a basic file for development as follows

echo 'DEBUG=True' > .env

Parkkihubi settings

  • PARKKIHUBI_PUBLIC_API_ENABLED default True
  • PARKKIHUBI_MONITORING_API_ENABLED default True
  • PARKKIHUBI_OPERATOR_API_ENABLED default True
  • PARKKIHUBI_ENFORCEMENT_API_ENABLED default True

Database

Create user and database

sudo -u postgres createuser -P -R -S parkkihubi  # use password `parkkihubi`
sudo -u postgres createdb -O parkkihubi parkkihubi
sudo -u postgres psql parkkihubi -c "CREATE EXTENSION postgis;"

Allow user to create test database

sudo -u postgres psql -c "ALTER USER parkkihubi CREATEDB;"

Tests also require that PostGIS extension is installed on the test database. This can be achieved most easily by adding PostGIS extension to the default template:

sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS postgis;"

Run migrations

python manage.py migrate

Updating requirements files

Use Prequ to update the requirements*.txt files.

pip install prequ

When you change requirements, set them in requirements.in or requirements-dev.in. Then run:

prequ update

Running tests

Run all tests

py.test

Run with coverage

py.test --cov-report html --cov .

Open htmlcov/index.html for the coverage report.

Importing parking areas

To import Helsinki parking areas run:

python manage.py import_parking_areas

Starting a development server

python manage.py runserver

Operator API will be available at http://127.0.0.1:8000/operator/v1/

Enforcement API will be available at http://127.0.0.1:8000/enforcement/v1/

Public API will be available at http://127.0.0.1:8000/public/v1/

Generating API documentation

The API documentation conforms to Swagger Specification 2.0.

Three possible ways (out of many) to generate the documentation:

  • Run the documentation generating script:

    ./generate-docs
    

    The output will be in docs/generated directory by default. If you want to generate to a different directory, give that directory as the first argument to the script.

  • bootprint-openapi

    Probably the recommended way.

    Installation:

    npm install -g bootprint
    npm install -g bootprint-openapi
    

    Running (in parkkihubi repository root):

    bootprint openapi docs/api/enforcement.yaml </output/path/enforcement/>
    bootprint openapi docs/api/operator.yaml </output/path/operator/>
    
  • swagger-codegen

    Due to a bug in swagger-codegen, we're using an unreleased version at the moment.

    To build swagger-codegen from source, you need Apache maven installed (you'll need java 7 runtime at a minimum):

      # Ubuntu
      sudo apt-get install maven
    

    Clone swagger-codegen master branch and build it:

      git clone https://github.com/swagger-api/swagger-codegen
      cd swagger-codegen/
      mvn clean package  # Takes a few minutes
    

    The client will now be available at modules/swagger-codegen-cli/target/swagger-codegen-cli.jar.

    To build the docs, in parkkihubi repository root:

      cd docs/api
      java -jar /path/to/codegen/swagger-codegen-cli.jar generate \
        -i enforcement.yaml -l html2 -c config.json \
        -o /output/path/enforcement/
      java -jar /path/to/codegen/swagger-codegen-cli.jar generate \
        -i operator.yaml -l html2 -c config.json \
        -o /output/path/operator/
    

License

MIT

parkkihubi's People

Contributors

suutari-ai avatar tuomas777 avatar urshala avatar japauliina avatar maxg0 avatar jaywink avatar amanpdyadav avatar kerkkoheiskanen avatar vikoivun avatar hukka avatar mingfeng avatar

Watchers

James Cloos 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.