2019-03-11 22:26:01 +00:00
|
|
|
import datetime
|
2016-07-02 20:30:54 +00:00
|
|
|
import unittest
|
2019-01-26 13:15:13 +00:00
|
|
|
|
2019-03-11 22:26:01 +00:00
|
|
|
from tests.base import TestBaseDB, db
|
2016-07-02 20:30:54 +00:00
|
|
|
|
2019-08-31 08:14:41 +00:00
|
|
|
from app.model import TakeoffLanding
|
2016-07-02 20:30:54 +00:00
|
|
|
|
2019-08-31 08:14:41 +00:00
|
|
|
from app.collect.takeoff_landings import update_entries
|
2016-07-02 20:30:54 +00:00
|
|
|
|
|
|
|
|
2019-01-26 19:14:18 +00:00
|
|
|
class TestTakeoffLanding(TestBaseDB):
|
2016-07-02 20:30:54 +00:00
|
|
|
def test_broken_rope(self):
|
2020-05-16 20:57:21 +00:00
|
|
|
"""The algorithm should detect one takeoff and one landing."""
|
2019-04-13 19:06:32 +00:00
|
|
|
|
2020-05-16 20:57:21 +00:00
|
|
|
self.insert_airports_and_devices()
|
|
|
|
self.insert_aircraft_beacons_broken_rope()
|
2016-07-02 20:30:54 +00:00
|
|
|
|
2017-12-10 16:30:27 +00:00
|
|
|
# find the takeoff and the landing
|
2019-03-11 22:26:01 +00:00
|
|
|
update_entries(db.session, start=datetime.datetime(2016, 7, 2, 0, 0, 0), end=datetime.datetime(2016, 7, 2, 23, 59, 59))
|
2019-08-31 08:14:41 +00:00
|
|
|
takeoff_landing_query = db.session.query(TakeoffLanding).filter(db.between(TakeoffLanding.timestamp, datetime.datetime(2016, 7, 2, 0, 0, 0), datetime.datetime(2016, 7, 2, 23, 59, 59)))
|
2019-04-13 19:06:32 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(takeoff_landing_query.all()), 2)
|
|
|
|
for entry in takeoff_landing_query.all():
|
2019-08-31 08:14:41 +00:00
|
|
|
self.assertEqual(entry.airport.name, "Koenigsdorf")
|
2017-12-10 16:30:27 +00:00
|
|
|
|
|
|
|
# we should not find the takeoff and the landing again
|
2019-03-11 22:26:01 +00:00
|
|
|
update_entries(db.session, start=datetime.datetime(2016, 7, 2, 0, 0, 0), end=datetime.datetime(2016, 7, 2, 23, 59, 59))
|
2019-04-13 19:06:32 +00:00
|
|
|
self.assertEqual(len(takeoff_landing_query.all()), 2)
|
|
|
|
|
|
|
|
def test_broken_rope_with_stall(self):
|
|
|
|
"""Here we have a broken rope where the glider passes again the threshold for take off."""
|
|
|
|
|
2020-05-16 20:57:21 +00:00
|
|
|
self.insert_airports_and_devices()
|
|
|
|
self.insert_aircraft_beacons_broken_rope_with_stall()
|
2019-04-13 19:06:32 +00:00
|
|
|
|
|
|
|
# find the takeoff and the landing
|
|
|
|
update_entries(db.session, start=datetime.datetime(2019, 4, 13, 0, 0, 0), end=datetime.datetime(2019, 4, 13, 23, 59, 59))
|
2019-08-31 08:14:41 +00:00
|
|
|
takeoff_landings = db.session.query(TakeoffLanding).filter(db.between(TakeoffLanding.timestamp, datetime.datetime(2019, 4, 13, 0, 0, 0), datetime.datetime(2019, 4, 13, 23, 59, 59))).all()
|
2019-04-13 19:06:32 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(takeoff_landings), 2)
|
|
|
|
for entry in takeoff_landings:
|
2019-08-31 08:14:41 +00:00
|
|
|
self.assertEqual(entry.airport.name, "Koenigsdorf")
|
2016-07-02 20:30:54 +00:00
|
|
|
|
2017-05-26 20:56:38 +00:00
|
|
|
|
2019-08-31 08:14:41 +00:00
|
|
|
if __name__ == "__main__":
|
2016-07-02 20:30:54 +00:00
|
|
|
unittest.main()
|