-
Notifications
You must be signed in to change notification settings - Fork 20
/
test_igc_lib.py
312 lines (233 loc) · 11.5 KB
/
test_igc_lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import unittest
import igc_lib
class TestBuildFromBRecord(unittest.TestCase):
def setUp(self):
self.test_record = 'B1227484612592N01249579EA0043700493extra-3s'
self.test_index = 10
def testBasicBRecordParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
self.assertIsNotNone(b_record)
def testRawimeParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# 12:27:48, from B "122748" 4612592N01249579EA0043700493extra-3s
expected_time = 48.0 # seconds
expected_time += 60.0 * 27.0 # minutes
expected_time += 3600.0 * 12.0 # hours
self.assertAlmostEqual(expected_time, b_record.rawtime)
def testLatParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# 46* 12.592' N, from B122748 "4612592N" 01249579EA0043700493extra-3s
expected_lat = 12.592 / 60.0 # minutes
expected_lat += 46.0 # degrees
self.assertAlmostEqual(expected_lat, b_record.lat)
def testLonParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# 012* 49.579' E, from B1227484612592N "01249579E" A0043700493extra-3s
expected_lon = 49.579 / 60.0 # minutes
expected_lon += 12.0 # degrees
self.assertAlmostEqual(expected_lon, b_record.lon)
def testValidityParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# "A", from B1227484612592N01249579E "A" 0043700493extra-3s
self.assertEqual("A", b_record.validity)
def testPressureAltParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# 437 meters, from B1227484612592N01249579EA "00437" 00493extra-3s
self.assertEqual(437.0, b_record.press_alt)
def testGNSSAltParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# 493 meters, from B1227484612592N01249579EA00437 "00493" extra-3s
self.assertEqual(493.0, b_record.gnss_alt)
def testExtrasParse(self):
b_record = igc_lib.GNSSFix.build_from_B_record(
self.test_record, self.test_index)
# "extra-3s", from B1227484612592N01249579EA0043700493 "extra-3s"
self.assertEqual("extra-3s", b_record.extras)
class TestNapretTaskParsing(unittest.TestCase):
def setUp(self):
test_file = 'testfiles/napret.lkt'
self.task = igc_lib.Task.create_from_lkt_file(test_file)
def testTaskHasStartTime(self):
self.assertAlmostEqual(self.task.start_time, 12*3600)
def testTaskHasEndTime(self):
self.assertAlmostEqual(self.task.end_time, 23*3600 + 59*60 + 59)
def testTaskHasTurnpoints(self):
self.assertEqual(len(self.task.turnpoints), 11)
self.assertEqual(self.task.turnpoints[0].kind, "start_enter")
def testTaskHasTurnpointsWithRadius(self):
self.assertGreaterEqual(min(map(lambda turnpoint: turnpoint.radius,
self.task.turnpoints)), 0.2)
self.assertLessEqual(max(map(lambda turnpoint: turnpoint.radius,
self.task.turnpoints)), 4)
def testTaskHasTurnpointsWithLatitude(self):
self.assertEqual(max(map(lambda turnpoint: int(turnpoint.lat / 46),
self.task.turnpoints)), 1)
def testTaskHasTurnpointsWithLongitude(self):
self.assertEqual(max(map(lambda turnpoint: int(turnpoint.lon / 12),
self.task.turnpoints)), 1)
class TestNapretFlightParsing(unittest.TestCase):
def setUp(self):
test_file = 'testfiles/napret.igc'
self.flight = igc_lib.Flight.create_from_file(test_file)
def testFileParsesOK(self):
self.assertListEqual(self.flight.notes, [])
self.assertTrue(self.flight.valid)
def testBothPressureSensorsAreOK(self):
self.assertTrue(self.flight.press_alt_valid)
self.assertTrue(self.flight.gnss_alt_valid)
def testChosesPressureSensor(self):
self.assertEqual(self.flight.alt_source, 'PRESS')
def testMetadataIsCorrectlyRead(self):
self.assertEqual(self.flight.fr_manuf_code, 'XGD')
self.assertEqual(self.flight.fr_uniq_id, 'jos')
self.assertFalse(hasattr(self.flight, 'i_record'))
# 2016-04-03 0:00 UTC
self.assertAlmostEqual(self.flight.date_timestamp, 1459641600.0)
self.assertEqual(self.flight.glider_type, 'test_glider')
self.assertEqual(self.flight.competition_class,
'test_competition_class')
self.assertFalse(hasattr(self.flight, 'fr_firmware_version'))
self.assertFalse(hasattr(self.flight, 'fr_hardware_version'))
self.assertFalse(hasattr(self.flight, 'fr_recorder_type'))
self.assertFalse(hasattr(self.flight, 'fr_gps_receiver'))
self.assertFalse(hasattr(self.flight, 'fr_pressure_sensor'))
def testBRecordsParsing(self):
self.assertEqual(len(self.flight.fixes), 5380)
def testFixesHaveCorrectIndices(self):
for i, fix in enumerate(self.flight.fixes):
self.assertEqual(i, fix.index)
def testFlightsDetection(self):
# Basic test, there should be at least one thermal
self.assertGreater(len(self.flight.thermals), 0)
def testGlidesDetection(self):
# Basic test, there should be at least one glide
self.assertGreater(len(self.flight.glides), 0)
def testSomeFixesAreInFlight(self):
self.assertTrue(
any(map(lambda fix: fix.flying, self.flight.fixes)))
def testSomeFixesAreNotInFlight(self):
self.assertTrue(
any(map(lambda fix: not fix.flying, self.flight.fixes)))
def testHasTakeoff(self):
self.assertTrue(hasattr(self.flight, 'takeoff_fix'))
def testHasLanding(self):
self.assertTrue(hasattr(self.flight, 'landing_fix'))
def testSomeFixesAreInCircling(self):
self.assertTrue(
any(map(lambda fix: fix.circling, self.flight.fixes)))
def testSomeFixesAreNotInCircling(self):
self.assertTrue(
any(map(lambda fix: not fix.circling, self.flight.fixes)))
def testThermalsAreAfterTakeoff(self):
takeoff_index = self.flight.takeoff_fix.index
for thermal in self.flight.thermals:
self.assertGreaterEqual(thermal.enter_fix.index, takeoff_index)
self.assertGreaterEqual(thermal.exit_fix.index, takeoff_index)
def testThermalsAreBeforeLanding(self):
landing_index = self.flight.landing_fix.index
for thermal in self.flight.thermals:
self.assertLessEqual(thermal.enter_fix.index, landing_index)
self.assertLessEqual(thermal.exit_fix.index, landing_index)
def testGlidesAreAfterTakeoff(self):
takeoff_index = self.flight.takeoff_fix.index
for glide in self.flight.glides:
self.assertGreaterEqual(glide.enter_fix.index, takeoff_index)
self.assertGreaterEqual(glide.exit_fix.index, takeoff_index)
def testGlidesAreBeforeLanding(self):
landing_index = self.flight.landing_fix.index
for glide in self.flight.glides:
self.assertLessEqual(glide.enter_fix.index, landing_index)
self.assertLessEqual(glide.exit_fix.index, landing_index)
class TestNewIGCDateIncrement(unittest.TestCase):
def setUp(self):
test_file = "testfiles/new_date_format.igc"
self.flight = igc_lib.Flight.create_from_file(test_file)
def testFileParsesOK(self):
self.assertListEqual(self.flight.notes, [])
self.assertTrue(self.flight.valid)
def testDateIsReadCorrectly(self):
# 2018-04-03 0:00 UTC
self.assertAlmostEqual(self.flight.date_timestamp, 1522713600.0)
class TestNoTimeIncrementFlightParsing(unittest.TestCase):
def setUp(self):
test_file = 'testfiles/no_time_increment.igc'
self.flight = igc_lib.Flight.create_from_file(test_file)
def testFileParsesOK(self):
self.assertListEqual(self.flight.notes, [])
self.assertTrue(self.flight.valid)
def testBRecordsParsing(self):
# There are 200 B records in the file, but the last
# 50 do not increment the time, and therefore should be dropped.
self.assertEqual(len(self.flight.fixes), 150)
class TestOlsztynFlightParsing(unittest.TestCase):
def setUp(self):
test_file = 'testfiles/olsztyn.igc'
self.flight = igc_lib.Flight.create_from_file(test_file)
def testFileParsesOK(self):
self.assertListEqual(self.flight.notes, [])
self.assertTrue(self.flight.valid)
def testMetadataIsCorrectlyRead(self):
self.assertEqual(self.flight.fr_manuf_code, 'LXN')
self.assertEqual(self.flight.fr_uniq_id, 'ABC')
self.assertEqual(
self.flight.i_record,
'I073638FXA3941ENL4246TAS4751GSP5254TRT5559VAT6063OAT')
# 2011-09-02 0:00 UTC
self.assertAlmostEqual(self.flight.date_timestamp, 1314921600.0)
self.assertEqual(self.flight.glider_type, 'test_glider_xx')
self.assertEqual(self.flight.competition_class,
'some_competition_class')
self.assertEqual(self.flight.fr_firmware_version, '2.2')
self.assertEqual(self.flight.fr_hardware_version, '2')
self.assertEqual(self.flight.fr_recorder_type,
'LXNAVIGATION,LX8000F')
self.assertEqual(self.flight.fr_gps_receiver,
'uBLOX LEA-4S-2,16,max9000m')
self.assertEqual(self.flight.fr_pressure_sensor,
'INTERSEMA,MS5534A,max10000m')
def testBRecordsParsing(self):
self.assertEqual(len(self.flight.fixes), 2469)
class TestNewZealandFlightParsing(unittest.TestCase):
def setUp(self):
test_file = 'testfiles/new_zealand.igc'
self.flight = igc_lib.Flight.create_from_file(test_file)
def testFileParsesOK(self):
self.assertListEqual(self.flight.notes, [])
self.assertTrue(self.flight.valid)
class ParsePickFirst(igc_lib.FlightParsingConfig):
which_flight_to_pick = 'first'
class ParsePickConcat(igc_lib.FlightParsingConfig):
which_flight_to_pick = 'concat'
class TestWhichFlightToPick(unittest.TestCase):
def setUp(self):
self.test_file = 'testfiles/flight_with_middle_landing.igc'
def testFileParsesOKPickFirst(self):
flight = igc_lib.Flight.create_from_file(
self.test_file, config_class=ParsePickFirst)
self.assertListEqual(flight.notes, [])
self.assertTrue(flight.valid)
def testFileParsesOKPickConcat(self):
flight = igc_lib.Flight.create_from_file(
self.test_file, config_class=ParsePickConcat)
self.assertListEqual(flight.notes, [])
self.assertTrue(flight.valid)
def testConcatIsLongerThanFirst(self):
flight_first = igc_lib.Flight.create_from_file(
self.test_file, config_class=ParsePickFirst)
flight_concat = igc_lib.Flight.create_from_file(
self.test_file, config_class=ParsePickConcat)
# Takeoff is the same
self.assertEqual(
flight_first.takeoff_fix.timestamp,
flight_concat.takeoff_fix.timestamp)
# But landing is earlier
self.assertLess(
flight_first.landing_fix.timestamp,
flight_concat.landing_fix.timestamp)