# -*- coding: utf-8 -*- ''' Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ''' from datetime import datetime, timezone from collections import namedtuple Location = namedtuple('Location', 'latitude longitude') """@class Dataset of a log entry """ class LogDataset: def __init__(self, datetime = None, gps_status = None, latitude = None, latitude_direction = None, longitude = None, longitude_direction = None, speed_over_ground = None, course_over_ground = None, water_depth = None, water_temperature = None): self._datetime = datetime self._gps_status = gps_status self._latitude = latitude self._latitude_direction = latitude_direction self._longitude = longitude self._longitude_direction = longitude_direction self._speed_over_ground = speed_over_ground self._course_over_ground = course_over_ground self._water_depth = water_depth self._water_temperature = water_temperature def datetime(self): return self._datetime def datetime_object(self): if self.datetime() is None: return None return datetime.strptime(self.datetime(), "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc) def datetime_set(self, datetime): self._datetime = datetime def gps_status(self): return self._gps_status def gps_status_set(self, status): self._gps_status = status def latitude(self): return self._latitude def latitude_set(self, latitude): self._latitude = latitude def latitude_direction(self): return self._latitude_direction def latitude_direction_set(self, direction): self._latitude_direction = direction def longitude(self): return self._longitude def longitude_set(self, longitude): self._longitude = longitude def longitude_direction(self): return self._longitude_direction def longitude_direction_set(self, direction): self._longitude_direction = direction def location(self): if self.latitude_direction() is None: return None elif self.latitude_direction() == 'N': latitude = self.latitude() elif self.latitude_direction() == 'S': latitude = -1.0 * self.latitude() else: return None if self.longitude_direction() is None: return None elif self.longitude_direction() == 'E': longitude = self.longitude() elif self.longitude_direction() == 'W': longitude = -1.0 * self.longitude() else: return None return Location(latitude, longitude) def speed_over_ground(self): return self._speed_over_ground def speed_over_ground_set(self, speed): self._speed_over_ground = speed def course_over_ground(self): return self._course_over_ground def course_over_ground_set(self, course): self._course_over_ground = course def water_depth(self): return self._water_depth def water_depth_set(self, depth): self._water_depth = depth def water_temperature(self): return self._water_temperature def water_temperature_set(self, temperature): self._water_temperature = temperature def to_dict(self): return {'datetime': self.datetime(), 'gps_status': self.gps_status(), 'latitude': self.latitude(), 'latitude_direction': self.latitude_direction(), 'longitude': self.longitude(), 'longitude_direction': self.longitude_direction(), 'speed_over_ground': self.speed_over_ground(), 'course_over_ground': self.course_over_ground(), 'water_depth': self.water_depth(), 'water_temperature': self.water_temperature()}