Changeset 9af0638 for src/common
- Timestamp:
- Feb 2, 2020, 5:30:22 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- ec9e811
- Parents:
- 75f09e4
- git-author:
- Joachim Langenbach <joachim.langenbach@…> (02/02/20 12:49:19)
- git-committer:
- Joachim Langenbach <joachim.langenbach@…> (02/02/20 17:30:22)
- Location:
- src/common
- Files:
-
- 4 added
- 5 moved
-
README (added)
-
bin/gnuboat-log-analyser (moved) (moved from src/gnuboat/bin/gnuboat-log-analyser ) (3 diffs)
-
bin/gnuboat-log-converter (moved) (moved from src/gnuboat/bin/gnuboat-log-converter ) (3 diffs)
-
gnuboat_common/__init__.py (added)
-
gnuboat_common/datahandler/__init__.py (moved) (moved from src/gnuboat/gnuboat/datahandler/__init__.py ) (2 diffs)
-
gnuboat_common/datahandler/logdataset.py (moved) (moved from src/gnuboat/gnuboat/datahandler/logdataset.py ) (3 diffs)
-
gnuboat_common/datahandler/loghandler.py (moved) (moved from src/gnuboat/gnuboat/datahandler/loghandler.py ) (4 diffs)
-
setup.py (added)
-
tox.ini (added)
Legend:
- Unmodified
- Added
- Removed
-
src/common/bin/gnuboat-log-analyser
r75f09e4 r9af0638 2 2 # -*- coding: utf-8 -*- 3 3 ''' 4 Copyright (C) 2018 - 20 19EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.4 Copyright (C) 2018 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 5 5 6 6 This program is free software: you can redistribute it and/or modify … … 31 31 import shutil 32 32 33 from gnuboat .datahandler import loghandler, logdataset33 from gnuboat_common.datahandler import loghandler, logdataset 34 34 35 35 # -999 is a workaround, as long gdal python api does not handle addAlpha … … 162 162 # parse, correct and append log file 163 163 csv_callback.stage_set(stage) 164 if not log_handler.gnuboat_read(log_file_path, csv_callback.callback): 164 result = log_handler.gnuboat_read_file(log_file_path, csv_callback.callback) 165 if result.messages(): 166 print('\n'.join(result.errors())) 167 if not result.success(): 165 168 sys.exit(5) 166 169 -
src/common/bin/gnuboat-log-converter
r75f09e4 r9af0638 2 2 # -*- coding: utf-8 -*- 3 3 ''' 4 Copyright (C) 2016 - 20 17EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.4 Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 5 5 6 6 This program is free software: you can redistribute it and/or modify … … 27 27 import subprocess 28 28 29 from gnuboat .datahandler import loghandler, logdataset29 from gnuboat_common.datahandler import loghandler, logdataset 30 30 31 31 class Format(Enum): … … 58 58 csv_callback = CsvCallback(output_file_csv) 59 59 log_handler = loghandler.LogHandler() 60 log_handler.gnuboat_read(input_file_path, csv_callback.callback, checksums_fix, errors_ignore) 60 result = log_handler.gnuboat_read_file(input_file_path, csv_callback.callback, checksums_fix, errors_ignore) 61 if result.messages(): 62 print('\n'.join(result.errors())) 61 63 output_file.close() 62 64 -
src/common/gnuboat_common/datahandler/__init__.py
r75f09e4 r9af0638 1 1 # -*- coding: utf-8 -*- 2 2 ''' 3 Copyright (C) 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.3 Copyright (C) 2018 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 4 4 5 5 This program is free software: you can redistribute it and/or modify … … 18 18 19 19 from .loghandler import LogHandler 20 from .logdataset import LogDataset 20 21 21 __all__ = ["loghandler" ]22 __all__ = ["loghandler", "logdataset"] -
src/common/gnuboat_common/datahandler/logdataset.py
r75f09e4 r9af0638 16 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 17 ''' 18 19 from datetime import datetime, timezone 20 from collections import namedtuple 21 22 Location = namedtuple('Location', 'latitude longitude') 18 23 19 24 """@class Dataset of a log entry … … 36 41 def datetime(self): 37 42 return self._datetime 43 44 def datetime_object(self): 45 if self.datetime() is None: 46 return None 47 return datetime.strptime(self.datetime(), "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc) 38 48 39 49 def datetime_set(self, datetime): … … 70 80 self._longitude_direction = direction 71 81 82 def location(self): 83 if self.latitude_direction() is None: 84 return None 85 elif self.latitude_direction() == 'N': 86 latitude = self.latitude() 87 elif self.latitude_direction() == 'S': 88 latitude = -1.0 * self.latitude() 89 else: 90 return None 91 if self.longitude_direction() is None: 92 return None 93 elif self.longitude_direction() == 'E': 94 longitude = self.longitude() 95 elif self.longitude_direction() == 'W': 96 longitude = -1.0 * self.longitude() 97 else: 98 return None 99 return Location(latitude, longitude) 100 72 101 def speed_over_ground(self): 73 102 return self._speed_over_ground -
src/common/gnuboat_common/datahandler/loghandler.py
r75f09e4 r9af0638 1 1 # -*- coding: utf-8 -*- 2 2 ''' 3 Copyright (C) 2016 - 20 18EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.3 Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 4 4 5 5 This program is free software: you can redistribute it and/or modify … … 25 25 import math 26 26 27 from gnuboat.datahandler import logdataset 27 from gnuboat_common.datahandler import logdataset 28 29 class LogParsingResult: 30 def __init__(self): 31 self._success = False 32 self._errors = [] 33 34 def error_add(self, error): 35 self._errors.append(error) 36 37 def errors(self): 38 return self._errors 39 40 def messages(self): 41 if len(self._errors) > 0: 42 return True 43 return False 44 45 def succeeded(self, status): 46 self._success = status 47 48 def success(self): 49 return self._success 28 50 29 51 """@class LogHandler … … 107 129 callback must be of a function wich excepts the LogDataset as a parameter. 108 130 """ 109 def gnuboat_read(self, input_file_path, callback, checksums_fix = False, errors_ignore = False): 131 def gnuboat_read_file(self, input_file_path, callback, checksums_fix = False, errors_ignore = False): 132 result = LogParsingResult() 133 110 134 # reading input file 111 135 try: 112 136 input_file = open(input_file_path, 'r') 113 137 except IOError as error: 114 print('ERROR: Could not open the input file: {}'.format(error)) 115 return False 138 result.error_add('ERROR: Could not open the input file: {}'.format(error)) 139 result.succeeded(False) 140 return result 141 result = self.gnuboat_read(input_file, callback, checksums_fix, errors_ignore = False) 142 input_file.close() 143 return result 144 145 """ Reads the original gnuboat log from input_list and calls a callable function on all complete LogDataset 146 callback must be of a function wich excepts the LogDataset as a parameter. 147 """ 148 def gnuboat_read(self, input_list, callback, checksums_fix = False, errors_ignore = False): 149 result = LogParsingResult() 150 116 151 current_row = 1 117 152 last_row = None 118 for line in input_ file:153 for line in input_list: 119 154 nmea_sentence = self.parse_nmea_sentence(line, checksums_fix) 120 155 if nmea_sentence is None: 121 print('INFO: Failed to parse nmea sentence ({}) at line {}'.format(line.strip(), current_row))156 result.error_add('INFO: Failed to parse nmea sentence ({}) at line {}'.format(line.strip(), current_row)) 122 157 if not errors_ignore: 123 input_file.close()124 return False158 result.succeeded(False) 159 return result 125 160 else: 126 161 nmea_sentence = nmea_sentence['nmea_sentence'] … … 146 181 if last_row is not None: 147 182 callback(last_row) 148 input_file.close()149 return True183 result.succeeded(True) 184 return result 150 185 151 186 def _to_float(self, string, current_row):
Note:
See TracChangeset
for help on using the changeset viewer.
