| [ea6eba1] | 1 | # -*- coding: utf-8 -*-
|
|---|
| 2 | '''
|
|---|
| 3 | Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | '''
|
|---|
| 18 |
|
|---|
| [9af0638] | 19 | from datetime import datetime, timezone
|
|---|
| 20 | from collections import namedtuple
|
|---|
| 21 |
|
|---|
| 22 | Location = namedtuple('Location', 'latitude longitude')
|
|---|
| 23 |
|
|---|
| [ea6eba1] | 24 | """@class Dataset of a log entry
|
|---|
| 25 | """
|
|---|
| 26 | class LogDataset:
|
|---|
| 27 | def __init__(self, datetime = None, gps_status = None, latitude = None, latitude_direction = None,
|
|---|
| 28 | longitude = None, longitude_direction = None, speed_over_ground = None,
|
|---|
| 29 | course_over_ground = None, water_depth = None, water_temperature = None):
|
|---|
| 30 | self._datetime = datetime
|
|---|
| 31 | self._gps_status = gps_status
|
|---|
| 32 | self._latitude = latitude
|
|---|
| 33 | self._latitude_direction = latitude_direction
|
|---|
| 34 | self._longitude = longitude
|
|---|
| 35 | self._longitude_direction = longitude_direction
|
|---|
| 36 | self._speed_over_ground = speed_over_ground
|
|---|
| 37 | self._course_over_ground = course_over_ground
|
|---|
| 38 | self._water_depth = water_depth
|
|---|
| 39 | self._water_temperature = water_temperature
|
|---|
| 40 |
|
|---|
| 41 | def datetime(self):
|
|---|
| 42 | return self._datetime
|
|---|
| 43 |
|
|---|
| [9af0638] | 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)
|
|---|
| 48 |
|
|---|
| [ea6eba1] | 49 | def datetime_set(self, datetime):
|
|---|
| 50 | self._datetime = datetime
|
|---|
| 51 |
|
|---|
| 52 | def gps_status(self):
|
|---|
| 53 | return self._gps_status
|
|---|
| 54 |
|
|---|
| 55 | def gps_status_set(self, status):
|
|---|
| 56 | self._gps_status = status
|
|---|
| 57 |
|
|---|
| 58 | def latitude(self):
|
|---|
| 59 | return self._latitude
|
|---|
| 60 |
|
|---|
| 61 | def latitude_set(self, latitude):
|
|---|
| 62 | self._latitude = latitude
|
|---|
| 63 |
|
|---|
| 64 | def latitude_direction(self):
|
|---|
| 65 | return self._latitude_direction
|
|---|
| 66 |
|
|---|
| 67 | def latitude_direction_set(self, direction):
|
|---|
| 68 | self._latitude_direction = direction
|
|---|
| 69 |
|
|---|
| 70 | def longitude(self):
|
|---|
| 71 | return self._longitude
|
|---|
| 72 |
|
|---|
| 73 | def longitude_set(self, longitude):
|
|---|
| 74 | self._longitude = longitude
|
|---|
| 75 |
|
|---|
| 76 | def longitude_direction(self):
|
|---|
| 77 | return self._longitude_direction
|
|---|
| 78 |
|
|---|
| 79 | def longitude_direction_set(self, direction):
|
|---|
| 80 | self._longitude_direction = direction
|
|---|
| 81 |
|
|---|
| [9af0638] | 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 |
|
|---|
| [ea6eba1] | 101 | def speed_over_ground(self):
|
|---|
| 102 | return self._speed_over_ground
|
|---|
| 103 |
|
|---|
| 104 | def speed_over_ground_set(self, speed):
|
|---|
| 105 | self._speed_over_ground = speed
|
|---|
| 106 |
|
|---|
| 107 | def course_over_ground(self):
|
|---|
| 108 | return self._course_over_ground
|
|---|
| 109 |
|
|---|
| 110 | def course_over_ground_set(self, course):
|
|---|
| 111 | self._course_over_ground = course
|
|---|
| 112 |
|
|---|
| 113 | def water_depth(self):
|
|---|
| 114 | return self._water_depth
|
|---|
| 115 |
|
|---|
| 116 | def water_depth_set(self, depth):
|
|---|
| 117 | self._water_depth = depth
|
|---|
| 118 |
|
|---|
| 119 | def water_temperature(self):
|
|---|
| 120 | return self._water_temperature
|
|---|
| 121 |
|
|---|
| 122 | def water_temperature_set(self, temperature):
|
|---|
| 123 | self._water_temperature = temperature
|
|---|
| 124 |
|
|---|
| 125 | def to_dict(self):
|
|---|
| 126 | return {'datetime': self.datetime(),
|
|---|
| 127 | 'gps_status': self.gps_status(),
|
|---|
| 128 | 'latitude': self.latitude(),
|
|---|
| 129 | 'latitude_direction': self.latitude_direction(),
|
|---|
| 130 | 'longitude': self.longitude(),
|
|---|
| 131 | 'longitude_direction': self.longitude_direction(),
|
|---|
| 132 | 'speed_over_ground': self.speed_over_ground(),
|
|---|
| 133 | 'course_over_ground': self.course_over_ground(),
|
|---|
| 134 | 'water_depth': self.water_depth(),
|
|---|
| 135 | 'water_temperature': self.water_temperature()}
|
|---|