kopia lustrzana https://github.com/glidernet/ogn-python
Migrate from manage.py to Flask Command Line Interface (WIP)
rodzic
28395c6426
commit
93f0cca587
13
manage.py
13
manage.py
|
@ -1,13 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from manager import Manager
|
||||
from ogn.commands import manager as command_manager
|
||||
from ogn.gateway.manage import manager as gateway_manager
|
||||
|
||||
manager = Manager()
|
||||
manager.merge(command_manager)
|
||||
manager.merge(gateway_manager, namespace='gateway')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
manager.main()
|
|
@ -1,5 +0,0 @@
|
|||
from ogn import app
|
||||
from ogn import routes
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
|
@ -1,17 +0,0 @@
|
|||
from .database import manager as database_manager
|
||||
from .bulkimport import manager as bulkimport_manager
|
||||
from .export import manager as export_manager
|
||||
from .logbook import manager as logbook_manager
|
||||
from .stats import manager as stats_manager
|
||||
from .flights import manager as flights_manager
|
||||
|
||||
from manager import Manager
|
||||
|
||||
manager = Manager()
|
||||
|
||||
manager.merge(database_manager, namespace='db')
|
||||
manager.merge(bulkimport_manager, namespace='bulkimport')
|
||||
manager.merge(export_manager, namespace='export')
|
||||
manager.merge(logbook_manager, namespace='logbook')
|
||||
manager.merge(stats_manager, namespace='stats')
|
||||
manager.merge(flights_manager, namespace='flights')
|
|
@ -1,57 +0,0 @@
|
|||
from datetime import datetime
|
||||
from tqdm import tqdm
|
||||
from manager import Manager
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.commands.database import get_database_days
|
||||
|
||||
from ogn.collect.stats import create_device_stats, create_receiver_stats, create_relation_stats,\
|
||||
update_qualities, update_receivers as update_receivers_command, update_devices as update_devices_command,\
|
||||
update_device_stats_jumps
|
||||
|
||||
from ogn.collect.ognrange import create_receiver_coverage
|
||||
|
||||
manager = Manager()
|
||||
|
||||
|
||||
@manager.command
|
||||
def create(start=None, end=None):
|
||||
"""Create DeviceStats, ReceiverStats and RelationStats."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
||||
pbar = tqdm(days)
|
||||
for single_date in pbar:
|
||||
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
||||
result = create_device_stats(session=session, date=single_date)
|
||||
result = update_device_stats_jumps(session=session, date=single_date)
|
||||
result = create_receiver_stats(session=session, date=single_date)
|
||||
result = create_relation_stats(session=session, date=single_date)
|
||||
result = update_qualities(session=session, date=single_date)
|
||||
|
||||
|
||||
@manager.command
|
||||
def update_receivers():
|
||||
"""Update receivers with data from stats."""
|
||||
|
||||
result = update_receivers_command(session=session)
|
||||
print(result)
|
||||
|
||||
|
||||
@manager.command
|
||||
def update_devices():
|
||||
"""Update devices with data from stats."""
|
||||
|
||||
result = update_devices_command(session=session)
|
||||
print(result)
|
||||
|
||||
|
||||
@manager.command
|
||||
def create_ognrange(start=None, end=None):
|
||||
"""Create stats for Melissas ognrange."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
||||
pbar = tqdm(days)
|
||||
for single_date in pbar:
|
||||
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
||||
result = create_receiver_coverage(session=session, date=single_date)
|
|
@ -1,7 +1,7 @@
|
|||
from flask import Flask
|
||||
from flask_bootstrap import Bootstrap
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from navigation import nav
|
||||
from ogn_python.navigation import nav
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('config.default')
|
|
@ -0,0 +1,6 @@
|
|||
from ogn_python import app
|
||||
from ogn_python import routes
|
||||
from ogn_python import commands
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
|
@ -2,7 +2,7 @@ from datetime import datetime, timedelta, timezone, date
|
|||
|
||||
from sqlalchemy import func, and_, between, case
|
||||
|
||||
from ogn.model import AircraftBeacon, Device, Receiver
|
||||
from ogn_python.model import AircraftBeacon, Device, Receiver
|
||||
|
||||
|
||||
def utc_to_local(utc_dt):
|
|
@ -3,7 +3,7 @@ from datetime import datetime, timedelta
|
|||
|
||||
from sqlalchemy import func, case
|
||||
from sqlalchemy.sql.expression import label
|
||||
from ogn.model import Receiver
|
||||
from ogn_python.model import Receiver
|
||||
|
||||
|
||||
def alchemyencoder(obj):
|
|
@ -5,9 +5,9 @@ from sqlalchemy.sql import null, and_, func, not_, case
|
|||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
from ogn.collect.celery import app
|
||||
from ogn.model import Country, DeviceInfo, DeviceInfoOrigin, AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from ogn.utils import get_ddb, get_flarmnet
|
||||
from ogn_python.collect.celery import app
|
||||
from ogn_python.model import Country, DeviceInfo, DeviceInfoOrigin, AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from ogn_python.utils import get_ddb, get_flarmnet
|
||||
|
||||
|
||||
logger = get_task_logger(__name__)
|
|
@ -4,9 +4,9 @@ from sqlalchemy import and_, or_, insert, update, exists, between
|
|||
from sqlalchemy.sql import func, null
|
||||
from sqlalchemy.sql.expression import true, false
|
||||
|
||||
from ogn.collect.celery import app
|
||||
from ogn.model import TakeoffLanding, Logbook, AircraftBeacon
|
||||
from ogn.utils import date_to_timestamps
|
||||
from ogn_python.collect.celery import app
|
||||
from ogn_python.model import TakeoffLanding, Logbook, AircraftBeacon
|
||||
from ogn_python.utils import date_to_timestamps
|
||||
|
||||
logger = get_task_logger(__name__)
|
||||
|
|
@ -4,9 +4,9 @@ from sqlalchemy import Date
|
|||
from sqlalchemy import and_, insert, update, exists, between
|
||||
from sqlalchemy.sql import func, null
|
||||
|
||||
from ogn.collect.celery import app
|
||||
from ogn.model import AircraftBeacon, ReceiverCoverage
|
||||
from ogn.utils import date_to_timestamps
|
||||
from ogn_python.collect.celery import app
|
||||
from ogn_python.model import AircraftBeacon, ReceiverCoverage
|
||||
from ogn_python.utils import date_to_timestamps
|
||||
|
||||
logger = get_task_logger(__name__)
|
||||
|
|
@ -4,11 +4,11 @@ from sqlalchemy import insert, distinct, between
|
|||
from sqlalchemy.sql import null, and_, func, or_, update
|
||||
from sqlalchemy.sql.expression import case
|
||||
|
||||
from ogn.model import AircraftBeacon, DeviceStats, ReceiverStats, RelationStats, Receiver, Device
|
||||
from ogn_python.model import AircraftBeacon, DeviceStats, ReceiverStats, RelationStats, Receiver, Device
|
||||
|
||||
from .celery import app
|
||||
from ogn.model.receiver_beacon import ReceiverBeacon
|
||||
from ogn.utils import date_to_timestamps
|
||||
from ogn_python.model.receiver_beacon import ReceiverBeacon
|
||||
from ogn_python.utils import date_to_timestamps
|
||||
|
||||
logger = get_task_logger(__name__)
|
||||
|
|
@ -6,9 +6,9 @@ from sqlalchemy import and_, or_, insert, between, exists
|
|||
from sqlalchemy.sql import func, null
|
||||
from sqlalchemy.sql.expression import case
|
||||
|
||||
from ogn.collect.celery import app
|
||||
from ogn.model import AircraftBeacon, TakeoffLanding, Airport
|
||||
from ogn.utils import date_to_timestamps
|
||||
from ogn_python.collect.celery import app
|
||||
from ogn_python.model import AircraftBeacon, TakeoffLanding, Airport
|
||||
from ogn_python.utils import date_to_timestamps
|
||||
|
||||
logger = get_task_logger(__name__)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
from ogn_python import app
|
||||
|
||||
from .bulkimport import user_cli as bulkimport_cli
|
||||
from .database import user_cli as database_cli
|
||||
from .export import user_cli as export_cli
|
||||
from .flights import user_cli as flights_cli
|
||||
from .logbook import user_cli as logbook_cli
|
||||
from .stats import user_cli as stats_cli
|
||||
|
||||
app.cli.add_command(bulkimport_cli)
|
||||
app.cli.add_command(database_cli)
|
||||
app.cli.add_command(flights_cli)
|
||||
app.cli.add_command(logbook_cli)
|
||||
app.cli.add_command(stats_cli)
|
|
@ -1,14 +1,21 @@
|
|||
from manager import Manager
|
||||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
import psycopg2
|
||||
from tqdm import tqdm
|
||||
from io import StringIO
|
||||
|
||||
from ogn.model import AircraftBeacon, ReceiverBeacon
|
||||
from ogn.utils import open_file
|
||||
from ogn.commands.database import get_database_days
|
||||
from ogn_python.model import AircraftBeacon, ReceiverBeacon
|
||||
from ogn_python.utils import open_file
|
||||
from ogn_python.commands.database import get_database_days
|
||||
|
||||
manager = Manager()
|
||||
from ogn_python import db
|
||||
|
||||
user_cli = AppGroup('bulkimport')
|
||||
user_cli.help = "Tools for accelerated data import."
|
||||
|
||||
|
||||
ALEMBIC_CONFIG_FILE = "alembic.ini"
|
||||
|
||||
|
||||
class LogfileDbSaver():
|
||||
|
@ -416,8 +423,8 @@ class LogfileDbSaver():
|
|||
|
||||
|
||||
def convert(sourcefile, datestr, saver):
|
||||
from ogn.gateway.process import string_to_message
|
||||
from ogn.gateway.process_tools import AIRCRAFT_BEACON_TYPES, RECEIVER_BEACON_TYPES
|
||||
from ogn_python.gateway.process import string_to_message
|
||||
from ogn_python.gateway.process_tools import AIRCRAFT_BEACON_TYPES, RECEIVER_BEACON_TYPES
|
||||
from datetime import datetime
|
||||
|
||||
fin = open_file(sourcefile)
|
||||
|
@ -467,7 +474,8 @@ def convert(sourcefile, datestr, saver):
|
|||
fin.close()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('file_import')
|
||||
@click.argument('path')
|
||||
def file_import(path):
|
||||
"""Import APRS logfiles into separate logfile tables."""
|
||||
|
||||
|
@ -501,7 +509,7 @@ def file_import(path):
|
|||
saver.add_missing_receivers()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('update')
|
||||
def update():
|
||||
"""Update beacons (add foreign keys, compute distance, bearing, ags, etc.) in separate logfile tables."""
|
||||
|
||||
|
@ -517,8 +525,10 @@ def update():
|
|||
saver.create_indices()
|
||||
|
||||
|
||||
@manager.command
|
||||
def transfer(start=None, end=None):
|
||||
@user_cli.command('transfer')
|
||||
@click.argument('start')
|
||||
@click.argument('end')
|
||||
def transfer(start, end):
|
||||
"""Transfer beacons from separate logfile tables to beacon table."""
|
||||
|
||||
with LogfileDbSaver() as saver:
|
||||
|
@ -536,7 +546,7 @@ def transfer(start=None, end=None):
|
|||
saver.transfer_receiver_beacons()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('create_flights2d')
|
||||
def create_flights2d():
|
||||
"""Create complete flight traces from logfile tables."""
|
||||
|
||||
|
@ -549,7 +559,7 @@ def create_flights2d():
|
|||
saver.create_flights2d()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('create_gaps2d')
|
||||
def create_gaps2d():
|
||||
"""Create 'gaps' from logfile tables."""
|
||||
|
||||
|
@ -562,7 +572,8 @@ def create_gaps2d():
|
|||
saver.create_gaps2d()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('file_export')
|
||||
@click.argument('path')
|
||||
def file_export(path):
|
||||
"""Export separate logfile tables to csv files. They can be used for fast bulk import with sql COPY command."""
|
||||
|
||||
|
@ -580,6 +591,3 @@ def file_export(path):
|
|||
saver.set_datestr(datestr)
|
||||
saver.export_to_path(path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
file_export()
|
|
@ -1,13 +1,17 @@
|
|||
from datetime import datetime, timedelta
|
||||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
from manager import Manager
|
||||
from ogn.collect.database import update_device_infos, update_country_code
|
||||
from ogn.commands.dbutils import engine, session
|
||||
from ogn.model import Base, DeviceInfoOrigin, AircraftBeacon
|
||||
from ogn.utils import get_airports, get_days
|
||||
from datetime import datetime, timedelta
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
manager = Manager()
|
||||
from ogn_python.collect.database import update_device_infos, update_country_code
|
||||
from ogn_python.model import *
|
||||
from ogn_python.utils import get_airports, get_days
|
||||
from ogn_python import db
|
||||
|
||||
user_cli = AppGroup('database')
|
||||
user_cli.help = "Database creation and handling."
|
||||
|
||||
|
||||
ALEMBIC_CONFIG_FILE = "alembic.ini"
|
||||
|
||||
|
@ -16,7 +20,7 @@ def get_database_days(start, end):
|
|||
"""Returns the first and the last day in aircraft_beacons table."""
|
||||
|
||||
if start is None and end is None:
|
||||
days_from_db = session.query(func.min(AircraftBeacon.timestamp).label('first_day'), func.max(AircraftBeacon.timestamp).label('last_day')).one()
|
||||
days_from_db = db.session.query(func.min(AircraftBeacon.timestamp).label('first_day'), func.max(AircraftBeacon.timestamp).label('last_day')).one()
|
||||
start = days_from_db[0].date()
|
||||
end = days_from_db[1].date()
|
||||
else:
|
||||
|
@ -28,16 +32,16 @@ def get_database_days(start, end):
|
|||
return days
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('init')
|
||||
def init():
|
||||
"""Initialize the database."""
|
||||
|
||||
from alembic.config import Config
|
||||
from alembic import command
|
||||
|
||||
session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
|
||||
session.execute('CREATE EXTENSION IF NOT EXISTS btree_gist;')
|
||||
session.commit()
|
||||
db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
|
||||
db.session.execute('CREATE EXTENSION IF NOT EXISTS btree_gist;')
|
||||
db.session.commit()
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
#alembic_cfg = Config(ALEMBIC_CONFIG_FILE)
|
||||
|
@ -45,17 +49,17 @@ def init():
|
|||
print("Done.")
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('init_timescaledb')
|
||||
def init_timescaledb():
|
||||
"""Initialize TimescaleDB features."""
|
||||
|
||||
session.execute('CREATE EXTENSION IF NOT EXISTS timescaledb;')
|
||||
session.execute("SELECT create_hypertable('aircraft_beacons', 'timestamp', chunk_target_size => '2GB', if_not_exists => TRUE);")
|
||||
session.execute("SELECT create_hypertable('receiver_beacons', 'timestamp', chunk_target_size => '2GB', if_not_exists => TRUE);")
|
||||
session.commit()
|
||||
db.session.execute('CREATE EXTENSION IF NOT EXISTS timescaledb;')
|
||||
db.session.execute("SELECT create_hypertable('aircraft_beacons', 'timestamp', chunk_target_size => '2GB', if_not_exists => TRUE);")
|
||||
db.session.execute("SELECT create_hypertable('receiver_beacons', 'timestamp', chunk_target_size => '2GB', if_not_exists => TRUE);")
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('upgrade')
|
||||
def upgrade():
|
||||
"""Upgrade database to the latest version."""
|
||||
|
||||
|
@ -66,7 +70,8 @@ def upgrade():
|
|||
command.upgrade(alembic_cfg, 'head')
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('drop')
|
||||
@click.argument('sure')
|
||||
def drop(sure='n'):
|
||||
"""Drop all tables."""
|
||||
if sure == 'y':
|
||||
|
@ -76,52 +81,55 @@ def drop(sure='n'):
|
|||
print("Add argument '--sure y' to drop all tables.")
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('import_ddb')
|
||||
def import_ddb():
|
||||
"""Import registered devices from the DDB."""
|
||||
|
||||
print("Import registered devices fom the DDB...")
|
||||
counter = update_device_infos(session, DeviceInfoOrigin.ogn_ddb)
|
||||
counter = update_device_infos(db.session, DeviceInfoOrigin.ogn_ddb)
|
||||
print("Imported %i devices." % counter)
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('import_file')
|
||||
@click.argument('path')
|
||||
def import_file(path='tests/custom_ddb.txt'):
|
||||
"""Import registered devices from a local file."""
|
||||
|
||||
print("Import registered devices from '{}'...".format(path))
|
||||
counter = update_device_infos(session,
|
||||
counter = update_device_infos(db.session,
|
||||
DeviceInfoOrigin.user_defined,
|
||||
path=path)
|
||||
print("Imported %i devices." % counter)
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('import_flarmnet')
|
||||
@click.argument('path')
|
||||
def import_flarmnet(path=None):
|
||||
"""Import registered devices from a local file."""
|
||||
|
||||
print("Import registered devices from '{}'...".format("internet" if path is None else path))
|
||||
counter = update_device_infos(session,
|
||||
counter = update_device_infos(db.session,
|
||||
DeviceInfoOrigin.flarmnet,
|
||||
path=path)
|
||||
print("Imported %i devices." % counter)
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('import_airports')
|
||||
@click.argument('path')
|
||||
def import_airports(path='tests/SeeYou.cup'):
|
||||
"""Import airports from a ".cup" file"""
|
||||
|
||||
print("Import airports from '{}'...".format(path))
|
||||
airports = get_airports(path)
|
||||
session.bulk_save_objects(airports)
|
||||
session.commit()
|
||||
session.execute("UPDATE airports SET border = ST_Expand(location, 0.05)")
|
||||
session.commit()
|
||||
db.session.bulk_save_objects(airports)
|
||||
db.session.commit()
|
||||
db.session.execute("UPDATE airports SET border = ST_Expand(location, 0.05)")
|
||||
db.session.commit()
|
||||
print("Imported {} airports.".format(len(airports)))
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('update_country_codes')
|
||||
def update_country_codes():
|
||||
"""Update country codes of all receivers."""
|
||||
|
||||
update_country_code(session=session)
|
||||
update_country_code(session=db.session)
|
|
@ -1,17 +1,19 @@
|
|||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
import datetime
|
||||
import re
|
||||
import csv
|
||||
|
||||
from aerofiles.igc import Writer
|
||||
from manager import Manager
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.model import AircraftBeacon, Device
|
||||
from ogn_python.model import *
|
||||
from ogn_python import db
|
||||
|
||||
user_cli = AppGroup('export')
|
||||
user_cli.help = "Export data in several file formats."
|
||||
|
||||
|
||||
manager = Manager()
|
||||
|
||||
|
||||
@manager.command
|
||||
@user_cli.command('cup')
|
||||
def cup():
|
||||
"""Export receiver waypoints as '.cup'."""
|
||||
|
||||
|
@ -45,17 +47,16 @@ def cup():
|
|||
INNER JOIN countries c ON c.gid = sq.country_id
|
||||
ORDER BY sq.name;
|
||||
"""
|
||||
results = session.execute(sql)
|
||||
results = db.session.execute(sql)
|
||||
|
||||
with open('receivers.cup', 'w') as outfile:
|
||||
outcsv = csv.writer(outfile)
|
||||
outcsv.writerow(results.keys())
|
||||
outcsv.writerows(results.fetchall())
|
||||
|
||||
|
||||
@manager.arg('address', help='address (flarm id)')
|
||||
@manager.arg('date', help='date (format: yyyy-mm-dd)')
|
||||
@manager.command
|
||||
@user_cli.command('igc')
|
||||
@click.argument('address')
|
||||
@click.argument('date')
|
||||
def igc(address, date):
|
||||
"""Export igc file for <address> at <date>."""
|
||||
if not re.match('.{6}', address):
|
||||
|
@ -66,7 +67,7 @@ def igc(address, date):
|
|||
print("Date {} not valid.".format(date))
|
||||
return
|
||||
|
||||
device_id = session.query(Device.id) \
|
||||
device_id = db.session.query(Device.id) \
|
||||
.filter(Device.address == address) \
|
||||
.first()
|
||||
|
||||
|
@ -95,7 +96,7 @@ def igc(address, date):
|
|||
'competition_class': 'Doubleseater',
|
||||
})
|
||||
|
||||
points = session.query(AircraftBeacon) \
|
||||
points = db.session.query(AircraftBeacon) \
|
||||
.filter(AircraftBeacon.device_id == device_id) \
|
||||
.filter(AircraftBeacon.timestamp > date + ' 00:00:00') \
|
||||
.filter(AircraftBeacon.timestamp < date + ' 23:59:59') \
|
|
@ -1,13 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from manager import Manager
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.commands.database import get_database_days
|
||||
from tqdm import tqdm
|
||||
|
||||
manager = Manager()
|
||||
from ogn_python.commands.database import get_database_days
|
||||
from ogn_python import db
|
||||
|
||||
user_cli = AppGroup('flights')
|
||||
user_cli.help = "Create 2D flight paths from data."
|
||||
|
||||
|
||||
def compute_flights2d(session, date):
|
||||
|
@ -66,8 +67,10 @@ def compute_flights2d(session, date):
|
|||
session.commit()
|
||||
|
||||
|
||||
@manager.command
|
||||
def flights2d(start=None, end=None):
|
||||
@user_cli.command('create')
|
||||
@click.argument('start')
|
||||
@click.argument('end')
|
||||
def create(start, end):
|
||||
"""Compute flights."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
@ -75,4 +78,4 @@ def flights2d(start=None, end=None):
|
|||
pbar = tqdm(days)
|
||||
for single_date in pbar:
|
||||
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
||||
result = compute_flights2d(session=session, date=single_date)
|
||||
result = compute_flights2d(session=db.session, date=single_date)
|
|
@ -1,23 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from manager import Manager
|
||||
from ogn.collect.logbook import update_logbook
|
||||
from ogn.collect.takeoff_landings import update_takeoff_landings
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.model import Airport, Logbook
|
||||
from sqlalchemy import or_, between
|
||||
from ogn_python.collect.logbook import update_logbook
|
||||
from ogn_python.collect.takeoff_landings import update_takeoff_landings
|
||||
from ogn_python.commands.dbutils import session
|
||||
from ogn_python.model import Airport, Logbook
|
||||
from sqlalchemy.sql import func
|
||||
from tqdm import tqdm
|
||||
from ogn.commands.database import get_database_days
|
||||
from ogn.utils import date_to_timestamps
|
||||
from ogn_python.commands.database import get_database_days
|
||||
from ogn_python.utils import date_to_timestamps
|
||||
|
||||
manager = Manager()
|
||||
from ogn_python import db
|
||||
|
||||
user_cli = AppGroup('logbook')
|
||||
user_cli.help = "Handling of logbook data."
|
||||
|
||||
|
||||
@manager.command
|
||||
def compute_takeoff_landing(start=None, end=None):
|
||||
@user_cli.command('compute_takeoff_landing')
|
||||
@click.argument('start')
|
||||
@click.argument('end')
|
||||
def compute_takeoff_landing(start, end):
|
||||
"""Compute takeoffs and landings."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
@ -28,8 +32,10 @@ def compute_takeoff_landing(start=None, end=None):
|
|||
result = update_takeoff_landings(session=session, date=single_date)
|
||||
|
||||
|
||||
@manager.command
|
||||
def compute_logbook(start=None, end=None):
|
||||
@user_cli.command('compute_logbook')
|
||||
@click.argument('start')
|
||||
@click.argument('end')
|
||||
def compute_logbook(start, end):
|
||||
"""Compute logbook."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
@ -40,8 +46,9 @@ def compute_logbook(start=None, end=None):
|
|||
result = update_logbook(session=session, date=single_date)
|
||||
|
||||
|
||||
@manager.arg('date', help='date (format: yyyy-mm-dd)')
|
||||
@manager.command
|
||||
@user_cli.command('show')
|
||||
@click.argument('airport_name')
|
||||
@click.argument('date')
|
||||
def show(airport_name, date=None):
|
||||
"""Show a logbook for <airport_name>."""
|
||||
airport = session.query(Airport) \
|
||||
|
@ -56,13 +63,13 @@ def show(airport_name, date=None):
|
|||
if date is not None:
|
||||
date = datetime.strptime(date, "%Y-%m-%d")
|
||||
(start, end) = date_to_timestamps(date)
|
||||
or_args = [between(Logbook.reftime, start, end)]
|
||||
or_args = [db.between(Logbook.reftime, start, end)]
|
||||
|
||||
# get all logbook entries and add device and airport infos
|
||||
logbook_query = session.query(func.row_number().over(order_by=Logbook.reftime).label('row_number'),
|
||||
Logbook) \
|
||||
.filter(*or_args) \
|
||||
.filter(or_(Logbook.takeoff_airport_id == airport.id,
|
||||
.filter(db.or_(Logbook.takeoff_airport_id == airport.id,
|
||||
Logbook.landing_airport_id == airport.id)) \
|
||||
.order_by(Logbook.reftime)
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
from datetime import datetime
|
||||
from tqdm import tqdm
|
||||
|
||||
from ogn_python.commands.database import get_database_days
|
||||
|
||||
from ogn_python.collect.stats import create_device_stats, create_receiver_stats, create_relation_stats,\
|
||||
update_qualities, update_receivers as update_receivers_command, update_devices as update_devices_command,\
|
||||
update_device_stats_jumps
|
||||
|
||||
from ogn_python.collect.ognrange import create_receiver_coverage
|
||||
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
user_cli = AppGroup('stats')
|
||||
user_cli.help = "Handling of statistical data."
|
||||
|
||||
|
||||
@user_cli.command('create')
|
||||
@click.argument('start')
|
||||
@click.argument('end')
|
||||
def create(start, end):
|
||||
"""Create DeviceStats, ReceiverStats and RelationStats."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
||||
pbar = tqdm(days)
|
||||
for single_date in pbar:
|
||||
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
||||
result = create_device_stats(session=db.session, date=single_date)
|
||||
result = update_device_stats_jumps(session=db.session, date=single_date)
|
||||
result = create_receiver_stats(session=db.session, date=single_date)
|
||||
result = create_relation_stats(session=db.session, date=single_date)
|
||||
result = update_qualities(session=db.session, date=single_date)
|
||||
|
||||
|
||||
@user_cli.command('update_receivers')
|
||||
def update_receivers():
|
||||
"""Update receivers with data from stats."""
|
||||
|
||||
result = update_receivers_command(session=db.session)
|
||||
print(result)
|
||||
|
||||
|
||||
@user_cli.command('update_devices')
|
||||
def update_devices():
|
||||
"""Update devices with data from stats."""
|
||||
|
||||
result = update_devices_command(session=db.session)
|
||||
print(result)
|
||||
|
||||
|
||||
@user_cli.command('create_ognrange')
|
||||
@click.argument('start')
|
||||
@click.argument('end')
|
||||
def create_ognrange(start=None, end=None):
|
||||
"""Create stats for Melissas ognrange."""
|
||||
|
||||
days = get_database_days(start, end)
|
||||
|
||||
pbar = tqdm(days)
|
||||
for single_date in pbar:
|
||||
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
||||
result = create_receiver_coverage(session=db.session, date=single_date)
|
|
@ -1,11 +1,11 @@
|
|||
import logging
|
||||
|
||||
from manager import Manager
|
||||
from ogn.client import AprsClient
|
||||
from ogn.gateway.process import string_to_message
|
||||
from ogn_python.client import AprsClient
|
||||
from ogn_python.gateway.process import string_to_message
|
||||
from datetime import datetime
|
||||
from ogn.gateway.process_tools import DbSaver
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn_python.gateway.process_tools import DbSaver
|
||||
from ogn_python.commands.dbutils import session
|
||||
|
||||
manager = Manager()
|
||||
|
|
@ -2,10 +2,10 @@ import logging
|
|||
|
||||
from mgrs import MGRS
|
||||
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.model import Location
|
||||
from ogn.parser import parse, ParseError
|
||||
from ogn.gateway.process_tools import DbSaver, AIRCRAFT_BEACON_TYPES, RECEIVER_BEACON_TYPES
|
||||
from ogn_python.commands.dbutils import session
|
||||
from ogn_python.model import Location
|
||||
from ogn_python.parser import parse, ParseError
|
||||
from ogn_python.gateway.process_tools import DbSaver, AIRCRAFT_BEACON_TYPES, RECEIVER_BEACON_TYPES
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
|
@ -1,6 +1,6 @@
|
|||
from datetime import datetime, timedelta
|
||||
from ogn.model import AircraftBeacon, ReceiverBeacon
|
||||
from ogn.collect.database import upsert
|
||||
from ogn_python.model import AircraftBeacon, ReceiverBeacon
|
||||
from ogn_python.collect.database import upsert
|
||||
|
||||
# define message types we want to proceed
|
||||
AIRCRAFT_BEACON_TYPES = ['aprs_aircraft', 'flarm', 'tracker', 'fanet', 'lt24', 'naviter', 'skylines', 'spider', 'spot']
|
|
@ -1,7 +1,7 @@
|
|||
from sqlalchemy.sql import func
|
||||
from .beacon import Beacon
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class AircraftBeacon(Beacon):
|
|
@ -1,6 +1,6 @@
|
|||
from geoalchemy2.types import Geometry
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Airport(db.Model):
|
|
@ -5,7 +5,7 @@ from sqlalchemy.ext.hybrid import hybrid_property
|
|||
|
||||
from .geo import Location
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Beacon(AbstractConcreteBase, db.Model):
|
|
@ -1,6 +1,6 @@
|
|||
from geoalchemy2.types import Geometry
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Country(db.Model):
|
|
@ -1,4 +1,4 @@
|
|||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Device(db.Model):
|
|
@ -1,4 +1,4 @@
|
|||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class DeviceInfo(db.Model):
|
|
@ -1,4 +1,4 @@
|
|||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class DeviceStats(db.Model):
|
|
@ -1,6 +1,6 @@
|
|||
from geoalchemy2.types import Geometry
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Flight2D(db.Model):
|
|
@ -1,6 +1,6 @@
|
|||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Logbook(db.Model):
|
|
@ -3,7 +3,7 @@ from geoalchemy2.types import Geometry
|
|||
|
||||
from .geo import Location
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class Receiver(db.Model):
|
|
@ -1,7 +1,7 @@
|
|||
from sqlalchemy.sql import func
|
||||
from .beacon import Beacon
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class ReceiverBeacon(Beacon):
|
|
@ -1,4 +1,4 @@
|
|||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class ReceiverCoverage(db.Model):
|
|
@ -1,6 +1,6 @@
|
|||
from geoalchemy2.types import Geometry
|
||||
|
||||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class ReceiverStats(db.Model):
|
|
@ -1,4 +1,4 @@
|
|||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class RelationStats(db.Model):
|
|
@ -1,4 +1,4 @@
|
|||
from ogn import db
|
||||
from ogn_python import db
|
||||
|
||||
|
||||
class TakeoffLanding(db.Model):
|
|
@ -1,9 +1,9 @@
|
|||
from flask import request, render_template
|
||||
|
||||
from ogn import app
|
||||
from ogn import db
|
||||
from ogn_python import app
|
||||
from ogn_python import db
|
||||
|
||||
from ogn.model import *
|
||||
from ogn_python.model import *
|
||||
|
||||
|
||||
@app.route('/')
|
Przed Szerokość: | Wysokość: | Rozmiar: 78 KiB Po Szerokość: | Wysokość: | Rozmiar: 78 KiB |
Przed Szerokość: | Wysokość: | Rozmiar: 43 B Po Szerokość: | Wysokość: | Rozmiar: 43 B |
Przed Szerokość: | Wysokość: | Rozmiar: 42 B Po Szerokość: | Wysokość: | Rozmiar: 42 B |
5
setup.py
5
setup.py
|
@ -33,13 +33,12 @@ setup(
|
|||
packages=find_packages(exclude=['tests', 'tests.*']),
|
||||
install_requires=[
|
||||
'Flask==1.0.2',
|
||||
'flask-bootstrap==3.3.7.1',
|
||||
'flask-sqlalchemy==2.3.2',
|
||||
'Flask-Migrate==2.3.1',
|
||||
'flask-bootstrap==3.3.7.1',
|
||||
'flask-nav==0.6',
|
||||
'geopy==1.17.0',
|
||||
'manage.py==0.2.10',
|
||||
'celery[redis]==4.2.1',
|
||||
'alembic==1.0.0',
|
||||
'aerofiles==0.4.1',
|
||||
'geoalchemy2==0.5.0',
|
||||
'shapely>=1.5.17,<1.6',
|
||||
|
|
|
@ -5,11 +5,11 @@ from datetime import datetime
|
|||
|
||||
from xmlunittest import XmlTestMixin
|
||||
|
||||
from ogn.model import AircraftBeacon, Receiver, Device, DeviceInfo
|
||||
from ogn_python.model import AircraftBeacon, Receiver, Device, DeviceInfo
|
||||
|
||||
from ogn.backend.liveglidernet import rec, lxml
|
||||
from ogn.backend.ognrange import stations2_filtered_pl
|
||||
from ogn.model.aircraft_type import AircraftType
|
||||
from ogn_python.backend.liveglidernet import rec, lxml
|
||||
from ogn_python.backend.ognrange import stations2_filtered_pl
|
||||
from ogn_python.model.aircraft_type import AircraftType
|
||||
|
||||
|
||||
class TestDB(unittest.TestCase, XmlTestMixin):
|
||||
|
@ -19,11 +19,11 @@ class TestDB(unittest.TestCase, XmlTestMixin):
|
|||
|
||||
def setUp(self):
|
||||
os.environ['OGN_CONFIG_MODULE'] = 'config.test'
|
||||
from ogn.commands.dbutils import engine, session
|
||||
from ogn_python.commands.dbutils import engine, session
|
||||
self.session = session
|
||||
self.engine = engine
|
||||
|
||||
from ogn.commands.database import init
|
||||
from ogn_python.commands.database import init
|
||||
init()
|
||||
|
||||
# Prepare Beacons
|
||||
|
|
|
@ -10,14 +10,14 @@ class TestBaseDB(unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
from ogn.commands.dbutils import engine, session
|
||||
from ogn_python.commands.dbutils import engine, session
|
||||
cls.session = session
|
||||
cls.engine = engine
|
||||
|
||||
from ogn.commands.database import drop
|
||||
from ogn_python.commands.database import drop
|
||||
drop(sure='y')
|
||||
|
||||
from ogn.commands.database import init
|
||||
from ogn_python.commands.database import init
|
||||
init()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -2,8 +2,8 @@ import unittest
|
|||
|
||||
from tests.base import TestBaseDB
|
||||
|
||||
from ogn.model import AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from ogn.collect.database import add_missing_devices, add_missing_receivers, upsert
|
||||
from ogn_python.model import AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from ogn_python.collect.database import add_missing_devices, add_missing_receivers, upsert
|
||||
|
||||
|
||||
class TestDatabase(TestBaseDB):
|
||||
|
|
|
@ -2,8 +2,8 @@ import unittest
|
|||
|
||||
from tests.base import TestBaseDB
|
||||
|
||||
from ogn.model import Logbook, Airport, Device, TakeoffLanding
|
||||
from ogn.collect.logbook import update_logbook
|
||||
from ogn_python.model import Logbook, Airport, Device, TakeoffLanding
|
||||
from ogn_python.collect.logbook import update_logbook
|
||||
|
||||
|
||||
class TestLogbook(TestBaseDB):
|
||||
|
|
|
@ -3,8 +3,8 @@ from datetime import date
|
|||
|
||||
from tests.base import TestBaseDB
|
||||
|
||||
from ogn.model import AircraftBeacon, Receiver, ReceiverCoverage, Device
|
||||
from ogn.collect.ognrange import create_receiver_coverage
|
||||
from ogn_python.model import AircraftBeacon, Receiver, ReceiverCoverage, Device
|
||||
from ogn_python.collect.ognrange import create_receiver_coverage
|
||||
|
||||
|
||||
class TestOGNrange(TestBaseDB):
|
||||
|
|
|
@ -3,9 +3,9 @@ from datetime import datetime, date
|
|||
|
||||
from tests.base import TestBaseDB
|
||||
|
||||
from ogn.model import AircraftBeacon, ReceiverBeacon, Receiver, Device, DeviceStats
|
||||
from ogn_python.model import AircraftBeacon, ReceiverBeacon, Receiver, Device, DeviceStats
|
||||
|
||||
from ogn.collect.stats import create_device_stats
|
||||
from ogn_python.collect.stats import create_device_stats
|
||||
|
||||
|
||||
class TestStats(TestBaseDB):
|
||||
|
|
|
@ -2,9 +2,9 @@ import unittest
|
|||
|
||||
from tests.base import TestBaseDB
|
||||
|
||||
from ogn.model import TakeoffLanding
|
||||
from ogn_python.model import TakeoffLanding
|
||||
|
||||
from ogn.collect.takeoff_landings import update_takeoff_landings
|
||||
from ogn_python.collect.takeoff_landings import update_takeoff_landings
|
||||
|
||||
|
||||
class TestTakeoffLanding(TestBaseDB):
|
||||
|
|
|
@ -3,8 +3,8 @@ import os
|
|||
|
||||
from tests.base import TestBaseDB
|
||||
|
||||
from ogn.model import DeviceInfo
|
||||
from ogn.commands.database import import_file
|
||||
from ogn_python.model import DeviceInfo
|
||||
from ogn_python.commands.database import import_file
|
||||
|
||||
|
||||
class TestDatabase(TestBaseDB):
|
||||
|
|
|
@ -2,7 +2,7 @@ import datetime
|
|||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ogn.gateway.process_tools import DbSaver
|
||||
from ogn_python.gateway.process_tools import DbSaver
|
||||
|
||||
|
||||
class DbSaverTest(unittest.TestCase):
|
||||
|
|
|
@ -2,8 +2,8 @@ import os
|
|||
import unittest
|
||||
from datetime import date
|
||||
|
||||
from ogn.model import AircraftType
|
||||
from ogn.utils import get_days, get_ddb, get_trackable, get_airports
|
||||
from ogn_python.model import AircraftType
|
||||
from ogn_python.utils import get_days, get_ddb, get_trackable, get_airports
|
||||
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
|
|
Ładowanie…
Reference in New Issue