A database backend for the Open Glider Network
 
 
 
 
 
 
Go to file
Konstantin Gründger 0299417367 Refactoring WIP 2019-08-31 12:30:07 +02:00
app Refactoring WIP 2019-08-31 12:30:07 +02:00
migrations Remove FK relation from device to device_info 2019-04-27 14:29:09 +02:00
tests Refactoring WIP 2019-08-31 12:30:07 +02:00
.gitignore gitignore: Add celerybeat-schedule 2016-02-17 18:26:00 +01:00
.travis.yml Update .travis.yml 2019-06-19 15:09:37 +02:00
CHANGELOG.md Preparation for 0.3.0 2016-10-22 09:22:40 +02:00
CONTRIBUTORS Appended contributors list 2016-09-28 11:31:40 +02:00
LICENSE Create LICENSE 2015-11-14 22:47:25 +01:00
MANIFEST.in Add MANIFEST.in to include README,LICENSE & tests 2016-01-12 17:24:28 +01:00
README.md Add missing kwargs (fixes #71) 2019-04-30 07:22:24 +02:00
Vagrantfile Refactoring WIP 2019-08-31 12:30:07 +02:00
ogn_python.py Refactoring WIP 2019-08-31 12:30:07 +02:00
requirements.txt Add setup.py to create a package 2016-01-12 13:56:18 +01:00
setup.cfg Refactoring 2016-07-01 07:19:31 +02:00
setup.py Remove flask-nav package 2019-08-30 08:15:29 +02:00

README.md

ogn-python

Build Status Coverage Status

A database backend for the Open Glider Network. The ogn-python module saves all received beacons into a database with SQLAlchemy. It connects to the OGN aprs servers with python-ogn-client. It requires PostgreSQL and PostGIS. For best performance you should use TimescaleDB, which is based on PostgreSQL.

Examples

Installation and Setup

  1. Checkout the repository

    git clone https://github.com/glidernet/ogn-python.git
    
  2. Install python requirements

    pip install -r requirements.txt
    
  3. Install PostgreSQL with PostGIS Extension. Create a database (use "ogn" as default, otherwise you have to modify the configuration, see below)

  4. Optional: Install redis for asynchronous tasks (like takeoff/landing-detection)

    apt-get install redis-server
    
  5. Set the configuration. Let the environment variable OGN_CONFIG_MODULE point to the configuration file:

    export OGN_CONFIG_MODULE="config/default.py"
    
  6. Create database

    ./flask database init
    
  7. Optional: Prepare tables for TimescaleDB

    ./flask database init_timescaledb
    
  8. Optional: Import world border dataset (needed if you want to know the country a receiver belongs to, etc.) Get the World Borders Dataset and unpack it. Then import it into your database (we use "ogn" as database name).

    shp2pgsql -s 4326 TM_WORLD_BORDERS-0.3.shp world_borders_temp | psql -d ogn
    psql -d ogn -c "INSERT INTO countries SELECT * FROM world_borders_temp;"
    psql -d ogn -c "DROP TABLE world_borders_temp;"
    
  9. Get world elevation data (needed for AGL calculation) Sources: There are many sources for DEM data. It is important that the spatial reference system (SRID) is the same as the database which is 4326. The GMTED2010 Viewer provides data for the world with SRID 4326. Just download the data you need.

    For Europe we can get the DEM as GeoTIFF files from the European Environment Agency. Because the SRID of these files is 3035 and we want 4326 we have to convert them (next step)

  10. Optional: Convert the elevation data into correct SRID

    We convert elevation from one SRID (here: 3035) to target SRID (4326):

    gdalwarp -s_srs "EPSG:3035" -t_srs "EPSG:4326" source.tif target.tif
    
  11. Import the GeoTIFF into the elevation table:

    raster2pgsql -s 4326 -c -C -I -M -t 100x100 elevation_data.tif public.elevation | psql -d ogn
    
  12. Import Airports (needed for takeoff and landing calculation). A cup file is provided under tests:

    flask database import_airports tests/SeeYou.cup 
    
  13. Import DDB (needed for registration signs in the logbook).

    flask database import_ddb
    

There is also a Vagrant environment for the development of ogn-python. You can create and start this virtual machine with vagrant up and login with vagrant ssh. The code of ogn-python will be available in the shared folder /vagrant.

Usage

Running the aprs client and task server

To schedule tasks like takeoff/landing-detection (logbook.compute), Celery with Redis is used. The following scripts run in the foreground and should be deamonized (eg. use supervisord).

  • Start the aprs client

    ./flask gateway run
    
  • Start a task server (make sure redis is up and running)

    celery -A ogn_python.collect worker -l info
    
  • Start the task scheduler (make sure a task server is up and running)

    celery -A ogn_python.collect beat -l info
    

Flask - Command Line Interface

Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=app.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  database  Database creation and handling.
  db        Perform database migrations.
  export    Export data in several file formats.
  flights   Create 2D flight paths from data.
  gateway   Connection to APRS servers.
  logbook   Handling of logbook data.
  routes    Show the routes for the app.
  run       Runs a development server.
  shell     Runs a shell in the app context.
  stats     Handling of statistical data.

Most commands are command groups, so if you execute this command you will get further (sub)commands.

Available tasks

  • ogn_python.collect.celery.update_takeoff_landings - Compute takeoffs and landings.
  • ogn_python.collect.celery.update_logbook_entries - Add/update logbook entries.
  • ogn_python.collect.celery.update_logbook_max_altitude - Add max altitudes in logbook when flight is complete (takeoff and landing).
  • ogn_python.collect.celery.import_ddb - Import registered devices from the DDB.
  • ogn_python.collect.celery.update_receivers_country_code - Update country code in receivers table if None.
  • ogn_python.collect.celery.purge_old_data - Delete AircraftBeacons and ReceiverBeacons older than given 'age'.
  • ogn_python.collect.celery.update_stats - Create stats and update receivers/devices with stats.
  • ogn_python.collect.celery.update_ognrange - Create receiver coverage stats for Melissas ognrange.

If the task server is up and running, tasks could be started manually. Here we compute takeoffs and landings for the past 90 minutes:

python3
>>>from ogn_python.collect.celery import update_takeoff_landings
>>>update_takeoff_landings.delay(last_minutes=90)

License

Licensed under the AGPLv3.