kopia lustrzana https://github.com/glidernet/python-ogn-client
Added normalized_quality calculation
rodzic
ed1634603e
commit
fe0257b4aa
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
from datetime import datetime
|
||||
|
||||
from ogn.parser.utils import createTimestamp, parseAngle, KNOTS_TO_MS, KPH_TO_MS, FEETS_TO_METER, fahrenheit_to_celsius, CheapRuler
|
||||
from ogn.parser.utils import createTimestamp, parseAngle, KNOTS_TO_MS, KPH_TO_MS, FEETS_TO_METER, fahrenheit_to_celsius, CheapRuler, normalized_quality
|
||||
from ogn.parser.pattern import PATTERN_APRS, PATTERN_APRS_POSITION, PATTERN_APRS_POSITION_WEATHER, PATTERN_APRS_STATUS, PATTERN_SERVER
|
||||
from ogn.parser.exceptions import AprsParseError
|
||||
|
||||
|
@ -39,6 +39,7 @@ def parse(aprs_message, reference_timestamp=None, calculate_relations=False):
|
|||
cheap_ruler = CheapRuler((message['latitude'] + positions[message['receiver_name']][1]) / 2.0)
|
||||
message['distance'] = cheap_ruler.distance((message['longitude'], message['latitude']), positions[message['receiver_name']])
|
||||
message['bearing'] = cheap_ruler.bearing((message['longitude'], message['latitude']), positions[message['receiver_name']])
|
||||
message['normalized_quality'] = normalized_quality(message['distance'], message['signal_quality']) if 'signal_quality' in message else None
|
||||
|
||||
return message
|
||||
|
||||
|
|
|
@ -87,3 +87,9 @@ class CheapRuler():
|
|||
return 0
|
||||
result = math.atan2(-dy, dx) * 180 / MATH_PI + 90
|
||||
return result if result >= 0 else result + 360
|
||||
|
||||
|
||||
def normalized_quality(distance, signal_quality):
|
||||
"""Signal quality normalized to 10km."""
|
||||
|
||||
return signal_quality + 20.0 * math.log10(distance / 10000.0) if distance > 0 else None
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import unittest
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from ogn.parser.utils import parseAngle, createTimestamp, CheapRuler
|
||||
from ogn.parser.utils import parseAngle, createTimestamp, CheapRuler, normalized_quality
|
||||
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
|
@ -56,6 +56,11 @@ class TestStringMethods(unittest.TestCase):
|
|||
bearing = cheap_ruler.bearing(koenigsdf, hochkoenig)
|
||||
self.assertAlmostEqual(bearing, 110.761300063515)
|
||||
|
||||
def test_normalized_quality(self):
|
||||
self.assertAlmostEqual(normalized_quality(10000, 1), 1)
|
||||
self.assertAlmostEqual(normalized_quality(20000, 10), 16.020599913279625)
|
||||
self.assertAlmostEqual(normalized_quality(5000, 5), -1.0205999132796242)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Ładowanie…
Reference in New Issue