position --> aircraft_beacon, receiver --> receiver_beacon

pull/1/head
Konstantin Gründger 2015-11-11 18:43:39 +01:00
rodzic 95c8f5037e
commit e20e886952
9 zmienionych plików z 68 dodań i 68 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
from .model import Beacon, Position, Receiver from .model import Beacon, AircraftBeacon, ReceiverBeacon
def parse_aprs(text): def parse_aprs(text):
@ -25,6 +25,6 @@ def parse_aprs(text):
# /o: ? # /o: ?
if beacon.symboltable == "I" and beacon.symbolcode == "&": if beacon.symboltable == "I" and beacon.symbolcode == "&":
return Receiver(beacon) return ReceiverBeacon(beacon)
else: else:
return Position(beacon) return AircraftBeacon(beacon)

Wyświetl plik

@ -1,7 +1,7 @@
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
from .model import Base, Position, Receiver, Flarm from .model import Base, AircraftBeacon, ReceiverBeacon, Flarm
# prepare db # prepare db

Wyświetl plik

@ -4,21 +4,21 @@ from sqlalchemy.sql import func
from sqlalchemy import distinct, and_ from sqlalchemy import distinct, and_
from ogn.db import session from ogn.db import session
from ogn.model import Receiver from ogn.model import ReceiverBeacon
back_24h = datetime.utcnow() - timedelta(days=1) back_24h = datetime.utcnow() - timedelta(days=1)
receiver_messages_per_24h = 24*60 / 5 receiver_messages_per_24h = 24*60 / 5
def get_receiver_info(): def get_receiver_info():
sq = session.query(distinct(Receiver.name).label('name'), func.max(Receiver.timestamp).label('lastseen'), func.count(Receiver.name).label('messages_count')).\ sq = session.query(distinct(ReceiverBeacon.name).label('name'), func.max(ReceiverBeacon.timestamp).label('lastseen'), func.count(ReceiverBeacon.name).label('messages_count')).\
filter(Receiver.timestamp > back_24h).\ filter(ReceiverBeacon.timestamp > back_24h).\
group_by(Receiver.name).\ group_by(ReceiverBeacon.name).\
subquery() subquery()
query = session.query(Receiver, sq.c.messages_count).\ query = session.query(ReceiverBeacon, sq.c.messages_count).\
filter(and_(Receiver.name == sq.c.name, Receiver.timestamp == sq.c.lastseen)).\ filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)).\
order_by(Receiver.name) order_by(ReceiverBeacon.name)
print('--- Receivers ---') print('--- Receivers ---')
for [receiver, messages_count] in query.all(): for [receiver, messages_count] in query.all():
@ -26,15 +26,15 @@ def get_receiver_info():
def get_software_stats(): def get_software_stats():
sq = session.query(Receiver.name, func.max(Receiver.timestamp).label('lastseen')).\ sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')).\
filter(Receiver.timestamp > back_24h).\ filter(ReceiverBeacon.timestamp > back_24h).\
group_by(Receiver.name).\ group_by(ReceiverBeacon.name).\
subquery() subquery()
versions = session.query(distinct(Receiver.version), func.count(Receiver.version)).\ versions = session.query(distinct(ReceiverBeacon.version), func.count(ReceiverBeacon.version)).\
filter(and_(Receiver.name == sq.c.name, Receiver.timestamp == sq.c.lastseen)).\ filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)).\
group_by(Receiver.version).\ group_by(ReceiverBeacon.version).\
order_by(Receiver.version) order_by(ReceiverBeacon.version)
print('\n--- Versions ---') print('\n--- Versions ---')
for [version, count] in versions.all(): for [version, count] in versions.all():
@ -42,15 +42,15 @@ def get_software_stats():
def get_hardware_stats(): def get_hardware_stats():
sq = session.query(Receiver.name, func.max(Receiver.timestamp).label('lastseen')).\ sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')).\
filter(Receiver.timestamp > back_24h).\ filter(ReceiverBeacon.timestamp > back_24h).\
group_by(Receiver.name).\ group_by(ReceiverBeacon.name).\
subquery() subquery()
platforms = session.query(distinct(Receiver.platform), func.count(Receiver.platform)).\ platforms = session.query(distinct(ReceiverBeacon.platform), func.count(ReceiverBeacon.platform)).\
filter(and_(Receiver.name == sq.c.name, Receiver.timestamp == sq.c.lastseen)).\ filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)).\
group_by(Receiver.platform).\ group_by(ReceiverBeacon.platform).\
order_by(Receiver.platform) order_by(ReceiverBeacon.platform)
print('\n--- Platforms ---') print('\n--- Platforms ---')
for [platform, count] in platforms.all(): for [platform, count] in platforms.all():

Wyświetl plik

@ -5,7 +5,7 @@ from sqlalchemy import and_, or_, insert, between
from sqlalchemy.sql.expression import case, true, false, label from sqlalchemy.sql.expression import case, true, false, label
from ogn.db import session from ogn.db import session
from ogn.model import Flarm, Position, TakeoffLanding from ogn.model import Flarm, AircraftBeacon, TakeoffLanding
def compute_takeoff_and_landing(): def compute_takeoff_and_landing():
@ -19,30 +19,30 @@ def compute_takeoff_and_landing():
last_takeoff_landing = datetime(2015, 1, 1, 0, 0, 0) last_takeoff_landing = datetime(2015, 1, 1, 0, 0, 0)
# make a query with current, previous and next position, so we can detect takeoffs and landings # make a query with current, previous and next position, so we can detect takeoffs and landings
sq = session.query(Position.address, sq = session.query(AircraftBeacon.address,
func.lag(Position.address).over(order_by=and_(Position.address, Position.timestamp)).label('address_prev'), func.lag(AircraftBeacon.address).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('address_prev'),
func.lead(Position.address).over(order_by=and_(Position.address, Position.timestamp)).label('address_next'), func.lead(AircraftBeacon.address).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('address_next'),
Position.timestamp, AircraftBeacon.timestamp,
func.lag(Position.timestamp).over(order_by=and_(Position.address, Position.timestamp)).label('timestamp_prev'), func.lag(AircraftBeacon.timestamp).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('timestamp_prev'),
func.lead(Position.timestamp).over(order_by=and_(Position.address, Position.timestamp)).label('timestamp_next'), func.lead(AircraftBeacon.timestamp).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('timestamp_next'),
Position.latitude, AircraftBeacon.latitude,
func.lag(Position.latitude).over(order_by=and_(Position.address, Position.timestamp)).label('latitude_prev'), func.lag(AircraftBeacon.latitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('latitude_prev'),
func.lead(Position.latitude).over(order_by=and_(Position.address, Position.timestamp)).label('latitude_next'), func.lead(AircraftBeacon.latitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('latitude_next'),
Position.longitude, AircraftBeacon.longitude,
func.lag(Position.longitude).over(order_by=and_(Position.address, Position.timestamp)).label('longitude_prev'), func.lag(AircraftBeacon.longitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('longitude_prev'),
func.lead(Position.longitude).over(order_by=and_(Position.address, Position.timestamp)).label('longitude_next'), func.lead(AircraftBeacon.longitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('longitude_next'),
Position.ground_speed, AircraftBeacon.ground_speed,
Position.track, AircraftBeacon.track,
func.lag(Position.track).over(order_by=and_(Position.address, Position.timestamp)).label('track_prev'), func.lag(AircraftBeacon.track).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('track_prev'),
func.lead(Position.track).over(order_by=and_(Position.address, Position.timestamp)).label('track_next'), func.lead(AircraftBeacon.track).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('track_next'),
Position.ground_speed, AircraftBeacon.ground_speed,
func.lag(Position.ground_speed).over(order_by=and_(Position.address, Position.timestamp)).label('ground_speed_prev'), func.lag(AircraftBeacon.ground_speed).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('ground_speed_prev'),
func.lead(Position.ground_speed).over(order_by=and_(Position.address, Position.timestamp)).label('ground_speed_next'), func.lead(AircraftBeacon.ground_speed).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('ground_speed_next'),
Position.altitude, AircraftBeacon.altitude,
func.lag(Position.altitude).over(order_by=and_(Position.address, Position.timestamp)).label('altitude_prev'), func.lag(AircraftBeacon.altitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('altitude_prev'),
func.lead(Position.altitude).over(order_by=and_(Position.address, Position.timestamp)).label('altitude_next')) \ func.lead(AircraftBeacon.altitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('altitude_next')) \
.filter(Position.timestamp > last_takeoff_landing) \ .filter(AircraftBeacon.timestamp > last_takeoff_landing) \
.order_by(func.date(Position.timestamp), Position.address, Position.timestamp) \ .order_by(func.date(AircraftBeacon.timestamp), AircraftBeacon.address, AircraftBeacon.timestamp) \
.subquery() .subquery()
# find takeoffs and landings (look at the trigger_speed) # find takeoffs and landings (look at the trigger_speed)

Wyświetl plik

@ -3,6 +3,6 @@ from .aircraft_type import AircraftType
from .base import Base from .base import Base
from .beacon import Beacon from .beacon import Beacon
from .flarm import Flarm from .flarm import Flarm
from .position import Position from ogn.model.aircraft_beacon import AircraftBeacon
from .receiver import Receiver from ogn.model.receiver_beacon import ReceiverBeacon
from .takeoff_landing import TakeoffLanding from .takeoff_landing import TakeoffLanding

Wyświetl plik

@ -6,8 +6,8 @@ from ogn.aprs_utils import fpm2ms
from .beacon import Beacon from .beacon import Beacon
class Position(Beacon): class AircraftBeacon(Beacon):
__tablename__ = "position" __tablename__ = "aircraft_beacon"
# Flarm specific data # Flarm specific data
address_type = Column(SmallInteger) address_type = Column(SmallInteger)
@ -125,4 +125,4 @@ class Position(Beacon):
raise Exception("No valid position description: %s" % part) raise Exception("No valid position description: %s" % part)
def __repr__(self): def __repr__(self):
return("<Position %s: %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s>" % (self.name, self.address_type, self.aircraft_type, self.timestamp, self.address_type, self.aircraft_type, self.stealth, self.address, self.climb_rate, self.turn_rate, self.signal_strength, self.error_count, self.frequency_offset, self.gps_status)) return("<AircraftBeacon %s: %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s>" % (self.name, self.address_type, self.aircraft_type, self.timestamp, self.address_type, self.aircraft_type, self.stealth, self.address, self.climb_rate, self.turn_rate, self.signal_strength, self.error_count, self.frequency_offset, self.gps_status))

Wyświetl plik

@ -5,10 +5,10 @@ from sqlalchemy import Column, String
from .beacon import Beacon from .beacon import Beacon
class Receiver(Beacon): class ReceiverBeacon(Beacon):
__tablename__ = "receiver" __tablename__ = "receiver_beacon"
# Receiver specific data # ReceiverBeacon specific data
version = Column(String) version = Column(String)
platform = Column(String) platform = Column(String)
cpu_load = 0 cpu_load = 0
@ -85,4 +85,4 @@ class Receiver(Beacon):
raise Exception("No valid receiver description: %s" % part) raise Exception("No valid receiver description: %s" % part)
def __repr__(self): def __repr__(self):
return("<Receiver %s: %s>" % (self.name, self.version)) return("<ReceiverBeacon %s: %s>" % (self.name, self.version))

Wyświetl plik

@ -2,12 +2,12 @@ import unittest
from ogn.aprs_utils import ms2fpm from ogn.aprs_utils import ms2fpm
from ogn.model.beacon import Beacon from ogn.model.beacon import Beacon
from ogn.model.position import Position from ogn.model.aircraft_beacon import AircraftBeacon
class TestStringMethods(unittest.TestCase): class TestStringMethods(unittest.TestCase):
def test_basic(self): def test_basic(self):
position = Position() position = AircraftBeacon()
position.parse("id0ADDA5BA -454fpm -1.1rot 8.8dB 0e +51.2kHz gps4x5 hear1084 hearB597 hearB598") position.parse("id0ADDA5BA -454fpm -1.1rot 8.8dB 0e +51.2kHz gps4x5 hear1084 hearB597 hearB598")
self.assertFalse(position.stealth) self.assertFalse(position.stealth)
@ -25,7 +25,7 @@ class TestStringMethods(unittest.TestCase):
self.assertEqual(position.heared_aircraft_IDs[2], 'B598') self.assertEqual(position.heared_aircraft_IDs[2], 'B598')
def test_stealth(self): def test_stealth(self):
position = Position() position = AircraftBeacon()
position.parse("id0ADD1234") position.parse("id0ADD1234")
self.assertFalse(position.stealth) self.assertFalse(position.stealth)
@ -33,7 +33,7 @@ class TestStringMethods(unittest.TestCase):
self.assertTrue(position.stealth) self.assertTrue(position.stealth)
def test_v024(self): def test_v024(self):
position = Position() position = AircraftBeacon()
position.parse("!W26! id21400EA9 -2454fpm +0.9rot 19.5dB 0e -6.6kHz gps1x1 s6.02 h44 rDF0C56") position.parse("!W26! id21400EA9 -2454fpm +0.9rot 19.5dB 0e -6.6kHz gps1x1 s6.02 h44 rDF0C56")
self.assertEqual(position.latitude, 0.002) self.assertEqual(position.latitude, 0.002)
@ -43,7 +43,7 @@ class TestStringMethods(unittest.TestCase):
self.assertEqual(position.real_id, "DF0C56") self.assertEqual(position.real_id, "DF0C56")
def test_v024_ogn_tracker(self): def test_v024_ogn_tracker(self):
position = Position() position = AircraftBeacon()
position.parse("!W34! id07353800 +020fpm -14.0rot FL004.43 38.5dB 0e -2.9kHz") position.parse("!W34! id07353800 +020fpm -14.0rot FL004.43 38.5dB 0e -2.9kHz")
self.assertEqual(position.flightlevel, 4.43) self.assertEqual(position.flightlevel, 4.43)
@ -51,7 +51,7 @@ class TestStringMethods(unittest.TestCase):
def test_copy_constructor(self): def test_copy_constructor(self):
beacon = Beacon() beacon = Beacon()
beacon.parse("FLRDDA5BA>APRS,qAS,LFMX:/160829h4415.41N/00600.03E'342/049/A=005524 id0ADDA5BA -454fpm -1.1rot 8.8dB 0e +51.2kHz gps4x5") beacon.parse("FLRDDA5BA>APRS,qAS,LFMX:/160829h4415.41N/00600.03E'342/049/A=005524 id0ADDA5BA -454fpm -1.1rot 8.8dB 0e +51.2kHz gps4x5")
position = Position(beacon) position = AircraftBeacon(beacon)
self.assertEqual(position.name, 'FLRDDA5BA') self.assertEqual(position.name, 'FLRDDA5BA')
self.assertEqual(position.address, 'DDA5BA') self.assertEqual(position.address, 'DDA5BA')

Wyświetl plik

@ -1,11 +1,11 @@
import unittest import unittest
from ogn.model.receiver import Receiver from ogn.model.receiver_beacon import ReceiverBeacon
class TestStringMethods(unittest.TestCase): class TestStringMethods(unittest.TestCase):
def test_v022(self): def test_v022(self):
receiver = Receiver() receiver = ReceiverBeacon()
receiver.parse("v0.2.2.x86 CPU:0.5 RAM:669.9/887.7MB NTP:1.0ms/+6.2ppm +52.0C RF:+0.06dB") receiver.parse("v0.2.2.x86 CPU:0.5 RAM:669.9/887.7MB NTP:1.0ms/+6.2ppm +52.0C RF:+0.06dB")
self.assertEqual(receiver.version, '0.2.2') self.assertEqual(receiver.version, '0.2.2')
@ -20,7 +20,7 @@ class TestStringMethods(unittest.TestCase):
self.assertEqual(receiver.rec_input_noise, 0.06) self.assertEqual(receiver.rec_input_noise, 0.06)
def test_v021(self): def test_v021(self):
receiver = Receiver() receiver = ReceiverBeacon()
receiver.parse("v0.2.1 CPU:0.8 RAM:25.6/458.9MB NTP:0.0ms/+0.0ppm +51.9C RF:+26-1.4ppm/-0.25dB") receiver.parse("v0.2.1 CPU:0.8 RAM:25.6/458.9MB NTP:0.0ms/+0.0ppm +51.9C RF:+26-1.4ppm/-0.25dB")
self.assertEqual(receiver.rec_crystal_correction, 26) self.assertEqual(receiver.rec_crystal_correction, 26)