From e20e88695216f63057ee97c3c4ef2eac6c49f20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Wed, 11 Nov 2015 18:43:39 +0100 Subject: [PATCH] position --> aircraft_beacon, receiver --> receiver_beacon --- ogn/aprs_parser.py | 6 +-- ogn/db.py | 2 +- ogn/db_analysis.py | 42 ++++++++-------- ogn/logbook.py | 50 +++++++++---------- ogn/model/__init__.py | 4 +- ogn/model/{position.py => aircraft_beacon.py} | 6 +-- ogn/model/{receiver.py => receiver_beacon.py} | 8 +-- ...st_position.py => test_aircraft_beacon.py} | 12 ++--- ...st_receiver.py => test_receiver_beacon.py} | 6 +-- 9 files changed, 68 insertions(+), 68 deletions(-) rename ogn/model/{position.py => aircraft_beacon.py} (93%) rename ogn/model/{receiver.py => receiver_beacon.py} (95%) rename tests/model/{test_position.py => test_aircraft_beacon.py} (89%) rename tests/model/{test_receiver.py => test_receiver_beacon.py} (89%) diff --git a/ogn/aprs_parser.py b/ogn/aprs_parser.py index e4915f1..3cdea88 100644 --- a/ogn/aprs_parser.py +++ b/ogn/aprs_parser.py @@ -1,4 +1,4 @@ -from .model import Beacon, Position, Receiver +from .model import Beacon, AircraftBeacon, ReceiverBeacon def parse_aprs(text): @@ -25,6 +25,6 @@ def parse_aprs(text): # /o: ? if beacon.symboltable == "I" and beacon.symbolcode == "&": - return Receiver(beacon) + return ReceiverBeacon(beacon) else: - return Position(beacon) + return AircraftBeacon(beacon) diff --git a/ogn/db.py b/ogn/db.py index 3266b38..69fd212 100644 --- a/ogn/db.py +++ b/ogn/db.py @@ -1,7 +1,7 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from .model import Base, Position, Receiver, Flarm +from .model import Base, AircraftBeacon, ReceiverBeacon, Flarm # prepare db diff --git a/ogn/db_analysis.py b/ogn/db_analysis.py index 00bea07..b9d9bfa 100644 --- a/ogn/db_analysis.py +++ b/ogn/db_analysis.py @@ -4,21 +4,21 @@ from sqlalchemy.sql import func from sqlalchemy import distinct, and_ from ogn.db import session -from ogn.model import Receiver +from ogn.model import ReceiverBeacon back_24h = datetime.utcnow() - timedelta(days=1) receiver_messages_per_24h = 24*60 / 5 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')).\ - filter(Receiver.timestamp > back_24h).\ - group_by(Receiver.name).\ + sq = session.query(distinct(ReceiverBeacon.name).label('name'), func.max(ReceiverBeacon.timestamp).label('lastseen'), func.count(ReceiverBeacon.name).label('messages_count')).\ + filter(ReceiverBeacon.timestamp > back_24h).\ + group_by(ReceiverBeacon.name).\ subquery() - query = session.query(Receiver, sq.c.messages_count).\ - filter(and_(Receiver.name == sq.c.name, Receiver.timestamp == sq.c.lastseen)).\ - order_by(Receiver.name) + query = session.query(ReceiverBeacon, sq.c.messages_count).\ + filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)).\ + order_by(ReceiverBeacon.name) print('--- Receivers ---') for [receiver, messages_count] in query.all(): @@ -26,15 +26,15 @@ def get_receiver_info(): def get_software_stats(): - sq = session.query(Receiver.name, func.max(Receiver.timestamp).label('lastseen')).\ - filter(Receiver.timestamp > back_24h).\ - group_by(Receiver.name).\ + sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')).\ + filter(ReceiverBeacon.timestamp > back_24h).\ + group_by(ReceiverBeacon.name).\ subquery() - versions = session.query(distinct(Receiver.version), func.count(Receiver.version)).\ - filter(and_(Receiver.name == sq.c.name, Receiver.timestamp == sq.c.lastseen)).\ - group_by(Receiver.version).\ - order_by(Receiver.version) + versions = session.query(distinct(ReceiverBeacon.version), func.count(ReceiverBeacon.version)).\ + filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)).\ + group_by(ReceiverBeacon.version).\ + order_by(ReceiverBeacon.version) print('\n--- Versions ---') for [version, count] in versions.all(): @@ -42,15 +42,15 @@ def get_software_stats(): def get_hardware_stats(): - sq = session.query(Receiver.name, func.max(Receiver.timestamp).label('lastseen')).\ - filter(Receiver.timestamp > back_24h).\ - group_by(Receiver.name).\ + sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')).\ + filter(ReceiverBeacon.timestamp > back_24h).\ + group_by(ReceiverBeacon.name).\ subquery() - platforms = session.query(distinct(Receiver.platform), func.count(Receiver.platform)).\ - filter(and_(Receiver.name == sq.c.name, Receiver.timestamp == sq.c.lastseen)).\ - group_by(Receiver.platform).\ - order_by(Receiver.platform) + platforms = session.query(distinct(ReceiverBeacon.platform), func.count(ReceiverBeacon.platform)).\ + filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)).\ + group_by(ReceiverBeacon.platform).\ + order_by(ReceiverBeacon.platform) print('\n--- Platforms ---') for [platform, count] in platforms.all(): diff --git a/ogn/logbook.py b/ogn/logbook.py index 2bb8380..ffbfcba 100644 --- a/ogn/logbook.py +++ b/ogn/logbook.py @@ -5,7 +5,7 @@ from sqlalchemy import and_, or_, insert, between from sqlalchemy.sql.expression import case, true, false, label from ogn.db import session -from ogn.model import Flarm, Position, TakeoffLanding +from ogn.model import Flarm, AircraftBeacon, TakeoffLanding def compute_takeoff_and_landing(): @@ -19,30 +19,30 @@ def compute_takeoff_and_landing(): 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 - sq = session.query(Position.address, - func.lag(Position.address).over(order_by=and_(Position.address, Position.timestamp)).label('address_prev'), - func.lead(Position.address).over(order_by=and_(Position.address, Position.timestamp)).label('address_next'), - Position.timestamp, - func.lag(Position.timestamp).over(order_by=and_(Position.address, Position.timestamp)).label('timestamp_prev'), - func.lead(Position.timestamp).over(order_by=and_(Position.address, Position.timestamp)).label('timestamp_next'), - Position.latitude, - func.lag(Position.latitude).over(order_by=and_(Position.address, Position.timestamp)).label('latitude_prev'), - func.lead(Position.latitude).over(order_by=and_(Position.address, Position.timestamp)).label('latitude_next'), - Position.longitude, - func.lag(Position.longitude).over(order_by=and_(Position.address, Position.timestamp)).label('longitude_prev'), - func.lead(Position.longitude).over(order_by=and_(Position.address, Position.timestamp)).label('longitude_next'), - Position.ground_speed, - Position.track, - func.lag(Position.track).over(order_by=and_(Position.address, Position.timestamp)).label('track_prev'), - func.lead(Position.track).over(order_by=and_(Position.address, Position.timestamp)).label('track_next'), - Position.ground_speed, - func.lag(Position.ground_speed).over(order_by=and_(Position.address, Position.timestamp)).label('ground_speed_prev'), - func.lead(Position.ground_speed).over(order_by=and_(Position.address, Position.timestamp)).label('ground_speed_next'), - Position.altitude, - func.lag(Position.altitude).over(order_by=and_(Position.address, Position.timestamp)).label('altitude_prev'), - func.lead(Position.altitude).over(order_by=and_(Position.address, Position.timestamp)).label('altitude_next')) \ - .filter(Position.timestamp > last_takeoff_landing) \ - .order_by(func.date(Position.timestamp), Position.address, Position.timestamp) \ + sq = session.query(AircraftBeacon.address, + func.lag(AircraftBeacon.address).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('address_prev'), + func.lead(AircraftBeacon.address).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('address_next'), + AircraftBeacon.timestamp, + func.lag(AircraftBeacon.timestamp).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('timestamp_prev'), + func.lead(AircraftBeacon.timestamp).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('timestamp_next'), + AircraftBeacon.latitude, + func.lag(AircraftBeacon.latitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('latitude_prev'), + func.lead(AircraftBeacon.latitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('latitude_next'), + AircraftBeacon.longitude, + func.lag(AircraftBeacon.longitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('longitude_prev'), + func.lead(AircraftBeacon.longitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('longitude_next'), + AircraftBeacon.ground_speed, + AircraftBeacon.track, + func.lag(AircraftBeacon.track).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('track_prev'), + func.lead(AircraftBeacon.track).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('track_next'), + AircraftBeacon.ground_speed, + func.lag(AircraftBeacon.ground_speed).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('ground_speed_prev'), + func.lead(AircraftBeacon.ground_speed).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('ground_speed_next'), + AircraftBeacon.altitude, + func.lag(AircraftBeacon.altitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('altitude_prev'), + func.lead(AircraftBeacon.altitude).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('altitude_next')) \ + .filter(AircraftBeacon.timestamp > last_takeoff_landing) \ + .order_by(func.date(AircraftBeacon.timestamp), AircraftBeacon.address, AircraftBeacon.timestamp) \ .subquery() # find takeoffs and landings (look at the trigger_speed) diff --git a/ogn/model/__init__.py b/ogn/model/__init__.py index 8bc7ccf..2f95373 100644 --- a/ogn/model/__init__.py +++ b/ogn/model/__init__.py @@ -3,6 +3,6 @@ from .aircraft_type import AircraftType from .base import Base from .beacon import Beacon from .flarm import Flarm -from .position import Position -from .receiver import Receiver +from ogn.model.aircraft_beacon import AircraftBeacon +from ogn.model.receiver_beacon import ReceiverBeacon from .takeoff_landing import TakeoffLanding diff --git a/ogn/model/position.py b/ogn/model/aircraft_beacon.py similarity index 93% rename from ogn/model/position.py rename to ogn/model/aircraft_beacon.py index 58094a1..2edeb31 100644 --- a/ogn/model/position.py +++ b/ogn/model/aircraft_beacon.py @@ -6,8 +6,8 @@ from ogn.aprs_utils import fpm2ms from .beacon import Beacon -class Position(Beacon): - __tablename__ = "position" +class AircraftBeacon(Beacon): + __tablename__ = "aircraft_beacon" # Flarm specific data address_type = Column(SmallInteger) @@ -125,4 +125,4 @@ class Position(Beacon): raise Exception("No valid position description: %s" % part) def __repr__(self): - return("" % (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("" % (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)) diff --git a/ogn/model/receiver.py b/ogn/model/receiver_beacon.py similarity index 95% rename from ogn/model/receiver.py rename to ogn/model/receiver_beacon.py index 1000665..4d3e892 100644 --- a/ogn/model/receiver.py +++ b/ogn/model/receiver_beacon.py @@ -5,10 +5,10 @@ from sqlalchemy import Column, String from .beacon import Beacon -class Receiver(Beacon): - __tablename__ = "receiver" +class ReceiverBeacon(Beacon): + __tablename__ = "receiver_beacon" - # Receiver specific data + # ReceiverBeacon specific data version = Column(String) platform = Column(String) cpu_load = 0 @@ -85,4 +85,4 @@ class Receiver(Beacon): raise Exception("No valid receiver description: %s" % part) def __repr__(self): - return("" % (self.name, self.version)) + return("" % (self.name, self.version)) diff --git a/tests/model/test_position.py b/tests/model/test_aircraft_beacon.py similarity index 89% rename from tests/model/test_position.py rename to tests/model/test_aircraft_beacon.py index b958554..6d5cfd0 100644 --- a/tests/model/test_position.py +++ b/tests/model/test_aircraft_beacon.py @@ -2,12 +2,12 @@ import unittest from ogn.aprs_utils import ms2fpm from ogn.model.beacon import Beacon -from ogn.model.position import Position +from ogn.model.aircraft_beacon import AircraftBeacon class TestStringMethods(unittest.TestCase): def test_basic(self): - position = Position() + position = AircraftBeacon() position.parse("id0ADDA5BA -454fpm -1.1rot 8.8dB 0e +51.2kHz gps4x5 hear1084 hearB597 hearB598") self.assertFalse(position.stealth) @@ -25,7 +25,7 @@ class TestStringMethods(unittest.TestCase): self.assertEqual(position.heared_aircraft_IDs[2], 'B598') def test_stealth(self): - position = Position() + position = AircraftBeacon() position.parse("id0ADD1234") self.assertFalse(position.stealth) @@ -33,7 +33,7 @@ class TestStringMethods(unittest.TestCase): self.assertTrue(position.stealth) 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") self.assertEqual(position.latitude, 0.002) @@ -43,7 +43,7 @@ class TestStringMethods(unittest.TestCase): self.assertEqual(position.real_id, "DF0C56") def test_v024_ogn_tracker(self): - position = Position() + position = AircraftBeacon() position.parse("!W34! id07353800 +020fpm -14.0rot FL004.43 38.5dB 0e -2.9kHz") self.assertEqual(position.flightlevel, 4.43) @@ -51,7 +51,7 @@ class TestStringMethods(unittest.TestCase): def test_copy_constructor(self): 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") - position = Position(beacon) + position = AircraftBeacon(beacon) self.assertEqual(position.name, 'FLRDDA5BA') self.assertEqual(position.address, 'DDA5BA') diff --git a/tests/model/test_receiver.py b/tests/model/test_receiver_beacon.py similarity index 89% rename from tests/model/test_receiver.py rename to tests/model/test_receiver_beacon.py index 4eb6b97..c687779 100644 --- a/tests/model/test_receiver.py +++ b/tests/model/test_receiver_beacon.py @@ -1,11 +1,11 @@ import unittest -from ogn.model.receiver import Receiver +from ogn.model.receiver_beacon import ReceiverBeacon class TestStringMethods(unittest.TestCase): 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") self.assertEqual(receiver.version, '0.2.2') @@ -20,7 +20,7 @@ class TestStringMethods(unittest.TestCase): self.assertEqual(receiver.rec_input_noise, 0.06) 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") self.assertEqual(receiver.rec_crystal_correction, 26)