kopia lustrzana https://github.com/glidernet/ogn-python
Refactoring
rodzic
791b6720e4
commit
9e91a825f5
|
@ -1,6 +1,6 @@
|
|||
from celery.utils.log import get_task_logger
|
||||
|
||||
from ogn.model import DeviceInfo, AddressOrigin
|
||||
from ogn.model import DeviceInfo, DeviceInfoOrigin
|
||||
from ogn.utils import get_ddb
|
||||
|
||||
from ogn.collect.celery import app
|
||||
|
@ -27,7 +27,7 @@ def import_ddb():
|
|||
"""Import registered devices from the DDB."""
|
||||
|
||||
logger.info("Import registered devices fom the DDB...")
|
||||
address_origin = AddressOrigin.ogn_ddb
|
||||
address_origin = DeviceInfoOrigin.ogn_ddb
|
||||
|
||||
counter = update_device_infos(app.session, address_origin)
|
||||
logger.info("Imported {} devices.".format(counter))
|
||||
|
@ -38,7 +38,7 @@ def import_file(path='tests/custom_ddb.txt'):
|
|||
"""Import registered devices from a local file."""
|
||||
|
||||
logger.info("Import registered devices from '{}'...".format(path))
|
||||
address_origin = AddressOrigin.user_defined
|
||||
address_origin = DeviceInfoOrigin.user_defined
|
||||
|
||||
counter = update_device_infos(app.session, address_origin, csvfile=path)
|
||||
logger.info("Imported {} devices.".format(counter))
|
||||
|
|
|
@ -184,7 +184,7 @@ def import_logfile(path):
|
|||
else:
|
||||
print("For {} beacons already exist. Skipping".format(reference_date_string))
|
||||
else:
|
||||
print("Unknown file type: {}".format())
|
||||
print("Unknown file type: {}".format(tail))
|
||||
|
||||
|
||||
def check_no_beacons(tablename, reference_date_string):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from manager import Manager
|
||||
from ogn.collect.database import update_device_infos
|
||||
from ogn.commands.dbutils import engine, session
|
||||
from ogn.model import Base, AddressOrigin, AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from ogn.model import Base, DeviceInfoOrigin, AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from ogn.utils import get_airports
|
||||
from sqlalchemy import insert, distinct
|
||||
from sqlalchemy.sql import null
|
||||
|
@ -53,7 +53,7 @@ def import_ddb():
|
|||
"""Import registered devices from the DDB."""
|
||||
|
||||
print("Import registered devices fom the DDB...")
|
||||
address_origin = AddressOrigin.ogn_ddb
|
||||
address_origin = DeviceInfoOrigin.ogn_ddb
|
||||
counter = update_device_infos(session,
|
||||
address_origin)
|
||||
print("Imported %i devices." % counter)
|
||||
|
@ -65,7 +65,7 @@ def import_file(path='tests/custom_ddb.txt'):
|
|||
# (flushes previously manually imported entries)
|
||||
|
||||
print("Import registered devices from '{}'...".format(path))
|
||||
address_origin = AddressOrigin.user_defined
|
||||
address_origin = DeviceInfoOrigin.user_defined
|
||||
counter = update_device_infos(session,
|
||||
address_origin,
|
||||
csvfile=path)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from manager import Manager
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.model import AddressOrigin
|
||||
from ogn.model import DeviceInfoOrigin
|
||||
from ogn.model.device_info import DeviceInfo
|
||||
from sqlalchemy import func, and_, true, false
|
||||
|
||||
|
@ -39,7 +39,7 @@ def get_devices_stats(session):
|
|||
|
||||
stats = {}
|
||||
for [address_origin, device_count, default_count, nt_count, ni_count, ntni_count] in query.all():
|
||||
origin = AddressOrigin(address_origin).name()
|
||||
origin = DeviceInfoOrigin(address_origin).name()
|
||||
stats[origin] = {'device_count': device_count,
|
||||
'default_count': default_count,
|
||||
'nt_count': nt_count,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# flake8: noqa
|
||||
from .address_origin import AddressOrigin
|
||||
from .aircraft_type import AircraftType
|
||||
from .base import Base
|
||||
from .beacon import Beacon
|
||||
from .device import Device
|
||||
from .device_info import DeviceInfo
|
||||
from .device_info_origin import DeviceInfoOrigin
|
||||
from .aircraft_beacon import AircraftBeacon
|
||||
from .receiver_beacon import ReceiverBeacon
|
||||
from .receiver import Receiver
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class AddressOrigin:
|
||||
class DeviceInfoOrigin:
|
||||
unknown = 0
|
||||
ogn_ddb = 1
|
||||
flarmnet = 2
|
|
@ -8,7 +8,7 @@ from geopy.geocoders import Nominatim
|
|||
from ogn.parser.utils import feet2m
|
||||
import requests
|
||||
|
||||
from .model import AddressOrigin, DeviceInfo, Airport, Location
|
||||
from .model import DeviceInfoOrigin, DeviceInfo, Airport, Location
|
||||
|
||||
|
||||
DDB_URL = "http://ddb.glidernet.org/download/?t=1"
|
||||
|
@ -22,7 +22,7 @@ nm2m = 1852
|
|||
mi2m = 1609.34
|
||||
|
||||
|
||||
def get_ddb(csvfile=None, address_origin=AddressOrigin.unknown):
|
||||
def get_ddb(csvfile=None, device_info_origin=DeviceInfoOrigin.unknown):
|
||||
if csvfile is None:
|
||||
r = requests.get(DDB_URL)
|
||||
rows = '\n'.join(i for i in r.text.splitlines() if i[0] != '#')
|
||||
|
@ -43,7 +43,7 @@ def get_ddb(csvfile=None, address_origin=AddressOrigin.unknown):
|
|||
device_info.tracked = row[5] == 'Y'
|
||||
device_info.identified = row[6] == 'Y'
|
||||
device_info.aircraft_type = int(row[7])
|
||||
device_info.address_origin = address_origin
|
||||
device_info.address_origin = device_info_origin
|
||||
|
||||
device_infos.append(device_info)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue