From ffa6c8b1f04f646e0389fa4aef020992dfb89148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Sun, 4 Oct 2020 12:25:02 +0200 Subject: [PATCH] Refactoring --- ogn/parser/aprs_comment/receiver_parser.py | 45 ++++++++++++---------- ogn/parser/aprs_comment/spider_parser.py | 10 ++--- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/ogn/parser/aprs_comment/receiver_parser.py b/ogn/parser/aprs_comment/receiver_parser.py index c47d3f1..9fd10e9 100644 --- a/ogn/parser/aprs_comment/receiver_parser.py +++ b/ogn/parser/aprs_comment/receiver_parser.py @@ -18,23 +18,28 @@ class ReceiverParser(BaseParser): def parse_status(self, aprs_comment): match = self.status_pattern.match(aprs_comment) - return {'version': match.group('version'), - 'platform': match.group('platform'), - 'cpu_load': float(match.group('cpu_load')), - 'free_ram': float(match.group('ram_free')), - 'total_ram': float(match.group('ram_total')), - 'ntp_error': float(match.group('ntp_offset')), - 'rt_crystal_correction': float(match.group('ntp_correction')), - 'voltage': float(match.group('voltage')) if match.group('voltage') else None, - 'amperage': float(match.group('amperage')) if match.group('amperage') else None, - 'cpu_temp': float(match.group('cpu_temperature')) if match.group('cpu_temperature') else None, - 'senders_visible': int(match.group('visible_senders')) if match.group('visible_senders') else None, - 'senders_total': int(match.group('senders')) if match.group('senders') else None, - 'rec_crystal_correction': int(match.group('rf_correction_manual')) if match.group('rf_correction_manual') else None, - 'rec_crystal_correction_fine': float(match.group('rf_correction_automatic')) if match.group('rf_correction_automatic') else None, - 'rec_input_noise': float(match.group('signal_quality')) if match.group('signal_quality') else None, - 'senders_signal': float(match.group('senders_signal_quality')) if match.group('senders_signal_quality') else None, - 'senders_messages': float(match.group('senders_messages')) if match.group('senders_messages') else None, - 'good_senders_signal': float(match.group('good_senders_signal_quality')) if match.group('good_senders_signal_quality') else None, - 'good_senders': float(match.group('good_senders')) if match.group('good_senders') else None, - 'good_and_bad_senders': float(match.group('good_and_bad_senders')) if match.group('good_and_bad_senders') else None} + result = { + 'version': match.group('version'), + 'platform': match.group('platform'), + 'cpu_load': float(match.group('cpu_load')), + 'free_ram': float(match.group('ram_free')), + 'total_ram': float(match.group('ram_total')), + 'ntp_error': float(match.group('ntp_offset')), + } + + if match.group('ntp_correction'): result['rt_crystal_correction'] = float(match.group('ntp_correction')) + if match.group('voltage'): result['voltage'] = float(match.group('voltage')) + if match.group('amperage'): result['amperage'] = float(match.group('amperage')) + if match.group('cpu_temperature'): result['cpu_temp'] = float(match.group('cpu_temperature')) + if match.group('visible_senders'): result['senders_visible'] = int(match.group('visible_senders')) + if match.group('senders'): result['senders_total'] = int(match.group('senders')) + if match.group('rf_correction_manual'): result['rec_crystal_correction'] = int(match.group('rf_correction_manual')) + if match.group('rf_correction_automatic'): result['rec_crystal_correction_fine'] = float(match.group('rf_correction_automatic')) + if match.group('signal_quality'): result['rec_input_noise'] = float(match.group('signal_quality')) + if match.group('senders_signal_quality'): result['senders_signal'] = float(match.group('senders_signal_quality')) + if match.group('senders_messages'): result['senders_messages'] = float(match.group('senders_messages')) + if match.group('good_senders_signal_quality'): result['good_senders_signal'] = float(match.group('good_senders_signal_quality')) + if match.group('good_senders'): result['good_senders'] = float(match.group('good_senders')) + if match.group('good_and_bad_senders'): result['good_and_bad_senders'] = float(match.group('good_and_bad_senders')) + + return result diff --git a/ogn/parser/aprs_comment/spider_parser.py b/ogn/parser/aprs_comment/spider_parser.py index 9adb084..f8c3d64 100644 --- a/ogn/parser/aprs_comment/spider_parser.py +++ b/ogn/parser/aprs_comment/spider_parser.py @@ -9,8 +9,8 @@ class SpiderParser(BaseParser): self.position_pattern = PATTERN_SPIDER_POSITION_COMMENT def parse_position(self, aprs_comment): - ac_match = self.position_pattern.match(aprs_comment) - return {'spider_id': ac_match.group('spider_id'), - 'signal_power': int(ac_match.group('signal_power')) if ac_match.group('signal_power') else None, - 'spider_registration': ac_match.group('spider_registration') if ac_match.group('spider_registration') else None, - 'gps_quality': ac_match.group('gps_quality') if ac_match.group('gps_quality') else None} + match = self.position_pattern.match(aprs_comment) + return {'spider_id': match.group('spider_id'), + 'signal_power': int(match.group('signal_power')) if match.group('signal_power') else None, + 'spider_registration': match.group('spider_registration') if match.group('spider_registration') else None, + 'gps_quality': match.group('gps_quality') if match.group('gps_quality') else None}