Esempio n. 1
0
    def determine_trip_fixes(self, trace):

        leg = -1
        enl_first_fix = None
        enl_registered = False

        fixes = list()
        start_fixes = list()
        for fix_minus1, fix in double_iterator(trace):

            if not enl_registered and self.enl_value_exceeded(fix):
                if enl_first_fix is None:
                    enl_first_fix = fix_minus1

                enl_time = seconds_time_difference_fixes(enl_first_fix, fix)
                enl_registered = enl_registered or self.enl_time_exceeded(
                    enl_time)
            elif not enl_registered:
                enl_first_fix = None

            if self.start_opening is None:
                after_start_opening = True
            else:
                after_start_opening = add_seconds(
                    fix['time'], self.start_time_buffer) > self.start_opening

            if leg == -1 and after_start_opening:
                if self.started(fix_minus1, fix):
                    fixes.append(fix_minus1)
                    start_fixes.append(fix_minus1)
                    leg += 1
                    enl_first_fix = None
                    enl_registered = False
            elif leg == 0:
                if self.started(fix_minus1, fix):  # restart
                    fixes[0] = fix_minus1
                    start_fixes.append(fix_minus1)
                    enl_first_fix = None
                    enl_registered = False
                if self.finished_leg(leg, fix_minus1,
                                     fix) and not enl_registered:
                    fixes.append(fix)
                    leg += 1
            elif 0 < leg < self.no_legs:
                if self.finished_leg(leg, fix_minus1,
                                     fix) and not enl_registered:
                    fixes.append(fix)
                    leg += 1

        enl_fix = enl_first_fix if enl_registered else None

        outlanding_fix = None
        if len(fixes) is not len(self.waypoints):
            outlanding_fix = self.determine_outlanding_fix(
                trace, fixes, start_fixes, enl_fix)

        return fixes, outlanding_fix
Esempio n. 2
0
    def determine_refined_start(self, trace, fixes):
        start_i = trace.index(fixes[0])
        interpolated_fixes = interpolate_fixes(trace[start_i],
                                               trace[start_i + 1])

        for fix, next_fix in double_iterator(interpolated_fixes):
            if self.started(fix, next_fix):
                return fix['time']

        raise ValueError('Start should have been determined')
Esempio n. 3
0
    def _determine_trip_distances(self, fixes, outlanding_fix):

        distances = list()
        for leg, (fix1, fix2) in enumerate(double_iterator(fixes)):
            distance = self._calculate_distance_completed_leg(leg, fix1, fix2)
            distances.append(distance)

        if outlanding_fix is not None:
            outlanding_leg = len(fixes) - 1
            distance = self._calculate_distance_outlanding_leg(
                outlanding_leg, fixes[-1], outlanding_fix)
            distances.append(distance)

        return distances
Esempio n. 4
0
    def test_all_phases(self):

        all_phases = self.phases.all_phases(leg='all')

        # Check if end fixes are the same as the start fixes of next phase
        for phase, next_phase in double_iterator(all_phases):
            self.assertEqual(phase[1][-1], next_phase[1][0])

        # check same number of phases
        self.assertEqual(len(all_phases), len(self.pysoar_phase_start_times))

        # check if start times of phases are within 2 seconds
        for phase, pysoar_phase_start_time in zip(
                all_phases, self.pysoar_phase_start_times):
            time_diff = seconds_time_difference(phase.fixes[0]['time'],
                                                pysoar_phase_start_time)
            self.assertLessEqual(abs(time_diff), 2)
Esempio n. 5
0
 def _calculate_nominal_distances(self):
     distances = list()
     for start_waypoint, end_waypoint in double_iterator(self.waypoints):
         distance = calculate_distance(start_waypoint.fix, end_waypoint.fix)
         distances.append(distance)
     return distances
Esempio n. 6
0
    def _get_sector_fixes(self, trace):

        current_leg = -1  # not yet started
        sector_fixes = list()
        enl_first_fix = None
        enl_registered = False

        for fix_minus1, fix in double_iterator(trace):

            # check ENL when aircraft logs ENL and no ENL outlanding has taken place
            if not enl_registered and self.enl_value_exceeded(fix):
                if enl_first_fix is None:
                    enl_first_fix = fix

                enl_time = seconds_time_difference_fixes(enl_first_fix, fix)
                if self.enl_time_exceeded(enl_time):
                    enl_registered = True
                    if current_leg > 0:
                        break
            elif not enl_registered:
                enl_first_fix = None

            if current_leg == -1:  # before start
                if self.started(fix_minus1, fix):
                    self._add_aat_sector_fix(sector_fixes, 0,
                                             fix_minus1)  # at task start point
                    current_leg = 0
                    enl_registered = False
                    enl_first_fix = None
            elif current_leg == 0:  # first leg, re-start still possible
                if self.started(fix_minus1, fix):  # restart
                    sector_fixes[0] = [fix_minus1]  # at task start point
                    current_leg = 0
                    enl_registered = False
                    enl_first_fix = None
                elif self.waypoints[1].inside_sector(
                        fix_minus1):  # first sector
                    if enl_registered:
                        break  # break when ENL is used and not restarted
                    self._add_aat_sector_fix(sector_fixes, 1, fix_minus1)
                    current_leg += 1
            elif 0 < current_leg < self.no_legs - 1:  # at least second leg, no re-start possible
                if self.waypoints[current_leg].inside_sector(
                        fix_minus1):  # previous waypoint
                    self._add_aat_sector_fix(sector_fixes, current_leg,
                                             fix_minus1)
                elif self.waypoints[current_leg + 1].inside_sector(
                        fix_minus1):  # next waypoint
                    self._add_aat_sector_fix(sector_fixes, current_leg + 1,
                                             fix_minus1)
                    current_leg += 1
            elif current_leg == self.no_legs - 1:  # last leg
                if self.waypoints[current_leg].inside_sector(fix_minus1):
                    self._add_aat_sector_fix(sector_fixes, current_leg,
                                             fix_minus1)
                elif self.finished(fix_minus1, fix):
                    sector_fixes.append([fix])  # at task finish point
                    break

        # add last fix to sector if not already present
        last_fix = trace[-1]
        last_waypoint = self.waypoints[current_leg]
        if not last_waypoint.is_line and last_waypoint.inside_sector(
                last_fix) and last_fix is not sector_fixes[-1][-1]:
            sector_fixes[-1].append(last_fix)

        if enl_registered:
            return sector_fixes, enl_first_fix
        else:
            return sector_fixes, None
Esempio n. 7
0
 def test_double_iterator(self):
     lst = [1, 2, 3, 4]
     result = double_iterator(lst)
     self.assertListEqual(list(result), [(1, 2), (2, 3), (3, 4)])