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): """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))
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 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 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__())
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)
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)