Example #1
0
    def test_unlock_flight_achievements_simple(self):
        from skylines.model.achievement import unlock_flight_achievements
        igc = self.create_sample_igc_file('f1.igc')
        flight = self.create_sample_flight(igc)
        db.session.add(flight)
        db.session.flush()

        unlock_flight_achievements(flight)
        db.session.flush()

        # Make sure achievements are unlocked
        assert ([a.name for a in self.pilot.achievements] ==
                ['duration-3', 'duration-5'])

        # Make sure events are created. We expect 2 event: for both unlocked
        # achievements
        events = list(model.Event.query())
        assert len(events) == 2
        assert ([(e.type, e.actor_id, e.flight_id) for e in events] ==
                [(model.Event.Type.ACHIEVEMENT, self.pilot.id, flight.id),
                 (model.Event.Type.ACHIEVEMENT, self.pilot.id, flight.id)])

        assert events[0].achievement_id is not None

        # Both pilot and his follower should receive notifications for both
        # achievements
        assert model.Notification.count_unread(self.pilot) == 2
        assert model.Notification.count_unread(self.follower) == 2
Example #2
0
def analyse_flight(flight_id, full=2048, triangle=6144, sprint=512):
    logger.info("Analysing flight %d" % flight_id)

    flight = Flight.get(flight_id)
    success = analysis.analyse_flight(flight, full, triangle, sprint)

    if not success:
        logger.warn("Analysis of flight %d failed." % flight_id)
        return

    unlock_flight_achievements(flight)

    db.session.commit()
Example #3
0
    def test_unlock_flight_achievements_correct_order(self):
        from skylines.model.achievement import unlock_flight_achievements
        # Create two flights
        igc1 = self.create_sample_igc_file('f1.igc')
        flight1 = self.create_sample_flight(igc1)
        flight1.takeoff_time = datetime(2013, 7, 7, 13, 0)
        flight1.landing_time = datetime(2013, 7, 7, 18, 0)
        flight1.date_local = datetime(2013, 7, 7, 13, 0)
        db.session.add(flight1)

        # Second flight was made before flight1, and only lasted 4 hours (so, 5
        # hour achievement is not earned for it)
        igc2 = self.create_sample_igc_file('f2.igc')
        flight2 = self.create_sample_flight(igc2)
        flight2.takeoff_time = datetime(2013, 7, 6, 13, 0)
        flight2.landing_time = datetime(2013, 7, 6, 17, 0)
        flight2.date_local = datetime(2013, 7, 6, 13, 0)
        db.session.add(flight2)
        db.session.flush()

        # We first unlock achievements for flight1, and then for earlier
        # flight2
        unlock_flight_achievements(flight1)
        db.session.flush()
        unlock_flight_achievements(flight2)
        db.session.flush()

        # Expect 'duration-3' achievement to be reassociated with flight2
        assert ([a.name for a in self.pilot.achievements] ==
                ['duration-3', 'duration-5'])

        assert [a.name for a in flight1.achievements] == ['duration-5']
        assert [a.name for a in flight2.achievements] == ['duration-3']

        # Event for duration-3 achievement should be reassociated too
        event1 = model.Event.query(flight_id=flight1.id).one()
        assert event1 is not None
        assert event1.achievement == flight1.achievements[0]
        assert event1.achievement.time_achieved == datetime(2013, 7, 7, 18, 0)

        event2 = model.Event.query(flight_id=flight2.id).one()
        assert event2 is not None
        assert event2.achievement == flight2.achievements[0]
        assert event2.achievement.time_achieved == datetime(2013, 7, 6, 17, 0)