def get(self, request): kml = Kml(name='AUVSI SUAS LIVE Flight Data') kml_mission = kml.newfolder(name='Missions') (mission, err) = active_mission() if err: return err MissionConfig.kml_all(kml_mission, [mission]) kml_flyzone = kml.newfolder(name='Fly Zones') FlyZone.kml_all(kml_flyzone) parameters = '?sessionid={}'.format(request.COOKIES['sessionid']) uri = request.build_absolute_uri( '/auvsi_admin/update.kml') + parameters netlink = kml.newnetworklink(name="Live Data") netlink.link.href = uri netlink.link.refreshmode = RefreshMode.oninterval netlink.link.refreshinterval = 0.5 response = HttpResponse(kml.kml()) response['Content-Type'] = 'application/vnd.google-earth.kml+xml' response['Content-Disposition' ] = 'attachment; filename=%s.kml' % 'live' response['Content-Length'] = str(len(response.content)) return response
def get(self, request): kml = Kml(name='AUVSI SUAS LIVE Flight Data') kml_mission = kml.newfolder(name='Missions') (mission, err) = active_mission() if err: return err MissionConfig.kml_all(kml_mission, [mission]) kml_flyzone = kml.newfolder(name='Fly Zones') FlyZone.kml_all(kml_flyzone) parameters = '?sessionid={}'.format(request.COOKIES['sessionid']) uri = request.build_absolute_uri( '/auvsi_admin/update.kml') + parameters netlink = kml.newnetworklink(name="Live Data") netlink.link.href = uri netlink.link.refreshmode = RefreshMode.oninterval netlink.link.refreshinterval = 0.5 response = HttpResponse(kml.kml()) response['Content-Type'] = 'application/vnd.google-earth.kml+xml' response['Content-Disposition'] = 'attachment; filename=live.kml' response['Content-Length'] = str(len(response.content)) return response
def setUp(self): """Sets up the client, server info URL, and user.""" cache.clear() self.user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') self.user.save() response = self.client.post(login_url, { 'username': '******', 'password': '******', }) self.assertEqual(200, response.status_code) self.info = ServerInfo() self.info.team_msg = 'test message' self.info.save() gpos = GpsPosition(latitude=0, longitude=0) gpos.save() self.mission = MissionConfig() self.mission.is_active = True self.mission.home_pos = gpos self.mission.emergent_last_known_pos = gpos self.mission.off_axis_target_pos = gpos self.mission.sric_pos = gpos self.mission.air_drop_pos = gpos self.mission.server_info = self.info self.mission.save()
def setUp(self): """Setup a single active mission to test live kml with.""" super(TestGenerateLiveKMLNoFixture, self).setUp() pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.save() self.config = config
def test_toKML(self): """Test Generation of kml for all mission data""" kml = Kml() MissionConfig.kml_all(kml=kml) data = kml.kml() names = [ 'Off Axis', 'SRIC', 'Home Position', 'Air Drop', 'Emergent LKP', 'Search Area', 'Waypoints', ] for name in names: tag = '<name>{}</name>'.format(name) err = 'tag "{}" not found in {}'.format(tag, data) self.assertIn(tag, data, err)
def get(self, request): kml = Kml(name='AUVSI SUAS Flight Data') kml_teams = kml.newfolder(name='Teams') kml_mission = kml.newfolder(name='Missions') users = User.objects.all() for user in users: # Ignore admins if user.is_superuser: continue UasTelemetry.kml(user=user, logs=UasTelemetry.by_user(user), kml=kml_teams, kml_doc=kml.document) MissionConfig.kml_all(kml_mission) kml_flyzone = kml.newfolder(name='Fly Zones') FlyZone.kml_all(kml_flyzone) response = HttpResponse(kml.kml()) response['Content-Type'] = 'application/vnd.google-earth.kml+xml' response['Content-Disposition'] = 'attachment; filename=mission.kml' response['Content-Length'] = str(len(response.content)) return response
def create_config(self): """Creates a dummy config for testing.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() config = MissionConfig() config.is_active = False config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos return config
def create_config(self): """Creates a dummy config for testing.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = False config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.ir_primary_target_pos = pos config.ir_secondary_target_pos = pos config.air_drop_pos = pos config.server_info = info return config
def setUp(self): """Setup a single active mission to test live kml with.""" super(TestGenerateLiveKMLNoFixture, self).setUp() pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = timezone.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.server_info = info config.save() self.config = config
def create_config(self): """Creates a dummy config for testing.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = False config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.server_info = info return config
def setUp(self): self.user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') self.user.save() # Create an active mission. pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.save() # Add a couple of stationary obstacles obst = self.create_stationary_obstacle(lat=38.142233, lon=-76.434082, radius=300, height=500) config.stationary_obstacles.add(obst) obst = self.create_stationary_obstacle(lat=38.442233, lon=-76.834082, radius=100, height=750) config.stationary_obstacles.add(obst) # And a couple of moving obstacles obst = self.create_moving_obstacle([ # (lat, lon, alt) (38.142233, -76.434082, 300), (38.141878, -76.425198, 700), ]) config.moving_obstacles.add(obst) obst = self.create_moving_obstacle([ # (lat, lon, alt) (38.145405, -76.428310, 100), (38.146582, -76.424099, 200), (38.144662, -76.427634, 300), (38.147729, -76.419185, 200), (38.147573, -76.420832, 100), (38.148522, -76.419507, 750), ]) config.moving_obstacles.add(obst) config.save() # Login response = self.client.post(login_url, { 'username': '******', 'password': '******' }) self.assertEqual(200, response.status_code)
def setUp(self): """Populates an active mission to test a cached view.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() self.pos = pos obst = StationaryObstacle() obst.gps_position = pos obst.cylinder_radius = 10 obst.cylinder_height = 10 obst.save() self.obst = obst config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.save() self.config = config config.stationary_obstacles.add(obst) config.save() self.login_url = reverse('auvsi_suas:login') self.obst_url = reverse('auvsi_suas:obstacles') self.clear_cache_url = reverse('auvsi_suas:clear_cache')
def test_satisfied_waypoints(self): """Tests the evaluation of waypoints method.""" # Create mission config gpos = GpsPosition() gpos.latitude = 10 gpos.longitude = 10 gpos.save() config = MissionConfig() config.home_pos = gpos config.emergent_last_known_pos = gpos config.off_axis_target_pos = gpos config.sric_pos = gpos config.air_drop_pos = gpos config.server_info = self.info config.save() # Create waypoints for config waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)] for i, waypoint in enumerate(waypoints): (lat, lon, alt) = waypoint pos = GpsPosition() pos.latitude = lat pos.longitude = lon pos.save() apos = AerialPosition() apos.altitude_msl = alt apos.gps_position = pos apos.save() wpt = Waypoint() wpt.position = apos wpt.order = i wpt.save() config.mission_waypoints.add(wpt) config.save() # Create UAS telemetry logs user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') def assertSatisfiedWaypoints(expect, got): """Assert two satisfied_waypoints return values are equal.""" self.assertEqual(expect[0], got[0]) self.assertEqual(expect[1], got[1]) for k in expect[2].keys(): self.assertIn(k, got[2]) self.assertAlmostEqual(expect[2][k], got[2][k], delta=0.1) for k in got[2].keys(): self.assertIn(k, expect[2]) # Only first is valid. entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)] expect = (1, 1, {0: 40, 1: 460785.17}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # First and last are valid, but missed second, so third doesn't count. entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)] expect = (1, 1, {0: 40, 1: 460785.03}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all, but don't stay within waypoint track. entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40)] expect = (3, 2, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Only hit the first waypoint on run one, hit all on run two. entries = [ (38, -76, 140), (40, -78, 600), (37, -75, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40) ] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all on run one, only hit the first waypoint on run two. entries = [ (38, -76, 140), (39, -77, 180), (40, -78, 40), # Run two: (38, -76, 140), (40, -78, 600), (37, -75, 40) ] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Remain on the waypoint track only on the second run. entries = [ (38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40) ] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Keep flying after hitting all waypoints. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40), (30.1, -78.1, 100)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Miss last target by a sane distance. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 60)] expect = (2, 2, {0: 40, 1: 20, 2: 60}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))
def test_satisfied_waypoints(self): """Tests the evaluation of waypoints method.""" data = TESTDATA_MISSIONCONFIG_EVALWAYPOINTS (waypoint_details, uas_log_details, exp_satisfied) = data # Create mission config gpos = GpsPosition() gpos.latitude = 10 gpos.longitude = 10 gpos.save() config = MissionConfig() config.home_pos = gpos config.emergent_last_known_pos = gpos config.off_axis_target_pos = gpos config.sric_pos = gpos config.air_drop_pos = gpos config.server_info = self.info config.save() # Create waypoints for config for wpt_id in xrange(len(waypoint_details)): (lat, lon, alt) = waypoint_details[wpt_id] pos = GpsPosition() pos.latitude = lat pos.longitude = lon pos.save() apos = AerialPosition() apos.altitude_msl = alt apos.gps_position = pos apos.save() wpt = Waypoint() wpt.position = apos wpt.order = wpt_id wpt.save() config.mission_waypoints.add(wpt) config.save() # Create UAS telemetry logs uas_logs = [] user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') for (lat, lon, alt) in uas_log_details: pos = GpsPosition() pos.latitude = lat pos.longitude = lon pos.save() apos = AerialPosition() apos.altitude_msl = alt apos.gps_position = pos apos.save() log = UasTelemetry() log.user = user log.uas_position = apos log.uas_heading = 0 log.save() uas_logs.append(log) # Assert correct satisfied waypoints wpts_satisfied = config.satisfied_waypoints(uas_logs) self.assertEqual(wpts_satisfied, exp_satisfied)
def test_unicode(self): """Tests the unicode method executes.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 100 pos.save() apos = AerialPosition() apos.altitude_msl = 1000 apos.gps_position = pos apos.save() wpt = Waypoint() wpt.position = apos wpt.order = 10 wpt.save() config = MissionConfig() config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.server_info = self.info config.save() config.mission_waypoints.add(wpt) config.search_grid_points.add(wpt) config.save() self.assertTrue(config.__unicode__())
class TestServerInfoView(TestCase): """Tests the server_info view.""" def setUp(self): """Sets up the client, server info URL, and user.""" cache.clear() self.user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') self.user.save() response = self.client.post(login_url, { 'username': '******', 'password': '******', }) self.assertEqual(200, response.status_code) self.info = ServerInfo() self.info.team_msg = 'test message' self.info.save() gpos = GpsPosition(latitude=0, longitude=0) gpos.save() self.mission = MissionConfig() self.mission.is_active = True self.mission.home_pos = gpos self.mission.emergent_last_known_pos = gpos self.mission.off_axis_target_pos = gpos self.mission.sric_pos = gpos self.mission.air_drop_pos = gpos self.mission.server_info = self.info self.mission.save() def test_invalid_request(self): """Tests an invalid request by mis-specifying parameters.""" response = self.client.post(info_url) self.assertEqual(405, response.status_code) def test_no_active_mission(self): """Tests that no active mission returns 500.""" self.mission.is_active = False self.mission.save() response = self.client.get(info_url) self.assertEqual(500, response.status_code) def test_correct_log_and_response(self): """Tests that access is logged and returns valid response.""" response = self.client.get(info_url) self.assertEqual(200, response.status_code) self.assertEqual(len(ServerInfoAccessLog.objects.all()), 1) access_log = ServerInfoAccessLog.objects.all()[0] self.assertEqual(access_log.user, self.user) json_data = json.loads(response.content) self.assertTrue('message' in json_data) self.assertTrue('message_timestamp' in json_data) self.assertTrue('server_time' in json_data) def test_loadtest(self): """Tests the max load the view can handle.""" if not settings.TEST_ENABLE_LOADTEST: return total_ops = 0 start_t = time.clock() while time.clock() - start_t < settings.TEST_LOADTEST_TIME: self.client.get(info_url) total_ops += 1 end_t = time.clock() total_t = end_t - start_t op_rate = total_ops / total_t print 'Server Info Rate (%f)' % op_rate self.assertGreaterEqual(op_rate, settings.TEST_LOADTEST_INTEROP_MIN_RATE)
def test_satisfied_waypoints(self): """Tests the evaluation of waypoints method.""" # Create mission config gpos = GpsPosition() gpos.latitude = 10 gpos.longitude = 10 gpos.save() config = MissionConfig() config.home_pos = gpos config.emergent_last_known_pos = gpos config.off_axis_target_pos = gpos config.sric_pos = gpos config.air_drop_pos = gpos config.server_info = self.info config.save() # Create waypoints for config waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)] for i, waypoint in enumerate(waypoints): (lat, lon, alt) = waypoint pos = GpsPosition() pos.latitude = lat pos.longitude = lon pos.save() apos = AerialPosition() apos.altitude_msl = alt apos.gps_position = pos apos.save() wpt = Waypoint() wpt.position = apos wpt.order = i wpt.save() config.mission_waypoints.add(wpt) config.save() # Create UAS telemetry logs user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') # Only first is valid. entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)] expect = (1, 1) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # First and last are valid, but missed second, so third doesn't count. entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)] expect = (1, 1) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Hit all. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Hit all, but don't stay within waypoint track. entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40)] expect = (3, 2) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Only hit the first waypoint on run one, hit all on run two. entries = [ (38, -76, 140), (40, -78, 600), (37, -75, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40) ] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Hit all on run one, only hit the first waypoint on run two. entries = [ (38, -76, 140), (39, -77, 180), (40, -78, 40), # Run two: (38, -76, 140), (40, -78, 600), (37, -75, 40) ] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Remain on the waypoint track only on the second run. entries = [ (38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40) ] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs))
def test_satisfied_waypoints(self): """Tests the evaluation of waypoints method.""" # Create mission config gpos = GpsPosition() gpos.latitude = 10 gpos.longitude = 10 gpos.save() config = MissionConfig() config.home_pos = gpos config.emergent_last_known_pos = gpos config.off_axis_target_pos = gpos config.sric_pos = gpos config.air_drop_pos = gpos config.server_info = self.info config.save() # Create waypoints for config waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)] for i, waypoint in enumerate(waypoints): (lat, lon, alt) = waypoint pos = GpsPosition() pos.latitude = lat pos.longitude = lon pos.save() apos = AerialPosition() apos.altitude_msl = alt apos.gps_position = pos apos.save() wpt = Waypoint() wpt.position = apos wpt.order = i wpt.save() config.mission_waypoints.add(wpt) config.save() # Create UAS telemetry logs user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') def assertSatisfiedWaypoints(expect, got): """Assert two satisfied_waypoints return values are equal.""" self.assertEqual(expect[0], got[0]) self.assertEqual(expect[1], got[1]) for k in expect[2].keys(): self.assertIn(k, got[2]) self.assertAlmostEqual(expect[2][k], got[2][k], delta=0.1) for k in got[2].keys(): self.assertIn(k, expect[2]) # Only first is valid. entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)] expect = (1, 1, {0: 40, 1: 460785.17}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # First and last are valid, but missed second, so third doesn't count. entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)] expect = (1, 1, {0: 40, 1: 460785.03}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all, but don't stay within waypoint track. entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40)] expect = (3, 2, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Only hit the first waypoint on run one, hit all on run two. entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all on run one, only hit the first waypoint on run two. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40), # Run two: (38, -76, 140), (40, -78, 600), (37, -75, 40)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Remain on the waypoint track only on the second run. entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Keep flying after hitting all waypoints. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40), (30.1, -78.1, 100)] expect = (3, 3, {0: 40, 1: 20, 2: 40}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Miss last target by a sane distance. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 60)] expect = (2, 2, {0: 40, 1: 20, 2: 60}) logs = self.create_uas_logs(user, entries) assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))
def test_satisfied_waypoints(self): """Tests the evaluation of waypoints method.""" # Create mission config gpos = GpsPosition() gpos.latitude = 10 gpos.longitude = 10 gpos.save() config = MissionConfig() config.home_pos = gpos config.emergent_last_known_pos = gpos config.off_axis_target_pos = gpos config.sric_pos = gpos config.air_drop_pos = gpos config.server_info = self.info config.save() # Create waypoints for config waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)] for i, waypoint in enumerate(waypoints): (lat, lon, alt) = waypoint pos = GpsPosition() pos.latitude = lat pos.longitude = lon pos.save() apos = AerialPosition() apos.altitude_msl = alt apos.gps_position = pos apos.save() wpt = Waypoint() wpt.position = apos wpt.order = i wpt.save() config.mission_waypoints.add(wpt) config.save() # Create UAS telemetry logs user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') # Only first is valid. entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)] expect = (1, 1) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # First and last are valid, but missed second, so third doesn't count. entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)] expect = (1, 1) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Hit all. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Hit all, but don't stay within waypoint track. entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40)] expect = (3, 2) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Only hit the first waypoint on run one, hit all on run two. entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Hit all on run one, only hit the first waypoint on run two. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40), # Run two: (38, -76, 140), (40, -78, 600), (37, -75, 40)] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs)) # Remain on the waypoint track only on the second run. entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40), (40, -78, 40), # Run two: (38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = (3, 3) logs = self.create_uas_logs(user, entries) self.assertEqual(expect, config.satisfied_waypoints(logs))
def setUp(self): """Populates an active mission to test a cached view.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() self.pos = pos info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() obst = StationaryObstacle() obst.gps_position = pos obst.cylinder_radius = 10 obst.cylinder_height = 10 obst.save() self.obst = obst config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.ir_primary_target_pos = pos config.ir_secondary_target_pos = pos config.air_drop_pos = pos config.server_info = info config.save() self.config = config config.stationary_obstacles.add(obst) config.save() self.login_url = reverse('auvsi_suas:login') self.obst_url = reverse('auvsi_suas:obstacles') self.clear_cache_url = reverse('auvsi_suas:clear_cache')
def setUp(self): self.user = User.objects.create_user("testuser", "*****@*****.**", "testpass") self.user.save() # Create an active mission. pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.air_drop_pos = pos config.server_info = info config.save() # Add a couple of stationary obstacles obst = self.create_stationary_obstacle(lat=38.142233, lon=-76.434082, radius=300, height=500) config.stationary_obstacles.add(obst) obst = self.create_stationary_obstacle(lat=38.442233, lon=-76.834082, radius=100, height=750) config.stationary_obstacles.add(obst) # And a couple of moving obstacles obst = self.create_moving_obstacle( [ # (lat, lon, alt) (38.142233, -76.434082, 300), (38.141878, -76.425198, 700), ] ) config.moving_obstacles.add(obst) obst = self.create_moving_obstacle( [ # (lat, lon, alt) (38.145405, -76.428310, 100), (38.146582, -76.424099, 200), (38.144662, -76.427634, 300), (38.147729, -76.419185, 200), (38.147573, -76.420832, 100), (38.148522, -76.419507, 750), ] ) config.moving_obstacles.add(obst) config.save() # Login response = self.client.post(login_url, {"username": "******", "password": "******"}) self.assertEqual(200, response.status_code)