本文整理汇总了Python中auvsi_suas.models.uas_telemetry.UasTelemetry.save方法的典型用法代码示例。如果您正苦于以下问题:Python UasTelemetry.save方法的具体用法?Python UasTelemetry.save怎么用?Python UasTelemetry.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auvsi_suas.models.uas_telemetry.UasTelemetry
的用法示例。
在下文中一共展示了UasTelemetry.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_logs
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def create_logs(self,
user,
num=10,
start=None,
delta=None,
altitude=100,
heading=90):
if start is None:
start = timezone.now()
if delta is None:
delta = datetime.timedelta(seconds=1)
logs = []
for i in xrange(num):
gps = GpsPosition(latitude=38 + 0.001 * i,
longitude=-78 + 0.001 * i)
gps.save()
pos = AerialPosition(gps_position=gps, altitude_msl=altitude)
pos.save()
log = UasTelemetry(user=user,
uas_position=pos,
uas_heading=heading)
log.save()
log.timestamp = start + i * delta
log.save()
logs.append(log)
return logs
示例2: create_uas_logs
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def create_uas_logs(self, user, entries):
"""Create a list of uas telemetry logs.
Args:
user: User to create logs for.
entries: List of (lat, lon, alt) tuples for each entry.
Returns:
List of UasTelemetry objects
"""
ret = []
for (lat, lon, alt) in entries:
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()
ret.append(log)
return ret
示例3: create_log_element
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def create_log_element(self, lat, lon, alt, user, log_time):
pos = GpsPosition(latitude=lat, longitude=lon)
pos.save()
apos = AerialPosition(gps_position=pos, altitude_msl=alt)
apos.save()
log = UasTelemetry(user=user, uas_position=apos, uas_heading=100, )
log.save()
log.timestamp = log_time
log.save()
return log
示例4: create_log_element
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def create_log_element(self, timestamp, user, lat, lon, alt, heading):
pos = GpsPosition(latitude=lat, longitude=lon)
pos.save()
apos = AerialPosition(gps_position=pos, altitude_msl=alt)
apos.save()
log = UasTelemetry(timestamp=timezone.now(),
user=user,
uas_position=apos,
uas_heading=heading)
log.save()
return log
示例5: test_evaluate_collision_with_uas
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def test_evaluate_collision_with_uas(self):
"""Tests the collision with UAS method."""
# Create testing data
user = User.objects.create_user('testuser', '[email protected]',
'testpass')
user.save()
(cyl_details, inside_pos,
outside_pos) = TESTDATA_STATOBST_EVALCOLLISION
(cyl_lat, cyl_lon, cyl_height, cyl_rad) = cyl_details
gpos = GpsPosition(latitude=cyl_lat, longitude=cyl_lon)
gpos.save()
obst = StationaryObstacle(gps_position=gpos,
cylinder_radius=cyl_rad,
cylinder_height=cyl_height)
obst.save()
inside_logs = []
outside_logs = []
logs_to_create = [
(inside_pos, inside_logs), (outside_pos, outside_logs)
]
for (positions, log_list) in logs_to_create:
for (lat, lon, alt) in positions:
gpos = GpsPosition(latitude=lat, longitude=lon)
gpos.save()
apos = AerialPosition(gps_position=gpos, altitude_msl=alt)
apos.save()
log = UasTelemetry(user=user, uas_position=apos, uas_heading=0)
log.save()
log_list.append(log)
# Assert collisions correctly evaluated
collisions = [(inside_logs, True), (outside_logs, False)]
for (log_list, inside) in collisions:
self.assertEqual(
obst.evaluate_collision_with_uas(log_list), inside)
for log in log_list:
self.assertEqual(
obst.evaluate_collision_with_uas([log]), inside)
示例6: create_logs
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def create_logs(self, user, num=10, start=None, delta=None):
if start is None:
start = timezone.now()
if delta is None:
delta = datetime.timedelta(seconds=1)
logs = []
for i in xrange(num):
gps_position = GpsPosition(latitude=0, longitude=0)
gps_position.save()
uas_position = AerialPosition(gps_position=gps_position,
altitude_msl=0)
uas_position.save()
log = UasTelemetry(user=user,
uas_position=uas_position,
uas_heading=0.0)
log.save()
log.timestamp = start + i * delta
log.save()
logs.append(log)
return logs
示例7: test_out_of_bounds
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
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_violations, exp_out_of_bounds_time, log_details in uas_details:
# Create the logs
user = User.objects.create_user('testuser%d' % user_id,
'[email protected]', 'testpass')
user_id += 1
uas_logs = []
for (lat, lon, alt, timestamp) in 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
num_violations, out_of_bounds_time = \
FlyZone.out_of_bounds(zones, uas_logs)
self.assertEqual(num_violations, exp_violations)
self.assertAlmostEqual(out_of_bounds_time, exp_out_of_bounds_time)
示例8: test_evaluate_collision_with_uas
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def test_evaluate_collision_with_uas(self):
"""Tests the collision with UAS method."""
# Get test data
user = User.objects.create_user('testuser', '[email protected]',
'testpass')
user.save()
testdata = TESTDATA_MOVOBST_EVALCOLLISION
(obst_rad, obst_speed, obst_pos, log_details) = testdata
# Create the obstacle
obst = MovingObstacle()
obst.speed_avg = obst_speed
obst.sphere_radius = obst_rad
obst.save()
for pos_id in xrange(len(obst_pos)):
(lat, lon, alt) = obst_pos[pos_id]
gpos = GpsPosition()
gpos.latitude = lat
gpos.longitude = lon
gpos.save()
apos = AerialPosition()
apos.gps_position = gpos
apos.altitude_msl = alt
apos.save()
wpt = Waypoint()
wpt.order = pos_id
wpt.position = apos
wpt.save()
obst.waypoints.add(wpt)
obst.save()
# Create sets of logs
epoch = timezone.now().replace(year=1970,
month=1,
day=1,
hour=0,
minute=0,
second=0,
microsecond=0)
inside_logs = []
outside_logs = []
for (time_sec, inside_pos, outside_pos) in log_details:
log_time = epoch + datetime.timedelta(seconds=time_sec)
logs_pos = [(inside_pos, inside_logs), (outside_pos, outside_logs)]
for (positions, log_list) in logs_pos:
for (lat, lon, alt) in positions:
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 = log_time
log.save()
log_list.append(log)
# Assert the obstacle correctly computes collisions
log_collisions = [(True, inside_logs), (False, outside_logs)]
for (inside, logs) in log_collisions:
self.assertEqual(obst.evaluate_collision_with_uas(logs), inside)
for log in logs:
self.assertEqual(
obst.evaluate_collision_with_uas([log]), inside)
示例9: test_interpolated_collision
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def test_interpolated_collision(self):
# Get test data
user = User.objects.create_user('testuser', '[email protected]',
'testpass')
user.save()
utm = distance.proj_utm(zone=18, north=True)
(obst_rad, obst_speed, obst_pos, log_details) = TESTDATA_MOVOBST_INTERP
# Create the obstacle
obst = MovingObstacle()
obst.speed_avg = obst_speed
obst.sphere_radius = obst_rad
obst.save()
for pos_id in xrange(len(obst_pos)):
(lat, lon, alt) = obst_pos[pos_id]
gpos = GpsPosition()
gpos.latitude = lat
gpos.longitude = lon
gpos.save()
apos = AerialPosition()
apos.gps_position = gpos
apos.altitude_msl = alt
apos.save()
wpt = Waypoint()
wpt.order = pos_id
wpt.position = apos
wpt.save()
obst.waypoints.add(wpt)
obst.save()
for (inside, log_list) in log_details:
logs = []
for i in range(len(log_list)):
lat, lon, alt = log_list[i]
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()
if i == 0:
log.timestamp = timezone.now().replace(year=1970,
month=1,
day=1,
hour=0,
minute=0,
second=0,
microsecond=0)
if i > 0:
log.timestamp = (
logs[i - 1].timestamp + datetime.timedelta(seconds=1))
logs.append(log)
self.assertEqual(
obst.determine_interpolated_collision(logs[0], logs[1], utm),
inside)
示例10: TestTeamsView
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
class TestTeamsView(TestCase):
"""Tests the teams view."""
def setUp(self):
self.superuser = User.objects.create_superuser(
'superuser', '[email protected]', 'superpass')
self.superuser.save()
# Login
response = self.client.post(login_url, {
'username': 'superuser',
'password': 'superpass'
})
self.assertEqual(200, response.status_code)
def create_data(self):
"""Create a basic sample dataset."""
self.user1 = User.objects.create_user('user1', '[email protected]',
'testpass')
self.user1.save()
self.user2 = User.objects.create_user('user2', '[email protected]',
'testpass')
self.user2.save()
# user1 is on mission
event = MissionClockEvent(user=self.user1,
team_on_clock=True,
team_on_timeout=False)
event.save()
# user1 is flying
event = TakeoffOrLandingEvent(user=self.user1, uas_in_air=True)
event.save()
# user2 has landed
event = TakeoffOrLandingEvent(user=self.user2, uas_in_air=True)
event.save()
event = TakeoffOrLandingEvent(user=self.user2, uas_in_air=False)
event.save()
# user2 is active
self.timestamp = timezone.now()
gps = GpsPosition(latitude=38.6462, longitude=-76.2452)
gps.save()
pos = AerialPosition(gps_position=gps, altitude_msl=0)
pos.save()
self.telem = UasTelemetry(user=self.user2,
uas_position=pos,
uas_heading=90)
self.telem.save()
self.telem.timestamp = dateutil.parser.parse(
u'2016-10-01T00:00:00.0+00:00')
self.telem.save()
def test_normal_user(self):
"""Normal users not allowed access."""
user = User.objects.create_user('testuser', '[email protected]',
'testpass')
user.save()
# Login
response = self.client.post(login_url, {
'username': 'testuser',
'password': 'testpass'
})
self.assertEqual(200, response.status_code)
response = self.client.get(teams_url)
self.assertEqual(403, response.status_code)
def test_no_users(self):
"""No users results in empty list, no superusers."""
response = self.client.get(teams_url)
self.assertEqual(200, response.status_code)
self.assertEqual([], json.loads(response.content))
def test_post(self):
"""POST not allowed"""
response = self.client.post(teams_url)
self.assertEqual(405, response.status_code)
def test_correct_json(self):
"""Response JSON is properly formatted."""
self.create_data()
response = self.client.get(teams_url)
self.assertEqual(200, response.status_code)
data = json.loads(response.content)
self.assertEqual(2, len(data))
for user in data:
self.assertIn('id', user)
self.assertIn('name', user)
#.........这里部分代码省略.........
示例11: post
# 需要导入模块: from auvsi_suas.models.uas_telemetry import UasTelemetry [as 别名]
# 或者: from auvsi_suas.models.uas_telemetry.UasTelemetry import save [as 别名]
def post(self, request):
"""Posts the UAS position with a POST request.
User must send a POST request with the following paramters:
latitude: A latitude in decimal degrees.
longitude: A logitude in decimal degrees.
altitude_msl: An MSL altitude in decimal feet.
uas_heading: The UAS (true north) heading in decimal degrees.
"""
try:
# Get the parameters
latitude = float(request.POST['latitude'])
longitude = float(request.POST['longitude'])
altitude_msl = float(request.POST['altitude_msl'])
uas_heading = float(request.POST['uas_heading'])
except KeyError:
# Failed to get POST parameters
logger.warning(
'User did not specify all params for uas telemetry request.')
logger.debug(request)
return HttpResponseBadRequest(
'Posting UAS position must contain POST parameters "latitude", '
'"longitude", "altitude_msl", and "uas_heading".')
except ValueError:
# Failed to convert parameters
logger.warning(
'User specified a param which could not converted to an ' +
'appropriate type.')
logger.debug(request)
return HttpResponseBadRequest(
'Failed to convert provided POST parameters to correct form.')
else:
# Check the values make sense
if latitude < -90 or latitude > 90:
logger.warning('User specified latitude out of valid range.')
logger.debug(request)
return HttpResponseBadRequest(
'Must provide latitude between -90 and 90 degrees.')
if longitude < -180 or longitude > 180:
logger.warning('User specified longitude out of valid range.')
logger.debug(request)
return HttpResponseBadRequest(
'Must provide longitude between -180 and 180 degrees.')
if uas_heading < 0 or uas_heading > 360:
logger.warning('User specified altitude out of valid range.')
logger.debug(request)
return HttpResponseBadRequest(
'Must provide heading between 0 and 360 degrees.')
# Store telemetry
logger.info('User uploaded telemetry: %s' % request.user.username)
gpos = GpsPosition(latitude=latitude, longitude=longitude)
gpos.save()
apos = AerialPosition(gps_position=gpos, altitude_msl=altitude_msl)
apos.save()
telemetry = UasTelemetry(user=request.user,
uas_position=apos,
uas_heading=uas_heading)
telemetry.save()
return HttpResponse('UAS Telemetry Successfully Posted.')