Example #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)
Example #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))
Example #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)
Example #4
0
class TestRaceTask(unittest.TestCase):

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

    def test_number_of_legs(self):
        self.assertEqual(self.race_task.no_legs, 4)

    def test_distances(self):
        distances = self.race_task.distances
        expected_distances = [25.15, 27.20, 43.65, 5.23]

        self.assertEqual(len(distances), len(expected_distances))

        for distance, expected_distance in zip(distances, expected_distances):
            self.assertAlmostEqual(distance/1000, expected_distance, places=2)

    def test_total_distance(self):
        self.assertAlmostEqual(self.race_task.total_distance / 1000, 101.24, places=2)

    def test_equal_tasks(self):
        race_task2 = get_task(self.igc_path)
        self.assertEqual(self.race_task, race_task2)

    def test_not_equal_tasks(self):
        waypoints = self.race_task.waypoints

        # test_unequal number_waypoints
        waypoints2 = deepcopy(waypoints)
        del waypoints2[2]
        race_task2 = RaceTask(waypoints2)
        self.assertNotEqual(self.race_task, race_task2)

        # test different waypoint
        waypoints3 = deepcopy(waypoints)
        waypoints3[2].r_max = 1000
        race_task2 = RaceTask(waypoints3)
        self.assertNotEqual(self.race_task, race_task2)

        # test different start_time
        race_task2 = RaceTask(waypoints, start_opening=datetime.time(0, 0, 0))
        self.assertNotEqual(race_task2, self.race_task)

        # test different start buffer
        race_task2 = RaceTask(waypoints, start_time_buffer=5)
        self.assertNotEqual(self.race_task, race_task2)
Example #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)
Example #6
0
class TestAAT(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)

    def test_number_of_legs(self):
        self.assertEqual(self.aat.no_legs, 5)

    def test_nominal_distances(self):
        nominal_distances = self.aat._nominal_distances
        expected_distances = [45.20, 43.25, 73.26, 88.28, 9.62]

        # note: the final distance is different from the one in soaringspot.
        # soaringspot says the last distance should be 9.12km. they wrongfully subtract 0.5km from the finish line

        self.assertEqual(len(nominal_distances), len(expected_distances))

        for distance, expected_distance in zip(nominal_distances, expected_distances):
            self.assertAlmostEqual(distance / 1e3, expected_distance, places=2)

    def test_equal_aat(self):
        aat2 = get_task(self.igc_path)
        self.assertEqual(self.aat, aat2)

    def test_not_equal_aat(self):

        waypoints = self.aat.waypoints

        # test_unequal number_waypoints
        waypoints2 = deepcopy(waypoints)
        del waypoints2[2]
        aat2 = AAT(waypoints2, self.aat._t_min)
        self.assertNotEqual(self.aat, aat2)

        # test unequal t_min
        aat2 = AAT(waypoints, datetime.time(1, 0, 0))
        self.assertNotEqual(self.aat, aat2)
Example #7
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)
Example #8
0
 def test_equal_aat(self):
     aat2 = get_task(self.igc_path)
     self.assertEqual(self.aat, aat2)
Example #9
0
 def test_equal_tasks(self):
     race_task2 = get_task(self.igc_path)
     self.assertEqual(self.race_task, race_task2)
Example #10
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'])
Example #11
0
class TestRaceTask(unittest.TestCase):

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

    def test_number_of_legs(self):
        self.assertEqual(self.race_task.no_legs, 4)

    def test_distances(self):
        distances = self.race_task.distances
        expected_distances = [25.15, 27.20, 43.65, 5.23]

        self.assertEqual(len(distances), len(expected_distances))

        for distance, expected_distance in zip(distances, expected_distances):
            self.assertAlmostEqual(distance / 1000,
                                   expected_distance,
                                   places=2)

    def test_total_distance(self):
        self.assertAlmostEqual(self.race_task.total_distance / 1000,
                               101.24,
                               places=2)

    def test_equal_tasks(self):
        race_task2 = get_task(self.igc_path)
        self.assertEqual(self.race_task, race_task2)

    def test_not_equal_tasks(self):
        waypoints = self.race_task.waypoints

        # test_unequal number_waypoints
        waypoints2 = deepcopy(waypoints)
        del waypoints2[2]
        race_task2 = RaceTask(waypoints2)
        self.assertNotEqual(self.race_task, race_task2)

        # test different waypoint
        waypoints3 = deepcopy(waypoints)
        waypoints3[2].r_max = 1000
        race_task2 = RaceTask(waypoints3)
        self.assertNotEqual(self.race_task, race_task2)

        # test different start_time
        race_task2 = RaceTask(waypoints, start_opening=datetime.time(0, 0, 0))
        self.assertNotEqual(race_task2, self.race_task)

        # test different start buffer
        race_task2 = RaceTask(waypoints, start_time_buffer=5)
        self.assertNotEqual(self.race_task, race_task2)

    def test_race_reduced_legs(self):
        """
        Race task with reduced legs, should produce correct distance

        https://www.soaringspot.com/en_gb/pribina-cup-2018-nitra-2018/results/15-meter/task-1-on-2018-04-02/daily
        """

        lcu_lines = [
            'LCU::C020418195435301299000202',
            'LCU::C0000000N00000000E',
            'LCU::C4819183N01759550E158LEHOTA',
            'LCU::C4907167N01819400E235PUCHOV',
            'LCU::C4748117N01842983E271STUROVO',
            'LCU::C4816767N01807967E001NITRA',
            'LCU::C0000000N00000000E',
        ]

        lseeyou_lines = [
            'LSEEYOU OZ=-1,Style=2,SpeedStyle=0,R1=5000m,A1=180,Line=1',
            'LSEEYOU OZ=0,Style=1,SpeedStyle=3,R1=500m,A1=180,Reduce=1',
            'LSEEYOU OZ=1,Style=1,SpeedStyle=3,R1=500m,A1=180,Reduce=1',
            'LSEEYOU OZ=2,Style=3,SpeedStyle=2,R1=3000m,A1=180,Reduce=1',
        ]

        waypoints = get_waypoints(lcu_lines, lseeyou_lines)
        race_task = RaceTask(waypoints)

        self.assertAlmostEqual(race_task.total_distance / 1000,
                               305.21,
                               places=2)

    def test_race_moved_leg(self):
        """
        Race task with moved waypoint, should not crash. somehow distances are not completely equal.

        https://www.soaringspot.com/en_gb/35th-world-gliding-championships-hosin-2018/results/18-meter/task-1-on-2018-07-29/daily
        """

        lcu_lines = [
            'LCU::C290718193533301299000203',
            'LCU::C0000000N00000000E',
            'LCU::C4908600N01432867E011SP07RADONICE',
            'LCU::C4936150N01352917E477ROZMITAL',
            'LCU::C4940950N01240067E442PRIMDA',
            'LCU::C4915633N01308733E385NYRSKO',
            'LCU::C4902383N01429650E001SP01HOSIN',
            'LCU::C0000000N00000000E',
        ]

        lseeyou_lines = [
            'LSEEYOU OZ=-1,Style=2,SpeedStyle=0,R1=5000m,A1=180,Line=1',
            'LSEEYOU OZ=0,Style=1,SpeedStyle=3,R1=500m,A1=180',
            'LSEEYOU OZ=1,Style=1,SpeedStyle=3,R1=500m,A1=180',
            'LSEEYOU OZ=2,Style=1,SpeedStyle=3,R1=500m,A1=180',
            'LSEEYOU OZ=3,Style=3,SpeedStyle=2,R1=5000m,A1=180,Move=1',
        ]

        waypoints = get_waypoints(lcu_lines, lseeyou_lines)

        try:
            race_task = RaceTask(waypoints)
        except Exception:
            self.fail()