Esempio n. 1
0
 def setUp(self):
     """Creates test data."""
     # Form test set for contains position
     self.testdata_containspos = []
     for test_data in TESTDATA_FLYZONE_CONTAINSPOS:
         # Create the FlyZone
         zone = FlyZone()
         zone.altitude_msl_min = test_data['min_alt']
         zone.altitude_msl_max = test_data['max_alt']
         zone.save()
         for waypoint_id in range(len(test_data['waypoints'])):
             (lat, lon) = test_data['waypoints'][waypoint_id]
             gpos = GpsPosition()
             gpos.latitude = lat
             gpos.longitude = lon
             gpos.save()
             apos = AerialPosition()
             apos.gps_position = gpos
             apos.altitude_msl = 0
             apos.save()
             wpt = Waypoint()
             wpt.order = waypoint_id
             wpt.position = apos
             wpt.save()
             zone.boundary_pts.add(wpt)
         # Form test set
         test_pos = []
         for pos in test_data['inside_pos']:
             test_pos.append((pos, True))
         for pos in test_data['outside_pos']:
             test_pos.append((pos, False))
         # Store
         self.testdata_containspos.append((zone, test_pos))
Esempio n. 2
0
 def setUp(self):
     """Creates test data."""
     # Form test set for contains position
     self.testdata_containspos = []
     for test_data in TESTDATA_FLYZONE_CONTAINSPOS:
         # Create the FlyZone
         zone = FlyZone()
         zone.altitude_msl_min = test_data['min_alt']
         zone.altitude_msl_max = test_data['max_alt']
         zone.save()
         for waypoint_id in range(len(test_data['waypoints'])):
             (lat, lon) = test_data['waypoints'][waypoint_id]
             gpos = GpsPosition()
             gpos.latitude = lat
             gpos.longitude = lon
             gpos.save()
             apos = AerialPosition()
             apos.gps_position = gpos
             apos.altitude_msl = 0
             apos.save()
             wpt = Waypoint()
             wpt.order = waypoint_id
             wpt.position = apos
             wpt.save()
             zone.boundary_pts.add(wpt)
         # Form test set
         test_pos = []
         for pos in test_data['inside_pos']:
             test_pos.append((pos, True))
         for pos in test_data['outside_pos']:
             test_pos.append((pos, False))
         # Store
         self.testdata_containspos.append((zone, test_pos))
Esempio n. 3
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     zone = FlyZone()
     zone.altitude_msl_min = 1
     zone.altitude_msl_max = 2
     zone.save()
     for _ in range(3):
         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()
         zone.boundary_pts.add(wpt)
     self.assertTrue(zone.__unicode__())
Esempio n. 4
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     zone = FlyZone()
     zone.altitude_msl_min = 1
     zone.altitude_msl_max = 2
     zone.save()
     for _ in range(3):
         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()
         zone.boundary_pts.add(wpt)
     self.assertTrue(zone.__unicode__())
Esempio n. 5
0
    def test_out_of_bounds(self):
        """Tests the UAS out of bounds method."""
        (zone_details, uas_details) = TESTDATA_FLYZONE_EVALBOUNDS
        # Create FlyZone objects
        zones = []
        for (alt_min, alt_max, wpts) in zone_details:
            zone = FlyZone()
            zone.altitude_msl_min = alt_min
            zone.altitude_msl_max = alt_max
            zone.save()
            for wpt_id in xrange(len(wpts)):
                (lat, lon) = wpts[wpt_id]
                gpos = GpsPosition()
                gpos.latitude = lat
                gpos.longitude = lon
                gpos.save()
                apos = AerialPosition()
                apos.gps_position = gpos
                apos.altitude_msl = 0
                apos.save()
                wpt = Waypoint()
                wpt.order = wpt_id
                wpt.position = apos
                wpt.save()
                zone.boundary_pts.add(wpt)
            zone.save()
            zones.append(zone)

        # For each user, validate time out of bounds
        user_id = 0
        epoch = timezone.now().replace(year=1970,
                                       month=1,
                                       day=1,
                                       hour=0,
                                       minute=0,
                                       second=0,
                                       microsecond=0)
        for exp_out_of_bounds_time, uas_log_details in uas_details:
            # Create the logs
            user = User.objects.create_user('testuser%d' % user_id,
                                            '*****@*****.**', 'testpass')
            user_id += 1
            uas_logs = []
            for (lat, lon, alt, timestamp) in uas_log_details:
                gpos = GpsPosition()
                gpos.latitude = lat
                gpos.longitude = lon
                gpos.save()
                apos = AerialPosition()
                apos.gps_position = gpos
                apos.altitude_msl = alt
                apos.save()
                log = UasTelemetry()
                log.user = user
                log.uas_position = apos
                log.uas_heading = 0
                log.save()
                log.timestamp = epoch + datetime.timedelta(seconds=timestamp)
                log.save()
                uas_logs.append(log)
            # Assert out of bounds time matches expected
            out_of_bounds_time = FlyZone.out_of_bounds(zones, uas_logs)
            self.assertAlmostEqual(out_of_bounds_time, exp_out_of_bounds_time)
Esempio n. 6
0
    def test_out_of_bounds(self):
        """Tests the UAS out of bounds method."""
        (zone_details, uas_details) = TESTDATA_FLYZONE_EVALBOUNDS
        # Create FlyZone objects
        zones = []
        for (alt_min, alt_max, wpts) in zone_details:
            zone = FlyZone()
            zone.altitude_msl_min = alt_min
            zone.altitude_msl_max = alt_max
            zone.save()
            for wpt_id in xrange(len(wpts)):
                (lat, lon) = wpts[wpt_id]
                gpos = GpsPosition()
                gpos.latitude = lat
                gpos.longitude = lon
                gpos.save()
                apos = AerialPosition()
                apos.gps_position = gpos
                apos.altitude_msl = 0
                apos.save()
                wpt = Waypoint()
                wpt.order = wpt_id
                wpt.position = apos
                wpt.save()
                zone.boundary_pts.add(wpt)
            zone.save()
            zones.append(zone)

        # For each user, validate time out of bounds
        user_id = 0
        epoch = timezone.now().replace(
            year=1970,
            month=1,
            day=1,
            hour=0,
            minute=0,
            second=0,
            microsecond=0)
        for exp_out_of_bounds_time, uas_log_details in uas_details:
            # Create the logs
            user = User.objects.create_user('testuser%d' % user_id,
                                            '*****@*****.**', 'testpass')
            user_id += 1
            uas_logs = []
            for (lat, lon, alt, timestamp) in uas_log_details:
                gpos = GpsPosition()
                gpos.latitude = lat
                gpos.longitude = lon
                gpos.save()
                apos = AerialPosition()
                apos.gps_position = gpos
                apos.altitude_msl = alt
                apos.save()
                log = UasTelemetry()
                log.user = user
                log.uas_position = apos
                log.uas_heading = 0
                log.save()
                log.timestamp = epoch + datetime.timedelta(seconds=timestamp)
                log.save()
                uas_logs.append(log)
            # Assert out of bounds time matches expected
            out_of_bounds_time = FlyZone.out_of_bounds(zones, uas_logs)
            self.assertAlmostEqual(out_of_bounds_time, exp_out_of_bounds_time)