# Path: ogn/parser/utils.py
# FPM_TO_MS = FEETS_TO_METER / 60     # ratio fpm to m/s
# 
# HPM_TO_DEGS = 180 / 60              # ratio between half turn per minute and degrees/s
# 
# Path: ogn/parser/aprs_comment/flarm_parser.py
# class FlarmParser(BaseParser):
#     def __init__(self):
#         self.beacon_type = 'flarm'
#         self.position_pattern = PATTERN_FLARM_POSITION_COMMENT
# 
#     def parse_position(self, aprs_comment):
#         match = self.position_pattern.match(aprs_comment)
# 
#         result = {}
#         if match.group('details'):
#             result.update({
#                 'address_type': int(match.group('details'), 16) & 0b00000011,
#                 'aircraft_type': (int(match.group('details'), 16) & 0b00111100) >> 2,
#                 'no-tracking': (int(match.group('details'), 16) & 0b01000000) >> 6 == 1,
#                 'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1,
#                 'address': match.group('address'),
#             })
#         if match.group('climb_rate'): result['climb_rate'] = int(match.group('climb_rate')) * FPM_TO_MS
#         if match.group('turn_rate'): result['turn_rate'] = float(match.group('turn_rate')) * HPM_TO_DEGS
#         if match.group('signal_quality'): result['signal_quality'] = float(match.group('signal_quality'))
#         if match.group('error_count'): result['error_count'] = int(match.group('error_count'))
#         if match.group('frequency_offset'): result['frequency_offset'] = float(match.group('frequency_offset'))
#         if match.group('gps_quality'):
#             result.update({
#                 'gps_quality': {
#                     'horizontal': int(match.group('gps_quality_horizontal')),
#                     'vertical': int(match.group('gps_quality_vertical'))
#                 }
#             })
#         if match.group('software_version'): result['software_version'] = float(match.group('software_version'))
#         if match.group('hardware_version'): result['hardware_version'] = int(match.group('hardware_version'), 16)
#         if match.group('real_address'): result['real_address'] = match.group('real_address')
#         if match.group('signal_power'): result['signal_power'] = float(match.group('signal_power'))
#         return result


import unittest
from ogn.parser.utils import FPM_TO_MS, HPM_TO_DEGS
from ogn.parser.aprs_comment.flarm_parser import FlarmParser



class TestStringMethods(unittest.TestCase):
    def test_position_comment(self):
        message = FlarmParser().parse_position("id21A8CBA8 -039fpm +0.1rot 3.5dB 2e -8.7kHz gps1x2 s6.09 h43 rDF0267")

        self.assertEqual(message['address_type'], 1)
        self.assertEqual(message['aircraft_type'], 8)
        self.assertFalse(message['stealth'])
        self.assertFalse(message['no-tracking'])
        self.assertEqual(message['address'], "A8CBA8")
        self.assertAlmostEqual(message['climb_rate'], -39 * FPM_TO_MS, 2)
        self.assertEqual(message['turn_rate'], 0.1 * HPM_TO_DEGS)
        self.assertEqual(message['signal_quality'], 3.5)
        self.assertEqual(message['error_count'], 2)
        self.assertEqual(message['frequency_offset'], -8.7)
        self.assertEqual(message['gps_quality'], {'horizontal': 1, 'vertical': 2})
        self.assertEqual(message['software_version'], 6.09)
        self.assertEqual(message['hardware_version'], 67)
        self.assertEqual(message['real_address'], "DF0267")

    def test_position_comment_relevant_keys_only(self):
        # return only keys where we got informations

# Path: ogn/parser/utils.py
# FPM_TO_MS = FEETS_TO_METER / 60     # ratio fpm to m/s
# 
# HPM_TO_DEGS = 180 / 60              # ratio between half turn per minute and degrees/s
# 
# Path: ogn/parser/aprs_comment/flarm_parser.py
# class FlarmParser(BaseParser):
#     def __init__(self):
#         self.beacon_type = 'flarm'
#         self.position_pattern = PATTERN_FLARM_POSITION_COMMENT
# 
#     def parse_position(self, aprs_comment):
#         match = self.position_pattern.match(aprs_comment)
# 
#         result = {}
#         if match.group('details'):
#             result.update({
#                 'address_type': int(match.group('details'), 16) & 0b00000011,
#                 'aircraft_type': (int(match.group('details'), 16) & 0b00111100) >> 2,
#                 'no-tracking': (int(match.group('details'), 16) & 0b01000000) >> 6 == 1,
#                 'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1,
#                 'address': match.group('address'),
#             })
#         if match.group('climb_rate'): result['climb_rate'] = int(match.group('climb_rate')) * FPM_TO_MS
#         if match.group('turn_rate'): result['turn_rate'] = float(match.group('turn_rate')) * HPM_TO_DEGS
#         if match.group('signal_quality'): result['signal_quality'] = float(match.group('signal_quality'))
#         if match.group('error_count'): result['error_count'] = int(match.group('error_count'))
#         if match.group('frequency_offset'): result['frequency_offset'] = float(match.group('frequency_offset'))
#         if match.group('gps_quality'):
#             result.update({
#                 'gps_quality': {
#                     'horizontal': int(match.group('gps_quality_horizontal')),
#                     'vertical': int(match.group('gps_quality_vertical'))
#                 }
#             })
#         if match.group('software_version'): result['software_version'] = float(match.group('software_version'))
#         if match.group('hardware_version'): result['hardware_version'] = int(match.group('hardware_version'), 16)
#         if match.group('real_address'): result['real_address'] = match.group('real_address')
#         if match.group('signal_power'): result['signal_power'] = float(match.group('signal_power'))
#         return result


# Path: tests/parser/test_parse_flarm.py
import unittest
from ogn.parser.utils import FPM_TO_MS, HPM_TO_DEGS
from ogn.parser.aprs_comment.flarm_parser import FlarmParser




class TestStringMethods(unittest.TestCase):
    def test_position_comment(self):
        message = FlarmParser().parse_position("id21A8CBA8 -039fpm +0.1rot 3.5dB 2e -8.7kHz gps1x2 s6.09 h43 rDF0267")

        self.assertEqual(message['address_type'], 1)
        self.assertEqual(message['aircraft_type'], 8)
        self.assertFalse(message['stealth'])
        self.assertFalse(message['no-tracking'])
        self.assertEqual(message['address'], "A8CBA8")
        self.assertAlmostEqual(message['climb_rate'], -39 * FPM_TO_MS, 2)
        self.assertEqual(message['turn_rate'], 0.1 * HPM_TO_DEGS)
        self.assertEqual(message['signal_quality'], 3.5)
        self.assertEqual(message['error_count'], 2)
        self.assertEqual(message['frequency_offset'], -8.7)
        self.assertEqual(message['gps_quality'], {'horizontal': 1, 'vertical': 2})
        self.assertEqual(message['software_version'], 6.09)
        self.assertEqual(message['hardware_version'], 67)
        self.assertEqual(message['real_address'], "DF0267")

    def test_position_comment_relevant_keys_only(self):
        # return only keys where we got informations

        message = FlarmParser().parse_position("id21A8CBA8")