ogn.utils: Add get_trackable.

pull/17/head
Fabian P. Schmidt 2015-12-01 19:11:31 +01:00
rodzic 49104499d9
commit bebf11edf3
3 zmienionych plików z 28 dodań i 4 usunięć

Wyświetl plik

@ -12,6 +12,10 @@ DDB_URL = "http://ddb.glidernet.org/download"
deg2rad = pi/180
rad2deg = 1/deg2rad
address_prefixes = {'F':'FLR',
'O':'OGN',
'I':'ICA'}
def get_ddb(csvfile=None):
if csvfile is None:
@ -43,6 +47,14 @@ def get_ddb(csvfile=None):
return devices
def get_trackable(ddb):
l = []
for i in ddb:
if i.tracked and i.address_type in address_prefixes:
l.append('{}{}'.format(address_prefixes[i.address_type], i.address))
return l
def get_country_code(latitude, longitude):
geolocator = Nominatim()
location = geolocator.reverse("%f, %f" % (latitude, longitude))

Wyświetl plik

@ -1,4 +1,7 @@
#DEVICE_TYPE,DEVICE_ID,AIRCRAFT_MODEL,REGISTRATION,CN,TRACKED,IDENTIFIED
'F','DD4711','HK36 TTC','D-EULE','CU','Y','Y'
'F','DD0815','Ventus 2cxM','D-1234','','Y','Y'
'F','DD3141','Arcus T','OE-4321','','Y','Y'
'F','DD0815','Ventus 2cxM','D-1234','','Y','N'
'F','DD1234','LS 8 18m','D-8654','12','N','Y'
'F','DD3141','Arcus T','OE-4321','','N','N'
'O','DEADBE','Baloon','OE-ABC','','Y','Y'
'I','999999','A380','G-XXXL','XXL','Y','Y'

Wyświetl plik

@ -1,6 +1,6 @@
import unittest
from ogn.utils import get_ddb, get_country_code, wgs84_to_sphere
from ogn.utils import get_ddb, get_trackable, get_country_code, wgs84_to_sphere
from ogn.model import AddressOrigin
@ -11,7 +11,7 @@ class TestStringMethods(unittest.TestCase):
def test_get_ddb_from_file(self):
devices = get_ddb('tests/custom_ddb.txt')
self.assertEqual(len(devices), 3)
self.assertEqual(len(devices), 6)
device = devices[0]
self.assertEqual(device.address, 'DD4711')
@ -23,6 +23,15 @@ class TestStringMethods(unittest.TestCase):
self.assertEqual(device.address_origin, AddressOrigin.userdefined)
def test_get_trackable(self):
devices = get_ddb('tests/custom_ddb.txt')
trackable = get_trackable(devices)
self.assertEqual(len(trackable), 4)
self.assertIn('FLRDD4711', trackable)
self.assertIn('FLRDD0815', trackable)
self.assertIn('OGNDEADBE', trackable)
self.assertIn('ICA999999', trackable)
def test_get_country_code(self):
latitude = 48.0
longitude = 11.0