kopia lustrzana https://github.com/glidernet/python-ogn-client
Refactoring: constants
rodzic
cda1cb511b
commit
3c63cffb23
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.pattern import PATTERN_FANET_POSITION_COMMENT
|
||||
|
||||
from .base import BaseParser
|
||||
|
@ -17,4 +17,4 @@ class FanetParser(BaseParser):
|
|||
'aircraft_type': (int(ac_match.group('details'), 16) & 0b01111100) >> 2 if ac_match.group('details') else None,
|
||||
'stealth': (int(ac_match.group('details'), 16) & 0b10000000) >> 7 == 1 if ac_match.group('details') else None,
|
||||
'address': ac_match.group('address') if ac_match.group('address') else None,
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms if ac_match.group('climb_rate') else None}
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * FPM_TO_MS if ac_match.group('climb_rate') else None}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.pattern import PATTERN_FLARM_POSITION_COMMENT
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
|
||||
from .base import BaseParser
|
||||
|
||||
|
@ -17,7 +17,7 @@ class FlarmParser(BaseParser):
|
|||
'aircraft_type': (int(ac_match.group('details'), 16) & 0b01111100) >> 2,
|
||||
'stealth': (int(ac_match.group('details'), 16) & 0b10000000) >> 7 == 1,
|
||||
'address': ac_match.group('address'),
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms,
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * FPM_TO_MS,
|
||||
'turn_rate': float(ac_match.group('turn_rate')),
|
||||
'signal_quality': float(ac_match.group('signal_quality')),
|
||||
'error_count': int(ac_match.group('error_count')),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.pattern import PATTERN_LT24_POSITION_COMMENT
|
||||
|
||||
from .base import BaseParser
|
||||
|
@ -14,5 +14,5 @@ class LT24Parser(BaseParser):
|
|||
def parse_position(aprs_comment):
|
||||
ac_match = re.search(PATTERN_LT24_POSITION_COMMENT, aprs_comment)
|
||||
return {'address': ac_match.group('id'),
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms if ac_match.group('climb_rate') else None,
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * FPM_TO_MS if ac_match.group('climb_rate') else None,
|
||||
'source': ac_match.group('source') if ac_match.group('source') else None}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.pattern import PATTERN_NAVITER_POSITION_COMMENT
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
|
||||
from .base import BaseParser
|
||||
|
||||
|
@ -19,5 +19,5 @@ class NaviterParser(BaseParser):
|
|||
'address_type': (int(match.group('details'), 16) & 0b0000001111110000) >> 4,
|
||||
'reserved': (int(match.group('details'), 16) & 0b0000000000001111),
|
||||
'address': match.group('address'),
|
||||
'climb_rate': int(match.group('climb_rate')) * fpm2ms if match.group('climb_rate') else None,
|
||||
'climb_rate': int(match.group('climb_rate')) * FPM_TO_MS if match.group('climb_rate') else None,
|
||||
'turn_rate': float(match.group('turn_rate')) if match.group('turn_rate') else None}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.pattern import PATTERN_RECEIVER_BEACON, PATTERN_AIRCRAFT_BEACON
|
||||
|
||||
from .base import BaseParser
|
||||
|
@ -35,7 +35,7 @@ class OgnParser(BaseParser):
|
|||
'aircraft_type': (int(ac_match.group('details'), 16) & 0b01111100) >> 2,
|
||||
'stealth': (int(ac_match.group('details'), 16) & 0b10000000) >> 7 == 1,
|
||||
'address': ac_match.group('address'),
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms if ac_match.group('climb_rate') else None,
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * FPM_TO_MS if ac_match.group('climb_rate') else None,
|
||||
'turn_rate': float(ac_match.group('turn_rate')) if ac_match.group('turn_rate') else None,
|
||||
'flightlevel': float(ac_match.group('flight_level')) if ac_match.group('flight_level') else None,
|
||||
'signal_quality': float(ac_match.group('signal_quality')) if ac_match.group('signal_quality') else None,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.pattern import PATTERN_SKYLINES_POSITION_COMMENT
|
||||
|
||||
from .base import BaseParser
|
||||
|
@ -14,4 +14,4 @@ class SkylinesParser(BaseParser):
|
|||
def parse_position(aprs_comment):
|
||||
ac_match = re.search(PATTERN_SKYLINES_POSITION_COMMENT, aprs_comment)
|
||||
return {'address': ac_match.group('id'),
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms if ac_match.group('climb_rate') else None}
|
||||
'climb_rate': int(ac_match.group('climb_rate')) * FPM_TO_MS if ac_match.group('climb_rate') else None}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
|
||||
from ogn.parser.pattern import PATTERN_TRACKER_POSITION_COMMENT, PATTERN_TRACKER_STATUS_COMMENT
|
||||
from ogn.parser.utils import fpm2ms
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
|
||||
from .base import BaseParser
|
||||
|
||||
|
@ -17,7 +17,7 @@ class TrackerParser(BaseParser):
|
|||
'aircraft_type': (int(match.group('details'), 16) & 0b01111100) >> 2,
|
||||
'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1,
|
||||
'address': match.group('address'),
|
||||
'climb_rate': int(match.group('climb_rate')) * fpm2ms if match.group('climb_rate') else None,
|
||||
'climb_rate': int(match.group('climb_rate')) * FPM_TO_MS if match.group('climb_rate') else None,
|
||||
'turn_rate': float(match.group('turn_rate')) if match.group('turn_rate') else None,
|
||||
'flightlevel': float(match.group('flight_level')) if match.group('flight_level') else None,
|
||||
'signal_quality': float(match.group('signal_quality')) if match.group('signal_quality') else None,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
from datetime import datetime
|
||||
|
||||
from ogn.parser.utils import createTimestamp, parseAngle, kts2kmh, feet2m
|
||||
from ogn.parser.utils import createTimestamp, parseAngle, KNOTS_TO_MS, KPH_TO_MS, FEETS_TO_METER
|
||||
from ogn.parser.pattern import PATTERN_APRS, PATTERN_APRS_POSITION, PATTERN_APRS_STATUS, PATTERN_SERVER
|
||||
from ogn.parser.exceptions import AprsParseError, OgnParseError
|
||||
|
||||
|
@ -64,8 +64,8 @@ def parse_aprs(message, reference_date, reference_time=None):
|
|||
(-1 if match_position.group('longitude_sign') == 'W' else 1),
|
||||
'symbolcode': match_position.group('symbol'),
|
||||
'track': int(match_position.group('course')) if match_position.group('course_extension') else None,
|
||||
'ground_speed': int(match_position.group('ground_speed')) * kts2kmh if match_position.group('ground_speed') else None,
|
||||
'altitude': int(match_position.group('altitude')) * feet2m,
|
||||
'ground_speed': int(match_position.group('ground_speed')) * KNOTS_TO_MS / KPH_TO_MS if match_position.group('ground_speed') else None,
|
||||
'altitude': int(match_position.group('altitude')) * FEETS_TO_METER,
|
||||
'comment': match_position.group('comment') if match_position.group('comment') else "",
|
||||
'aprs_type': aprs_type}
|
||||
elif aprs_type == 'status':
|
||||
|
|
|
@ -3,13 +3,10 @@ from datetime import datetime, timedelta
|
|||
from ogn.parser.exceptions import AmbigousTimeError
|
||||
|
||||
|
||||
kmh2kts = 0.539957
|
||||
feet2m = 0.3048
|
||||
ms2fpm = 196.85
|
||||
|
||||
kts2kmh = 1 / kmh2kts
|
||||
m2feet = 1 / feet2m
|
||||
fpm2ms = 1 / ms2fpm
|
||||
FEETS_TO_METER = 0.3048 # ratio feets to meter
|
||||
FPM_TO_MS = FEETS_TO_METER / 60 # ratio fpm to m/s
|
||||
KNOTS_TO_MS = 0.5144 # ratio knots to m/s
|
||||
KPH_TO_MS = 2.7778 # ratio kph to m/s
|
||||
|
||||
|
||||
def parseAngle(dddmmhht):
|
||||
|
|
|
@ -2,7 +2,7 @@ import unittest
|
|||
|
||||
from datetime import datetime
|
||||
|
||||
from ogn.parser.utils import kts2kmh, m2feet
|
||||
from ogn.parser.utils import KNOTS_TO_MS, KPH_TO_MS, FEETS_TO_METER
|
||||
from ogn.parser.parse import parse_aprs
|
||||
from ogn.parser.exceptions import AprsParseError
|
||||
|
||||
|
@ -24,8 +24,8 @@ class TestStringMethods(unittest.TestCase):
|
|||
self.assertAlmostEqual(message['longitude'], 6.0005, 5)
|
||||
self.assertEqual(message['symbolcode'], '\'')
|
||||
self.assertEqual(message['track'], 342)
|
||||
self.assertEqual(message['ground_speed'], 49 * kts2kmh)
|
||||
self.assertAlmostEqual(message['altitude'] * m2feet, 5524, 5)
|
||||
self.assertEqual(message['ground_speed'], 49 * KNOTS_TO_MS / KPH_TO_MS)
|
||||
self.assertAlmostEqual(message['altitude'], 5524 * FEETS_TO_METER, 5)
|
||||
self.assertEqual(message['comment'], "this is a comment")
|
||||
|
||||
self.assertEqual(message['aprs_type'], 'position')
|
||||
|
@ -76,7 +76,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
raw_message = "OGNF71F40>APRS,qAS,NAVITER:/080852h4414.37N/01532.06E'253/052/A=-00013 !W73! id1EF71F40 -060fpm +0.0rot"
|
||||
message = parse_aprs(raw_message, reference_date=datetime(2015, 1, 1))
|
||||
|
||||
self.assertAlmostEqual(message['altitude'] * m2feet, -13, 5)
|
||||
self.assertAlmostEqual(message['altitude'], -13 * FEETS_TO_METER, 5)
|
||||
|
||||
def test_invalid_coordinates(self):
|
||||
# sometimes the coordinates leave their valid range: -90<=latitude<=90 or -180<=longitude<=180
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.fanet_parser import FanetParser
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
self.assertEqual(message['aircraft_type'], 7)
|
||||
self.assertFalse(message['stealth'])
|
||||
self.assertEqual(message['address'], "1103CE")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, -2, 0.1)
|
||||
self.assertAlmostEqual(message['climb_rate'], -2 * FPM_TO_MS, 0.1)
|
||||
|
||||
def test_pseudo_status_comment(self):
|
||||
message = FanetParser.parse_position("")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.flarm_parser import FlarmParser
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
self.assertEqual(message['aircraft_type'], 8)
|
||||
self.assertFalse(message['stealth'])
|
||||
self.assertEqual(message['address'], "A8CBA8")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, -39, 2)
|
||||
self.assertAlmostEqual(message['climb_rate'], -39 * FPM_TO_MS, 2)
|
||||
self.assertEqual(message['turn_rate'], 0.1)
|
||||
self.assertEqual(message['signal_quality'], 3.5)
|
||||
self.assertEqual(message['error_count'], 2)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.lt24_parser import LT24Parser
|
||||
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
def test_position_comment(self):
|
||||
message = LT24Parser.parse_position("id25387 +000fpm GPS")
|
||||
message = LT24Parser.parse_position("id25387 +123fpm GPS")
|
||||
|
||||
self.assertEqual(message['address'], "25387")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, 0, 2)
|
||||
self.assertAlmostEqual(message['climb_rate'], 123 * FPM_TO_MS, 2)
|
||||
self.assertEqual(message['source'], 'GPS')
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.naviter_parser import NaviterParser
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
self.assertEqual(message['reserved'], 0)
|
||||
self.assertEqual(message['address'], "042121")
|
||||
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, 123, 2)
|
||||
self.assertAlmostEqual(message['climb_rate'], 123 * FPM_TO_MS, 2)
|
||||
self.assertEqual(message['turn_rate'], 0.5)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.ogn_parser import OgnParser
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
self.assertEqual(message['aircraft_type'], 2)
|
||||
self.assertFalse(message['stealth'])
|
||||
self.assertEqual(message['address'], "DDA5BA")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, -454, 2)
|
||||
self.assertAlmostEqual(message['climb_rate'], -454 * FPM_TO_MS, 2)
|
||||
self.assertEqual(message['turn_rate'], -1.1)
|
||||
self.assertEqual(message['signal_quality'], 8.8)
|
||||
self.assertEqual(message['error_count'], 0)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.skylines_parser import SkylinesParser
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
message = SkylinesParser.parse_position("id2816 -015fpm")
|
||||
|
||||
self.assertEqual(message['address'], "2816")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, -15, 2)
|
||||
self.assertAlmostEqual(message['climb_rate'], -15 * FPM_TO_MS, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from ogn.parser.utils import ms2fpm
|
||||
from ogn.parser.utils import FPM_TO_MS
|
||||
from ogn.parser.aprs_comment.tracker_parser import TrackerParser
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
self.assertEqual(message['aircraft_type'], 1)
|
||||
self.assertFalse(message['stealth'])
|
||||
self.assertEqual(message['address'], "2FD00F")
|
||||
self.assertAlmostEqual(message['climb_rate'] * ms2fpm, -58, 2)
|
||||
self.assertAlmostEqual(message['climb_rate'], -58 * FPM_TO_MS, 2)
|
||||
self.assertEqual(message['turn_rate'], 1.1)
|
||||
self.assertEqual(message['flightlevel'], 3.12)
|
||||
self.assertEqual(message['signal_quality'], 32.8)
|
||||
|
|
Ładowanie…
Reference in New Issue