Esempio n. 1
0
    def get(self, request):
        kml = Kml(name='AUVSI SUAS Flight Data')
        kml_missions = kml.newfolder(name='Missions')
        users = User.objects.all()
        for mission in MissionConfig.objects.all():
            kml_mission = mission_kml(mission, kml_missions, kml.document)
            kml_flights = kml_mission.newfolder(name='Flights')
            for user in users:
                if user.is_superuser:
                    continue
                flights = TakeoffOrLandingEvent.flights(mission, user)
                if not flights:
                    continue
                uas_telemetry_kml(
                    user=user,
                    flights=flights,
                    logs=UasTelemetry.by_user(user),
                    kml=kml_flights,
                    kml_doc=kml.document)

        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
Esempio n. 2
0
    def __init__(self, submitted_objects, real_objects):
        """Creates an evaluation of submitted objects against real objects.

        Args:
            submitted_objects: List of submitted Odlc objects, all from
                               the same user.
            real_objects: List of real objects made by judges.

        Raises:
            AssertionError: not all submitted objects are from the same user.
        """
        self.submitted_objects = submitted_objects
        self.real_objects = real_objects

        if self.submitted_objects:
            self.user = self.submitted_objects[0].user
            for t in self.submitted_objects:
                if t.user != self.user:
                    raise AssertionError(
                        "All submitted objects must be from the same user")

            self.flights = TakeoffOrLandingEvent.flights(self.user)

        self.matches = self.match_odlcs(submitted_objects, real_objects)
        self.unmatched = self.find_unmatched(submitted_objects, real_objects,
                                             self.matches)
Esempio n. 3
0
    def actionable_submission(self, flights=None):
        """Checks if Odlc meets Actionable Intelligence submission criteria.

        A object is "actionable" if one of the following conditions is met:
            (a) If it was submitted over interop and last updated during the
                aircraft's first flight.
            (b) If the object was submitted via USB, the object's
                actionable_override flag was set by an admin.

        Args:
            flights: Optional memoized flights for this object's user. If
                     omitted, the flights will be looked up.

        Returns:
            True if object may be considered an "actionable" submission.
        """
        if flights is None:
            flights = TakeoffOrLandingEvent.flights(self.user)

        actionable = False
        if len(flights) > 0:
            flight = flights[0]
            if flight.within(self.creation_time) and \
                flight.within(self.last_modified_time):
                actionable = True

        return self.actionable_override or actionable
Esempio n. 4
0
def generate_feedback(mission_config, user, team_eval):
    """Generates mission feedback for the given team and mission.

    Args:
        mission_config: The mission to evaluate the team against.
        user: The team user object for which to evaluate and provide feedback.
        team_eval: The team evaluation to fill.
    """
    feedback = team_eval.feedback

    # Find the user's flights.
    flight_periods = TakeoffOrLandingEvent.flights(mission_config, user)
    for period in flight_periods:
        if period.duration() is None:
            team_eval.warnings.append('Infinite flight period.')
    uas_period_logs = [
        UasTelemetry.dedupe(logs)
        for logs in UasTelemetry.by_time_period(user, flight_periods)
    ]
    uas_logs = list(itertools.chain.from_iterable(uas_period_logs))
    if not uas_logs:
        team_eval.warnings.append('No UAS telemetry logs.')

    # Determine interop telemetry rates.
    telem_max, telem_avg = UasTelemetry.rates(
        user, flight_periods, time_period_logs=uas_period_logs)
    if telem_max:
        feedback.uas_telemetry_time_max_sec = telem_max
    if telem_avg:
        feedback.uas_telemetry_time_avg_sec = telem_avg

    # Determine if the uas hit the waypoints.
    feedback.waypoints.extend(
        UasTelemetry.satisfied_waypoints(
            mission_config.home_pos,
            mission_config.mission_waypoints.order_by('order'), uas_logs))

    # Evaluate the object detections.
    user_odlcs = Odlc.objects.filter(user=user).filter(
        mission=mission_config.pk).all()
    evaluator = OdlcEvaluator(user_odlcs,
                              mission_config.odlcs.all(), flight_periods)
    feedback.odlc.CopyFrom(evaluator.evaluate())

    # Determine collisions with stationary.
    for obst in mission_config.stationary_obstacles.all():
        obst_eval = feedback.stationary_obstacles.add()
        obst_eval.id = obst.pk
        obst_eval.hit = obst.evaluate_collision_with_uas(uas_logs)

    # Add judge feedback.
    try:
        judge_feedback = MissionJudgeFeedback.objects.get(
            mission=mission_config.pk, user=user.pk)
        feedback.judge.CopyFrom(judge_feedback.proto())
    except MissionJudgeFeedback.DoesNotExist:
        team_eval.warnings.append('No MissionJudgeFeedback for team.')
Esempio n. 5
0
    def kml(cls, user, logs, kml, kml_doc):
        """
        Appends kml nodes describing the given user's flight as described
        by the log array given.

        Args:
            user: A Django User to get username from
            logs: A list of UasTelemetry elements
            kml: A simpleKML Container to which the flight data will be added
            kml_doc: The simpleKML Document to which schemas will be added
        Returns:
            None
        """
        kml_folder = kml.newfolder(name=user.username)

        flights = TakeoffOrLandingEvent.flights(user)
        if len(flights) == 0:
            return

        logs = UasTelemetry.dedupe(UasTelemetry.filter_bad(logs))
        for i, flight in enumerate(flights):
            name = '%s Flight %d' % (user.username, i + 1)
            flight_logs = filter(lambda x: flight.within(x.timestamp), logs)

            coords = []
            angles = []
            when = []
            for entry in logs:
                pos = entry.uas_position.gps_position
                # Spatial Coordinates
                coord = (pos.longitude, pos.latitude,
                         units.feet_to_meters(entry.uas_position.altitude_msl))
                coords.append(coord)

                # Time Elements
                time = entry.timestamp.strftime(KML_DATETIME_FORMAT)
                when.append(time)

                # Degrees heading, tilt, and roll
                angle = (entry.uas_heading, 0.0, 0.0)
                angles.append(angle)

            # Create a new track in the folder
            trk = kml_folder.newgxtrack(name=name)
            trk.altitudemode = AltitudeMode.absolute

            # Append flight data
            trk.newwhen(when)
            trk.newgxcoord(coords)
            trk.newgxangle(angles)

            # Set styling
            trk.extrude = 1  # Extend path to ground
            trk.style.linestyle.width = 2
            trk.style.linestyle.color = Color.blue
            trk.iconstyle.icon.href = KML_PLANE_ICON
Esempio n. 6
0
def evaluate_teams(mission_config, users=None):
    """Evaluates the teams (non admin users) of the competition.

    Args:
        mission_config: The mission to evaluate users against.
        users: Optional list of users to eval. If None will evaluate all.
    Returns:
        A auvsi_suas.proto.MultiUserMissionEvaluation.
    """
    # Start a results map from user to MissionEvaluation.
    mission_eval = interop_admin_api_pb2.MultiUserMissionEvaluation()

    # If not provided, eval all users.
    if users is None:
        users = User.objects.all()

    logger.info('Starting team evaluations.')
    for user in sorted(users, key=lambda u: u.username):
        # Ignore admins.
        if user.is_superuser:
            continue

        # Ignore users with no flights for mission.
        if not TakeoffOrLandingEvent.flights(mission_config, user):
            logger.info('Skipping user with no flights: %s' % user.username)
            continue

        # Start the evaluation data structure.
        logger.info('Evaluation starting for user: %s.' % user.username)
        team_eval = mission_eval.teams.add()
        team_eval.team = user.username
        # Generate feedback.
        generate_feedback(mission_config, user, team_eval)
        # Generate score from feedback.
        score_team(team_eval)

    return mission_eval
Esempio n. 7
0
def generate_feedback(mission_config, user, team_eval):
    """Generates mission feedback for the given team and mission.

    Args:
        mission_config: The mission to evaluate the team against.
        user: The team user object for which to evaluate and provide feedback.
        team_eval: The team evaluation to fill.
    """
    feedback = team_eval.feedback

    # Calculate the total mission clock time.
    missions = MissionClockEvent.missions(user)
    mission_clock_time = datetime.timedelta(seconds=0)
    for mission in missions:
        duration = mission.duration()
        if duration is None:
            team_eval.warnings.append('Infinite mission clock.')
        else:
            mission_clock_time += duration
    feedback.mission_clock_time_sec = mission_clock_time.total_seconds()

    # Calculate total time in air.
    flight_periods = TakeoffOrLandingEvent.flights(user)
    if flight_periods:
        flight_time = reduce(lambda x, y: x + y,
                             [p.duration() for p in flight_periods])
        feedback.flight_time_sec = flight_time.total_seconds()
    else:
        feedback.flight_time_sec = 0
    # Find the user's flights.
    for period in flight_periods:
        if period.duration() is None:
            team_eval.warnings.append('Infinite flight period.')
    uas_period_logs = [
        UasTelemetry.dedupe(logs)
        for logs in UasTelemetry.by_time_period(user, flight_periods)
    ]
    uas_logs = list(itertools.chain.from_iterable(uas_period_logs))
    if not uas_logs:
        team_eval.warnings.append('No UAS telemetry logs.')

    # Determine interop telemetry rates.
    telem_max, telem_avg = UasTelemetry.rates(user,
                                              flight_periods,
                                              time_period_logs=uas_period_logs)
    if telem_max:
        feedback.uas_telemetry_time_max_sec = telem_max
    if telem_avg:
        feedback.uas_telemetry_time_avg_sec = telem_avg

    # Determine if the uas went out of bounds. This must be done for
    # each period individually so time between periods isn't counted as
    # out of bounds time. Note that this calculates reported time out
    # of bounds, not actual or possible time spent out of bounds.
    out_of_bounds = datetime.timedelta(seconds=0)
    feedback.boundary_violations = 0
    for logs in uas_period_logs:
        bv, bt = FlyZone.out_of_bounds(mission_config.fly_zones.all(), logs)
        feedback.boundary_violations += bv
        out_of_bounds += bt
    feedback.out_of_bounds_time_sec = out_of_bounds.total_seconds()

    # Determine if the uas hit the waypoints.
    feedback.waypoints.extend(
        UasTelemetry.satisfied_waypoints(
            mission_config.home_pos,
            mission_config.mission_waypoints.order_by('order'), uas_logs))

    # Evaluate the object detections.
    user_odlcs = Odlc.objects.filter(user=user).all()
    evaluator = OdlcEvaluator(user_odlcs, mission_config.odlcs.all())
    feedback.odlc.CopyFrom(evaluator.evaluate())

    # Determine collisions with stationary and moving obstacles.
    for obst in mission_config.stationary_obstacles.all():
        obst_eval = feedback.stationary_obstacles.add()
        obst_eval.id = obst.pk
        obst_eval.hit = obst.evaluate_collision_with_uas(uas_logs)
    for obst in mission_config.moving_obstacles.all():
        obst_eval = feedback.moving_obstacles.add()
        obst_eval.id = obst.pk
        obst_eval.hit = obst.evaluate_collision_with_uas(uas_logs)

    # Add judge feedback.
    try:
        judge_feedback = MissionJudgeFeedback.objects.get(
            mission=mission_config.pk, user=user.pk)
        feedback.judge.CopyFrom(judge_feedback.proto())
    except MissionJudgeFeedback.DoesNotExist:
        team_eval.warnings.append('No MissionJudgeFeedback for team.')

    # Sanity check mission time.
    judge_mission_clock = (feedback.judge.flight_time_sec +
                           feedback.judge.post_process_time_sec)
    if abs(feedback.mission_clock_time_sec - judge_mission_clock) > 30:
        team_eval.warnings.append(
            'Mission clock differs between interop and judge.')
Esempio n. 8
0
    def evaluate_periods(self, expected):
        """Check actual periods against expected."""
        periods = TakeoffOrLandingEvent.flights(self.user1)

        self.assertSequenceEqual(expected, periods)
Esempio n. 9
0
def generate_feedback(mission_config, user, team_eval):
    """Generates mission feedback for the given team and mission.

    Args:
        mission_config: The mission to evaluate the team against.
        user: The team user object for which to evaluate and provide feedback.
        team_eval: The team evaluation to fill.
    """
    feedback = team_eval.feedback

    # Calculate the total mission clock time.
    missions = MissionClockEvent.missions(user)
    mission_clock_time = datetime.timedelta(seconds=0)
    for mission in missions:
        duration = mission.duration()
        if duration is None:
            team_eval.warnings.append('Infinite mission clock.')
        else:
            mission_clock_time += duration
    feedback.mission_clock_time_sec = mission_clock_time.total_seconds()

    # Calculate total time in air.
    flight_periods = TakeoffOrLandingEvent.flights(user)
    if flight_periods:
        flight_time = reduce(lambda x, y: x + y, [p.duration()
                                                  for p in flight_periods])
        feedback.flight_time_sec = flight_time.total_seconds()
    else:
        feedback.flight_time_sec = 0
    # Find the user's flights.
    for period in flight_periods:
        if period.duration() is None:
            team_eval.warnings.append('Infinite flight period.')
    uas_period_logs = [
        UasTelemetry.dedupe(logs)
        for logs in UasTelemetry.by_time_period(user, flight_periods)
    ]
    uas_logs = list(itertools.chain.from_iterable(uas_period_logs))
    if not uas_logs:
        team_eval.warnings.append('No UAS telemetry logs.')

    # Determine interop telemetry rates.
    telem_max, telem_avg = UasTelemetry.rates(user,
                                              flight_periods,
                                              time_period_logs=uas_period_logs)
    if telem_max:
        feedback.uas_telemetry_time_max_sec = telem_max
    if telem_avg:
        feedback.uas_telemetry_time_avg_sec = telem_avg

    # Determine if the uas went out of bounds. This must be done for
    # each period individually so time between periods isn't counted as
    # out of bounds time. Note that this calculates reported time out
    # of bounds, not actual or possible time spent out of bounds.
    out_of_bounds = datetime.timedelta(seconds=0)
    feedback.boundary_violations = 0
    for logs in uas_period_logs:
        bv, bt = FlyZone.out_of_bounds(mission_config.fly_zones.all(), logs)
        feedback.boundary_violations += bv
        out_of_bounds += bt
    feedback.out_of_bounds_time_sec = out_of_bounds.total_seconds()

    # Determine if the uas hit the waypoints.
    feedback.waypoints.extend(UasTelemetry.satisfied_waypoints(
        mission_config.home_pos, mission_config.mission_waypoints.order_by(
            'order'), uas_logs))

    # Evaluate the targets.
    user_targets = Target.objects.filter(user=user).all()
    evaluator = TargetEvaluator(user_targets, mission_config.targets.all())
    feedback.target.CopyFrom(evaluator.evaluate())

    # Determine collisions with stationary and moving obstacles.
    for obst in mission_config.stationary_obstacles.all():
        obst_eval = feedback.stationary_obstacles.add()
        obst_eval.id = obst.pk
        obst_eval.hit = obst.evaluate_collision_with_uas(uas_logs)
    for obst in mission_config.moving_obstacles.all():
        obst_eval = feedback.moving_obstacles.add()
        obst_eval.id = obst.pk
        obst_eval.hit = obst.evaluate_collision_with_uas(uas_logs)

    # Add judge feedback.
    try:
        judge_feedback = MissionJudgeFeedback.objects.get(
            mission=mission_config.pk,
            user=user.pk)
        feedback.judge.CopyFrom(judge_feedback.proto())
    except MissionJudgeFeedback.DoesNotExist:
        team_eval.warnings.append('No MissionJudgeFeedback for team.')

    # Sanity check mission time.
    judge_mission_clock = (
        feedback.judge.flight_time_sec + feedback.judge.post_process_time_sec)
    if abs(feedback.mission_clock_time_sec - judge_mission_clock) > 30:
        team_eval.warnings.append(
            'Mission clock differs between interop and judge.')
Esempio n. 10
0
    def kml(cls, user, logs, kml, kml_doc):
        """
        Appends kml nodes describing the given user's flight as described
        by the log array given.

        Args:
            user: A Django User to get username from
            logs: A list of UasTelemetry elements
            kml: A simpleKML Container to which the flight data will be added
            kml_doc: The simpleKML Document to which schemas will be added
        Returns:
            None
        """
        # KML Compliant Datetime Formatter
        kml_datetime_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        icon = 'http://maps.google.com/mapfiles/kml/shapes/airports.png'

        kml_folder = kml.newfolder(name=user.username)

        flights = TakeoffOrLandingEvent.flights(user)
        if len(flights) == 0:
            return

        logs = UasTelemetry.dedupe(UasTelemetry.filter_bad(logs))
        for i, flight in enumerate(flights):
            label = 'Flight {}'.format(i + 1)  # Flights are one-indexed
            kml_flight = kml_folder.newfolder(name=label)

            flight_logs = filter(lambda x: flight.within(x.timestamp), logs)
            if len(flight_logs) < 2:
                continue

            coords = []
            angles = []
            when = []
            for entry in flight_logs:
                pos = entry.uas_position.gps_position
                # Spatial Coordinates
                coord = (pos.longitude, pos.latitude,
                         units.feet_to_meters(entry.uas_position.altitude_msl))
                coords.append(coord)

                # Time Elements
                time = entry.timestamp.strftime(kml_datetime_format)
                when.append(time)

                # Degrees heading, tilt, and roll
                angle = (entry.uas_heading, 0.0, 0.0)
                angles.append(angle)

            # Create a new track in the folder
            trk = kml_flight.newgxtrack(name='Flight Path')
            trk.altitudemode = AltitudeMode.absolute

            # Append flight data
            trk.newwhen(when)
            trk.newgxcoord(coords)
            trk.newgxangle(angles)

            # Set styling
            trk.extrude = 1  # Extend path to ground
            trk.style.linestyle.width = 2
            trk.style.linestyle.color = Color.blue
            trk.iconstyle.icon.href = icon
    def evaluate_periods(self, expected):
        """Check actual periods against expected."""
        periods = TakeoffOrLandingEvent.flights(self.user1)

        self.assertSequenceEqual(expected, periods)
Esempio n. 12
0
    def setUp(self):
        """Setup the test case."""
        super(TestOdlcEvaluator, self).setUp()
        self.maxDiff = None
        self.user = User.objects.create_user('user', '*****@*****.**',
                                             'pass')

        l1 = GpsPosition(latitude=38, longitude=-76)
        l1.save()
        l2 = GpsPosition(latitude=38.0003, longitude=-76)
        l2.save()
        l3 = GpsPosition(latitude=-38, longitude=76)
        l3.save()
        l4 = GpsPosition(latitude=0, longitude=0)
        l4.save()

        # Mission
        pos = GpsPosition()
        pos.latitude = 10
        pos.longitude = 100
        pos.save()
        wpt = Waypoint()
        wpt.order = 10
        wpt.latitude = 10
        wpt.longitude = 100
        wpt.altitude_msl = 1000
        wpt.save()
        self.mission = MissionConfig()
        self.mission.home_pos = pos
        self.mission.lost_comms_pos = pos
        self.mission.emergent_last_known_pos = pos
        self.mission.off_axis_odlc_pos = pos
        self.mission.map_center_pos = pos
        self.mission.map_height_ft = 1
        self.mission.air_drop_pos = pos
        self.mission.ugv_drive_pos = pos
        self.mission.save()
        self.mission.mission_waypoints.add(wpt)
        self.mission.search_grid_points.add(wpt)
        self.mission.save()

        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=True)
        event.save()

        # A odlc worth full points.
        self.submit1 = Odlc(mission=self.mission,
                            user=self.user,
                            odlc_type=interop_api_pb2.Odlc.STANDARD,
                            location=l1,
                            orientation=interop_api_pb2.Odlc.S,
                            shape=interop_api_pb2.Odlc.SQUARE,
                            shape_color=interop_api_pb2.Odlc.WHITE,
                            alphanumeric='ABC',
                            alphanumeric_color=interop_api_pb2.Odlc.BLACK,
                            description='Submit test odlc 1',
                            description_approved=True,
                            autonomous=True,
                            thumbnail_approved=True)
        self.submit1.save()
        self.real1 = Odlc(mission=self.mission,
                          user=self.user,
                          odlc_type=interop_api_pb2.Odlc.STANDARD,
                          location=l1,
                          orientation=interop_api_pb2.Odlc.S,
                          shape=interop_api_pb2.Odlc.SQUARE,
                          shape_color=interop_api_pb2.Odlc.WHITE,
                          alphanumeric='ABC',
                          alphanumeric_color=interop_api_pb2.Odlc.BLACK,
                          description='Real odlc 1')
        self.real1.save()

        # A odlc worth less than full points.
        self.submit2 = Odlc(
            mission=self.mission,
            user=self.user,
            odlc_type=interop_api_pb2.Odlc.STANDARD,
            location=l1,
            orientation=interop_api_pb2.Odlc.N,
            shape=interop_api_pb2.Odlc.CIRCLE,
            shape_color=interop_api_pb2.Odlc.WHITE,
            # alphanumeric set below
            alphanumeric_color=interop_api_pb2.Odlc.BLACK,
            description='Submit test odlc 2',
            autonomous=False,
            thumbnail_approved=True)
        self.submit2.save()
        self.real2 = Odlc(mission=self.mission,
                          user=self.user,
                          odlc_type=interop_api_pb2.Odlc.STANDARD,
                          location=l2,
                          orientation=interop_api_pb2.Odlc.S,
                          shape=interop_api_pb2.Odlc.TRIANGLE,
                          shape_color=interop_api_pb2.Odlc.WHITE,
                          alphanumeric='ABC',
                          alphanumeric_color=interop_api_pb2.Odlc.BLACK,
                          description='Real test odlc 2')
        self.real2.save()

        # A odlc worth no points, so unmatched.
        self.submit3 = Odlc(mission=self.mission,
                            user=self.user,
                            odlc_type=interop_api_pb2.Odlc.STANDARD,
                            location=l4,
                            orientation=interop_api_pb2.Odlc.NW,
                            shape=interop_api_pb2.Odlc.PENTAGON,
                            shape_color=interop_api_pb2.Odlc.GRAY,
                            alphanumeric='XYZ',
                            alphanumeric_color=interop_api_pb2.Odlc.ORANGE,
                            description='Incorrect description',
                            autonomous=False,
                            thumbnail_approved=True)
        self.submit3.save()
        self.real3 = Odlc(
            mission=self.mission,
            user=self.user,
            odlc_type=interop_api_pb2.Odlc.STANDARD,
            orientation=interop_api_pb2.Odlc.E,
            shape=interop_api_pb2.Odlc.SEMICIRCLE,
            shape_color=interop_api_pb2.Odlc.YELLOW,
            alphanumeric='LMN',
            # alphanumeric_color set below
            location=l3,
            description='Test odlc 3')
        self.real3.save()

        # Odlcs without approved image has no match value.
        self.submit4 = Odlc(mission=self.mission,
                            user=self.user,
                            odlc_type=interop_api_pb2.Odlc.EMERGENT,
                            location=l1,
                            description='Test odlc 4',
                            autonomous=False,
                            thumbnail_approved=False)
        self.submit4.save()
        self.real4 = Odlc(mission=self.mission,
                          user=self.user,
                          odlc_type=interop_api_pb2.Odlc.EMERGENT,
                          location=l1,
                          description='Test odlc 4')
        self.real4.save()

        # A odlc without location worth fewer points.
        self.submit5 = Odlc(mission=self.mission,
                            user=self.user,
                            odlc_type=interop_api_pb2.Odlc.STANDARD,
                            orientation=interop_api_pb2.Odlc.N,
                            shape=interop_api_pb2.Odlc.TRAPEZOID,
                            shape_color=interop_api_pb2.Odlc.PURPLE,
                            alphanumeric='PQR',
                            alphanumeric_color=interop_api_pb2.Odlc.BLUE,
                            description='Test odlc 5',
                            autonomous=False,
                            thumbnail_approved=True)
        self.submit5.save()
        self.real5 = Odlc(mission=self.mission,
                          user=self.user,
                          odlc_type=interop_api_pb2.Odlc.STANDARD,
                          location=l1,
                          orientation=interop_api_pb2.Odlc.N,
                          shape=interop_api_pb2.Odlc.TRAPEZOID,
                          shape_color=interop_api_pb2.Odlc.PURPLE,
                          alphanumeric='PQR',
                          alphanumeric_color=interop_api_pb2.Odlc.BLUE,
                          description='Test odlc 5')
        self.real5.save()

        # Emergent odlc with correct description.
        self.submit6 = Odlc(mission=self.mission,
                            user=self.user,
                            odlc_type=interop_api_pb2.Odlc.EMERGENT,
                            location=l1,
                            description='Submit test odlc 6',
                            description_approved=True,
                            autonomous=True,
                            thumbnail_approved=True)
        self.submit6.save()
        self.real6 = Odlc(mission=self.mission,
                          user=self.user,
                          odlc_type=interop_api_pb2.Odlc.EMERGENT,
                          location=l1,
                          description='Real odlc 1',
                          description_approved=True)
        self.real6.save()

        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=False)
        event.save()

        # submit2 updated after landing.
        self.submit2.alphanumeric = 'ABC'
        self.submit2.update_last_modified()
        self.submit2.save()
        self.submit2.update_last_modified()
        self.submit3.alphanumeric_color = interop_api_pb2.Odlc.YELLOW
        self.submit3.update_last_modified()
        self.submit3.save()
        # Unused but not unmatched odlc.
        self.submit7 = Odlc(mission=self.mission,
                            user=self.user,
                            odlc_type=interop_api_pb2.Odlc.STANDARD,
                            location=l4,
                            alphanumeric_color=interop_api_pb2.Odlc.BLACK,
                            description='Submit unused test odlc 1',
                            autonomous=False,
                            thumbnail_approved=True)
        self.submit7.save()

        self.submitted_odlcs = [
            self.submit7, self.submit6, self.submit5, self.submit4,
            self.submit3, self.submit2, self.submit1
        ]
        self.real_odlcs = [
            self.real1, self.real2, self.real3, self.real4, self.real5,
            self.real6
        ]

        self.flights = TakeoffOrLandingEvent.flights(self.mission, self.user)
Esempio n. 13
0
    def test_actionable_submission(self):
        """Tests actionable_submission correctly filters submissions."""
        # t1 created and updated before take off.
        t1 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        t1.save()
        t1.alphanumeric = 'A'
        t1.update_last_modified()
        t1.save()

        # t2 created before take off and updated in flight.
        t2 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        t2.save()

        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=True)
        event.save()

        t2.alphanumeric = 'A'
        t2.update_last_modified()
        t2.save()

        # t3 created and updated in flight.
        t3 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        t3.save()
        t3.alphanumeric = 'A'
        t3.update_last_modified()
        t3.save()

        # t4 created in flight and updated after landing.
        t4 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        t4.save()

        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=False)
        event.save()

        t4.alphanumeric = 'A'
        t4.update_last_modified()
        t4.save()

        # t5 created and updated after landing.
        t5 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        t5.save()
        t5.alphanumeric = 'A'
        t5.update_last_modified()
        t5.save()

        # t6 created and updated in second flight.
        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=True)
        event.save()
        t6 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        t6.save()
        t6.alphanumeric = 'A'
        t6.update_last_modified()
        t6.save()
        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=False)
        event.save()

        # t7 which is not actionable.
        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=True)
        event.save()
        t7 = Odlc(mission=self.mission,
                  user=self.user,
                  odlc_type=interop_api_pb2.Odlc.STANDARD)
        event = TakeoffOrLandingEvent(user=self.user,
                                      mission=self.mission,
                                      uas_in_air=False)
        event.save()

        flights = TakeoffOrLandingEvent.flights(self.mission, self.user)

        self.assertFalse(t1.actionable_submission(flights))
        self.assertFalse(t2.actionable_submission(flights))
        self.assertTrue(t3.actionable_submission(flights))
        self.assertFalse(t4.actionable_submission(flights))
        self.assertFalse(t5.actionable_submission(flights))
        self.assertFalse(t6.actionable_submission(flights))
        self.assertFalse(t7.actionable_submission(flights))
Esempio n. 14
0
    def kml(cls, user, logs, kml, kml_doc):
        """
        Appends kml nodes describing the given user's flight as described
        by the log array given.

        Args:
            user: A Django User to get username from
            logs: A list of UasTelemetry elements
            kml: A simpleKML Container to which the flight data will be added
            kml_doc: The simpleKML Document to which schemas will be added
        Returns:
            None
        """
        # KML Compliant Datetime Formatter
        kml_datetime_format = "%Y-%m-%dT%H:%M:%S.%fZ"
        icon = 'http://maps.google.com/mapfiles/kml/shapes/airports.png'
        threshold = 1  # Degrees

        kml_folder = kml.newfolder(name=user.username)

        flights = TakeoffOrLandingEvent.flights(user)
        if len(flights) == 0:
            return

        logs = filter(lambda log: cls._is_bad_position(log, threshold), logs)
        for i, flight in enumerate(flights):
            label = 'Flight {}'.format(i + 1)  # Flights are one-indexed
            kml_flight = kml_folder.newfolder(name=label)

            flight_logs = filter(lambda x: flight.within(x.timestamp), logs)
            if len(flight_logs) < 2:
                continue

            coords = []
            angles = []
            when = []
            for entry in flight_logs:
                pos = entry.uas_position.gps_position
                # Spatial Coordinates
                coord = (pos.longitude, pos.latitude,
                         units.feet_to_meters(entry.uas_position.altitude_msl))
                coords.append(coord)

                # Time Elements
                time = entry.timestamp.strftime(kml_datetime_format)
                when.append(time)

                # Degrees heading, tilt, and roll
                angle = (entry.uas_heading, 0.0, 0.0)
                angles.append(angle)

            # Create a new track in the folder
            trk = kml_flight.newgxtrack(name='Flight Path')
            trk.altitudemode = AltitudeMode.absolute

            # Append flight data
            trk.newwhen(when)
            trk.newgxcoord(coords)
            trk.newgxangle(angles)

            # Set styling
            trk.extrude = 1  # Extend path to ground
            trk.style.linestyle.width = 2
            trk.style.linestyle.color = Color.blue
            trk.iconstyle.icon.href = icon

            for obstacle in MovingObstacle.objects.all():
                obstacle.kml(path=flight_logs, kml=kml_flight, kml_doc=kml_doc)