Beispiel #1
0
class TestAATTripOutlandingInside(unittest.TestCase):
    """
    Test AAT Trip in which an outlanding takes place inside the last rounded sector.
    """

    # https://www.soaringspot.com/en_gb/cae-nls-nederlandse-kampioenschappen-zweefvliegen-2012/results/club/task-10-on-2012-05-26/daily
    # competitor 7, YES
    cwd = os.path.dirname(__file__)
    igc_path = os.path.join(cwd, '..', 'igc_files',
                            'aat_outlanding_inside_sector.igc')
    aat = get_task(igc_path)
    trace = get_trace(igc_path)
    trip = Trip(aat, trace)

    def test_trip_fixes(self):

        # assert correct number of trip fixes
        self.assertEqual(len(self.trip.fixes), 4)

        # assert if opensoar finds same fixes as seeyou, based on time
        fix_times = [
            # tuple with (opensoar time, SeeYou time)
            (self.trip.refined_start_time, datetime.time(12, 24, 14)),
            (self.trip.fixes[1]['time'], datetime.time(12, 57, 53)),
            (self.trip.fixes[2]['time'], datetime.time(13, 42, 31)),
            (self.trip.fixes[3]['time'], datetime.time(14, 4, 5)),
            (self.trip.outlanding_fix['time'], datetime.time(14, 5, 49)),
        ]

        for opensoar_time, seeyou_time in fix_times:
            self.assertEqual(seeyou_time, opensoar_time)

    def test_total_distance(self):
        total_distance = sum(self.trip.distances)
        self.assertAlmostEqual(total_distance / 1e3, 86.07, places=2)
Beispiel #2
0
class TestTrip(unittest.TestCase):
    """
    This testcase covers a completed race task. number 2, comp id HS:
    https://www.soaringspot.com/en/sallandse-tweedaagse-2014/results/club/task-1-on-2014-06-21/daily
    """

    cwd = os.path.dirname(__file__)
    igc_path = os.path.join(cwd, '..', 'igc_files', 'race_task_completed.igc')
    race_task = get_task(igc_path)
    trace = get_trace(igc_path)
    trip = Trip(race_task, trace)

    def test_number_of_fixes(self):
        self.assertEqual(len(self.trip.fixes), 5)

    def test_distances(self):
        self.assertListEqual(self.trip.distances, self.race_task.distances)

    def test_outlanded(self):
        self.assertFalse(self.trip.outlanded())

    def test_start_time(self):
        start_fix = self.trip.fixes[0]
        refined_start_time = self.trip.refined_start_time
        self.assertEqual(start_fix['time'], datetime.time(12, 12, 54))
        self.assertEqual(refined_start_time, datetime.time(12, 12, 55))

    def test_finish_time(self):
        finish_fix = self.trip.fixes[-1]
        self.assertEqual(finish_fix['time'], datetime.time(13, 21, 58))
Beispiel #3
0
class TestOutlandingTrip(unittest.TestCase):
    """
    This testcase covers an outlanding on a race task. number 7, comp id SU:
    https://www.soaringspot.com/en/sallandse-tweedaagse-2014/results/club/task-1-on-2014-06-21/daily
    """

    cwd = os.path.dirname(__file__)
    igc_path = os.path.join(cwd, '..', 'igc_files', 'outlanding_race_task.igc')
    race_task = get_task(igc_path)
    trace = get_trace(igc_path)
    trip = Trip(race_task, trace)

    def test_total_distance(self):
        self.assertAlmostEqual(sum(self.trip.distances) / 1000,
                               89.99,
                               places=2)

    def test_completed_legs(self):
        self.assertEqual(self.trip.completed_legs(), 2)

    def test_fix_after_leg_on_outlanding_leg(self):
        """A fix happening on the outlanding leg can never be after the leg, because that leg is never finished."""
        fix = {'time': datetime.time(14, 44, 45)}
        fix_after_leg = self.trip.fix_after_leg(fix, leg=2)
        self.assertFalse(fix_after_leg)
Beispiel #4
0
    def analyse(self, task, classification_method: str):

        if self.trace is None or len(self.trace) == 0:
            raise ValueError('No trace present')

        self._trip = Trip(task, self.trace)

        # competitor should have at least started
        if len(self._trip.fixes) >= 1:
            self._phases = FlightPhases(classification_method, self.trace, self._trip)
Beispiel #5
0
class TestEnlOutlandingTrip(unittest.TestCase):
    """
    This testcase covers an ENL outlanding on a race task. number 10, comp id 2C:
    https://www.soaringspot.com/en/nk-zweefvliegen-2017/results/18-meter-klasse/task-8-on-2017-05-31/daily
    """

    cwd = os.path.dirname(__file__)
    igc_path = os.path.join(cwd, '..', 'igc_files',
                            'outlanding_race_task_enl.igc')
    race_task = get_task(igc_path)
    trace = get_trace(igc_path)
    trip = Trip(race_task, trace)

    def test_total_distance(self):
        self.assertAlmostEqual(sum(self.trip.distances) / 1000,
                               378.13,
                               places=2)

    def test_completed_legs(self):
        self.assertEqual(self.trip.completed_legs(), 4)
Beispiel #6
0
class TestAATTrip(unittest.TestCase):

    # https://www.soaringspot.com/en_gb/cae-nls-nederlandse-kampioenschappen-zweefvliegen-2012/results/club/task-10-on-2012-05-26/daily
    # competitor 3, SP

    cwd = os.path.dirname(__file__)
    igc_path = os.path.join(cwd, '..', 'igc_files', 'aat_completed.igc')
    aat = get_task(igc_path)
    trace = get_trace(igc_path)
    trip = Trip(aat, trace)

    def test_total_distance(self):
        total_distance = sum(self.trip.distances)
        self.assertAlmostEqual(total_distance / 1e3, 199.42, places=2)

    def test_start_time(self):
        start_time = self.trip.fixes[0]['time']
        expected_start_time = datetime.time(12, 22, 8)
        self.assertEqual(expected_start_time, start_time)

    def test_finish_time(self):
        finish_time = self.trip.finish_time
        expected_finish_time = datetime.time(15, 52, 8)
        self.assertEqual(expected_finish_time, finish_time)
Beispiel #7
0
class TestFlightPhases(unittest.TestCase):

    pysoar_phase_start_times = [
        datetime.time(12, 12, 52),
        datetime.time(12, 20, 22),
        datetime.time(12, 24, 14),
        datetime.time(12, 29, 22),
        datetime.time(12, 33, 6),
        datetime.time(12, 34, 50),
        datetime.time(12, 37, 42),
        datetime.time(12, 47, 14),
        datetime.time(12, 52, 42),
        datetime.time(13, 1, 0),
        datetime.time(13, 4, 52),
    ]

    cwd = os.path.dirname(__file__)
    igc_path = os.path.join(cwd, '..', 'igc_files', 'race_task_completed.igc')

    trace = get_trace(igc_path)
    race_task = get_task(igc_path)
    trip = Trip(race_task, trace)
    phases = FlightPhases('pysoar', trace, trip)

    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)

    def test_thermals(self):

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

        # check if indeed only thermals
        for thermal in thermals:
            self.assertFalse(thermal.is_cruise)

        # check if correct phases are classified as thermals
        for thermal, pysoar_start_time in zip(
                thermals, self.pysoar_phase_start_times[1::2]):
            time_diff = seconds_time_difference(thermal.fixes[0]['time'],
                                                pysoar_start_time)
            self.assertLessEqual(abs(time_diff), 2)

    def test_cruises(self):

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

        # check if indeed only cruises
        for cruise in cruises:
            self.assertTrue(cruise.is_cruise)

        # check if correct phases are classified as cruises
        for cruise, pysoar_start_time in zip(
                cruises, self.pysoar_phase_start_times[0::2]):
            time_diff = seconds_time_difference(cruise.fixes[0]['time'],
                                                pysoar_start_time)
            self.assertLessEqual(abs(time_diff), 2)

    def test_thermals_on_leg(self):

        thermals_leg2 = self.phases.thermals(leg=1)

        # check indeed subset of all thermals
        self.assertTrue(len(thermals_leg2) < len(self.phases.thermals()))

        # check all thermals
        for thermal in thermals_leg2:
            self.assertFalse(thermal.is_cruise)

        leg_start_time = self.trip.fixes[1]['time']
        leg_end_time = self.trip.fixes[2]['time']

        # check starttime of first thermal
        start_time = thermals_leg2[0].fixes[0]['time']
        self.assertEqual(seconds_time_difference(start_time, leg_start_time),
                         0)

        # check endtime of last thermal
        end_time = thermals_leg2[-1].fixes[-1]['time']
        self.assertEqual(seconds_time_difference(end_time, leg_end_time), 0)

    def test_cruises_on_leg(self):

        cruises_leg2 = self.phases.cruises(leg=1)

        # check indeed subset of all thermals
        self.assertTrue(len(cruises_leg2) < len(self.phases.cruises()))

        # check all cruises
        for cruise in cruises_leg2:
            self.assertTrue(cruise.is_cruise)

    def test_phases_on_leg_spanning_complete_leg(self):
        """This test covers the case when the phase starts before the start of the leg and ends after
        the end of the leg."""

        trace = [
            {
                'time': datetime.time(11, 33, 26),
                'lat': 52.468183333333336,
                'lon': 6.3402,
                'validity': 'A',
                'pressure_alt': -37,
                'gps_alt': 47,
                'FXA': 2,
                'SIU': 1
            },
            {
                'time': datetime.time(11, 33, 34),
                'lat': 52.468183333333336,
                'lon': 6.3402,
                'validity': 'A',
                'pressure_alt': -37,
                'gps_alt': 47,
                'FXA': 2,
                'SIU': 1
            },
            {
                'time': datetime.time(11, 33, 42),
                'lat': 52.468183333333336,
                'lon': 6.3402,
                'validity': 'A',
                'pressure_alt': -37,
                'gps_alt': 47,
                'FXA': 2,
                'SIU': 1
            },
            {
                'time': datetime.time(11, 33, 50),
                'lat': 52.468183333333336,
                'lon': 6.3402,
                'validity': 'A',
                'pressure_alt': -37,
                'gps_alt': 48,
                'FXA': 1,
                'SIU': 1
            },
            {
                'time': datetime.time(11, 33, 58),
                'lat': 52.468183333333336,
                'lon': 6.340216666666667,
                'validity': 'A',
                'pressure_alt': -37,
                'gps_alt': 48,
                'FXA': 1,
                'SIU': 1
            },
            {
                'time': datetime.time(11, 34, 6),
                'lat': 52.46816666666667,
                'lon': 6.339666666666667,
                'validity': 'A',
                'pressure_alt': -38,
                'gps_alt': 49,
                'FXA': 1,
                'SIU': 1
            },
        ]

        trip = deepcopy(self.trip)
        trip.fixes = [trace[1], trace[4]]

        phases = FlightPhases('pysoar', trace, trip)

        # there should only be one phase: starting at first fix and ending at last fix of trace
        # these are conditions to a correct test setup, therefore no actual tests
        assert len(phases._phases) == 1
        assert phases._phases[0].fixes[0]['time'] == trace[0]['time']
        assert phases._phases[0].fixes[-1]['time'] == trace[-1]['time']

        all_phases_leg0 = phases.all_phases(leg=0)

        # check 1 phase found
        self.assertEqual(len(all_phases_leg0), 1)

        # check if phase correctly starts and ends at the trip fixes and not the trace fixes
        first_phase_fix = all_phases_leg0[0].fixes[0]
        last_phase_fix = all_phases_leg0[0].fixes[-1]
        self.assertEqual(first_phase_fix['time'], trip.fixes[0]['time'])
        self.assertEqual(last_phase_fix['time'], trip.fixes[-1]['time'])