source: src/common/gnuboat_common/datahandler/logdataset.py@ 77cd9cf

debian/bullseye
Last change on this file since 77cd9cf was 7be94aa, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
  • Property mode set to 100644
File size: 4.6 KB
Line 
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
19from datetime import datetime, timezone
20from collections import namedtuple
21
22Location = namedtuple('Location', 'latitude longitude')
23"""@class Dataset of a log entry
24"""
25
26
27class LogDataset:
28 def __init__(
29 self,
30 datetime=None,
31 gps_status=None,
32 latitude=None,
33 latitude_direction=None,
34 longitude=None,
35 longitude_direction=None,
36 speed_over_ground=None,
37 course_over_ground=None,
38 water_depth=None,
39 water_temperature=None
40 ):
41 self._datetime = datetime
42 self._gps_status = gps_status
43 self._latitude = latitude
44 self._latitude_direction = latitude_direction
45 self._longitude = longitude
46 self._longitude_direction = longitude_direction
47 self._speed_over_ground = speed_over_ground
48 self._course_over_ground = course_over_ground
49 self._water_depth = water_depth
50 self._water_temperature = water_temperature
51
52 def datetime(self):
53 return self._datetime
54
55 def datetime_object(self):
56 if self.datetime() is None:
57 return None
58 return datetime.strptime(self.datetime(), "%Y-%m-%d %H:%M:%S").replace(
59 tzinfo=timezone.utc
60 )
61
62 def datetime_set(self, datetime):
63 self._datetime = datetime
64
65 def gps_status(self):
66 return self._gps_status
67
68 def gps_status_set(self, status):
69 self._gps_status = status
70
71 def latitude(self):
72 return self._latitude
73
74 def latitude_set(self, latitude):
75 self._latitude = latitude
76
77 def latitude_direction(self):
78 return self._latitude_direction
79
80 def latitude_direction_set(self, direction):
81 self._latitude_direction = direction
82
83 def longitude(self):
84 return self._longitude
85
86 def longitude_set(self, longitude):
87 self._longitude = longitude
88
89 def longitude_direction(self):
90 return self._longitude_direction
91
92 def longitude_direction_set(self, direction):
93 self._longitude_direction = direction
94
95 def location(self):
96 if self.latitude_direction() is None:
97 return None
98 elif self.latitude_direction() == 'N':
99 latitude = self.latitude()
100 elif self.latitude_direction() == 'S':
101 latitude = -1.0 * self.latitude()
102 else:
103 return None
104 if self.longitude_direction() is None:
105 return None
106 elif self.longitude_direction() == 'E':
107 longitude = self.longitude()
108 elif self.longitude_direction() == 'W':
109 longitude = -1.0 * self.longitude()
110 else:
111 return None
112 return Location(latitude, longitude)
113
114 def speed_over_ground(self):
115 return self._speed_over_ground
116
117 def speed_over_ground_set(self, speed):
118 self._speed_over_ground = speed
119
120 def course_over_ground(self):
121 return self._course_over_ground
122
123 def course_over_ground_set(self, course):
124 self._course_over_ground = course
125
126 def water_depth(self):
127 return self._water_depth
128
129 def water_depth_set(self, depth):
130 self._water_depth = depth
131
132 def water_temperature(self):
133 return self._water_temperature
134
135 def water_temperature_set(self, temperature):
136 self._water_temperature = temperature
137
138 def to_dict(self):
139 return {
140 'datetime': self.datetime(),
141 'gps_status': self.gps_status(),
142 'latitude': self.latitude(),
143 'latitude_direction': self.latitude_direction(),
144 'longitude': self.longitude(),
145 'longitude_direction': self.longitude_direction(),
146 'speed_over_ground': self.speed_over_ground(),
147 'course_over_ground': self.course_over_ground(),
148 'water_depth': self.water_depth(),
149 'water_temperature': self.water_temperature()
150 }
Note: See TracBrowser for help on using the repository browser.