Changeset 9af0638 for src/common


Ignore:
Timestamp:
Feb 2, 2020, 5:30:22 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
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)
Message:

Created new python gnuboat_common package, with functions used by gnuboat and mapservice

Location:
src/common
Files:
4 added
5 moved

Legend:

Unmodified
Added
Removed
  • src/common/bin/gnuboat-log-analyser

    r75f09e4 r9af0638  
    22# -*- coding: utf-8 -*-
    33'''
    4     Copyright (C) 2018 - 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     4    Copyright (C) 2018 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    55
    66    This program is free software: you can redistribute it and/or modify
    … …  
    3131import shutil
    3232
    33 from gnuboat.datahandler import loghandler, logdataset
     33from gnuboat_common.datahandler import loghandler, logdataset
    3434
    3535# -999 is a workaround, as long gdal python api does not handle addAlpha
    … …  
    162162                # parse, correct and append log file
    163163                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():
    165168                        sys.exit(5)
    166169               
  • src/common/bin/gnuboat-log-converter

    r75f09e4 r9af0638  
    22# -*- coding: utf-8 -*-
    33'''
    4     Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     4    Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    55
    66    This program is free software: you can redistribute it and/or modify
    … …  
    2727import subprocess
    2828
    29 from gnuboat.datahandler import loghandler, logdataset
     29from gnuboat_common.datahandler import loghandler, logdataset
    3030
    3131class Format(Enum):
    … …  
    5858    csv_callback = CsvCallback(output_file_csv)
    5959    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()))
    6163    output_file.close()
    6264
  • src/common/gnuboat_common/datahandler/__init__.py

    r75f09e4 r9af0638  
    11# -*- coding: utf-8 -*-
    22'''
    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.
    44
    55    This program is free software: you can redistribute it and/or modify
    … …  
    1818
    1919from .loghandler import LogHandler
     20from .logdataset import LogDataset
    2021
    21 __all__ = ["loghandler"]
     22__all__ = ["loghandler", "logdataset"]
  • src/common/gnuboat_common/datahandler/logdataset.py

    r75f09e4 r9af0638  
    1616    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717'''
     18
     19from datetime import datetime, timezone
     20from collections import namedtuple
     21
     22Location = namedtuple('Location', 'latitude longitude')
    1823
    1924"""@class Dataset of a log entry
    … …  
    3641        def datetime(self):
    3742                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)
    3848       
    3949        def datetime_set(self, datetime):
    … …  
    7080                self._longitude_direction = direction
    7181               
     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       
    72101        def speed_over_ground(self):
    73102                return self._speed_over_ground
  • src/common/gnuboat_common/datahandler/loghandler.py

    r75f09e4 r9af0638  
    11    # -*- coding: utf-8 -*-
    22'''
    3     Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    44
    55    This program is free software: you can redistribute it and/or modify
    … …  
    2525import math
    2626
    27 from gnuboat.datahandler import logdataset
     27from gnuboat_common.datahandler import logdataset
     28
     29class 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
    2850
    2951"""@class LogHandler
    … …  
    107129                callback must be of a function wich excepts the LogDataset as a parameter.
    108130        """
    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               
    110134                # reading input file
    111135                try:
    112136                        input_file = open(input_file_path, 'r')
    113137                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               
    116151                current_row = 1
    117152                last_row = None
    118                 for line in input_file:
     153                for line in input_list:
    119154                        nmea_sentence = self.parse_nmea_sentence(line, checksums_fix)
    120155                        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))
    122157                                if not errors_ignore:
    123                                         input_file.close()
    124                                         return False
     158                                        result.succeeded(False)
     159                                        return result
    125160                        else:
    126161                                nmea_sentence = nmea_sentence['nmea_sentence']
    … …  
    146181                if last_row is not None:
    147182                        callback(last_row)
    148                 input_file.close()
    149                 return True
     183                result.succeeded(True)
     184                return result
    150185
    151186        def _to_float(self, string, current_row):
Note: See TracChangeset for help on using the changeset viewer.