예제 #1
0
 def test_complex_model_types_available(self):
     with app.app_context():
         model_types_names = ['CombProb', 'SearchSeg']
         for mt in model_types_names:
             model_type = ModelType.query.filter_by(name=mt).first()
             self.assertIsNotNone(model_type.id)
             self.assertTrue(model_type.complex)
예제 #2
0
 def test_model_weight_for_complex_must_be_none(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         comb_model = add_complex_model_comb(db.session, analysis.id)
         with self.assertRaises(AssertionError):
             comb_model.create_weights(weight=3)
예제 #3
0
 def test_analysis_with_profiles(self):
     with app.app_context():
         action = Action(name='Example', lost_time=datetime.datetime.now())
         db.session.add(action)
         db.session.flush()
         analysis = Analysis(name='Some basic analysis',
                             action_id=action.id,
                             ipp_longitude=80,
                             ipp_latitude=70,
                             rp_latitude=30,
                             rp_longitude=80)
         db.session.add(analysis)
         db.session.flush()
         person_type_tourist = PersonType.query.filter_by(
             name='tourist').first()
         person_type_climber = PersonType.query.filter_by(
             name='climber').first()
         self.assertIsNotNone(person_type_tourist.id)
         self.assertIsNotNone(person_type_climber.id)
         tourist = Profile(analysis_id=analysis.id,
                           person_type_id=person_type_tourist.id,
                           weight=random.randint(1, 10))
         climber = Profile(analysis_id=analysis.id,
                           person_type_id=person_type_climber.id,
                           weight=random.randint(1, 10))
         db.session.add(tourist)
         db.session.add(climber)
         db.session.flush()
         self.assertIsNotNone(tourist.id)
         self.assertIsNotNone(climber.id)
         self.assertEquals(analysis.profiles.count(), 2)
예제 #4
0
    def test_starting_analysis_with_complex_models(self):
        result_ids = {
            "HorDistIPP": "3897890975230495710",
            "ElevChgIPP": "4709831647259734695",
            "HorChgIPP": "4375692374598762347",
            "TrackOffset": "3476273469987234659",
            "DispAngle": "3892345235423495710",
            "FindLocation": "4709831647263434695",
            "Mobility": "4375692374598762346",
        }
        expected_content = {
            "CombProb": "3897890975230495710",
            "SearchSeg": "3476273469987234659",
        }

        httpretty.register_uri(httpretty.POST,
                               server_path('complex_analysis'),
                               body=json.dumps(expected_content),
                               content_type="application/json")

        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_complex_models_analysis(db.session, action.id)
            for model in analysis.simple_models():
                model.update_result(result_ids[model.name])
            draft_simple_models = analysis.draft_models().join(
                Model.model_type).filter(ModelType.complex == False)
            assert draft_simple_models.count() == 0
            analysis.start_computation()
            for model in analysis.complex_models():
                self.assertEquals(model.result_id,
                                  expected_content[model.name])
예제 #5
0
    def test_cs_profiles_representation(self):
        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_analysis_with_coordinates(db.session, action.id)

            person_type_tourist = PersonType.query.filter_by(
                name='tourist').first()
            person_type_climber = PersonType.query.filter_by(
                name='climber').first()

            weight_tourist, weight_climber = 3, 7

            tourist = Profile(analysis_id=analysis.id,
                              person_type_id=person_type_tourist.id,
                              weight=weight_tourist)
            climber = Profile(analysis_id=analysis.id,
                              person_type_id=person_type_climber.id,
                              weight=weight_climber)
            db.session.add(tourist)
            db.session.add(climber)
            db.session.flush()

            expected = {'tourist': weight_tourist, 'climber': weight_climber}

            self.assertEquals(len(analysis.cs_profiles()), 2)
            self.assertEquals(analysis.cs_profiles(), expected)
예제 #6
0
 def setUp(self):
     self.app = app.test_client()
     with app.app_context():
         db.session.close()
         db.drop_all()
         db.create_all()
         setup_db(db.session)
예제 #7
0
    def test_updating_layers(self):
        expected_content = {
            "status": "finished",
            "layer_ids": ["432542345", "785642345", "434567678", "969824586"]
        }

        layers_count = 4
        result_id = "3897890975230495710"
        path = server_path('analysis/%s' % result_id)
        httpretty.register_uri(httpretty.GET,
                               path,
                               body=json.dumps(expected_content),
                               content_type="application/json")

        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_analysis_with_coordinates(db.session, action.id)
            model = add_simple_model(db.session, analysis.id)

            # mocking starting computation
            model.update_result(result_id)

            analysis.update_result()

            finished_id = ModelStatus.by_name(ModelStatus.FINISHED).id
            assert model.status_id == finished_id
            assert analysis.analysis_status_id == finished_id
            assert len(model.layer_urls()) == layers_count
            layer_paths = [
                layer_path(layers_id)
                for layers_id in expected_content['layer_ids']
            ]
            for l in model.layer_urls():
                assert l in layer_paths
예제 #8
0
 def test_adding_analysis(self):
     with app.app_context():
         action = Action(name='Example', lost_time=datetime.datetime.now())
         db.session.add(action)
         db.session.flush()
         analysis = Analysis(name='Basic', action_id=action.id)
         db.session.add(analysis)
         db.session.flush()
         self.assertIsNotNone(analysis.id)
예제 #9
0
 def test_duplicating_analysis_deep(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_simple_models_analysis(db.session, action.id)
         duplicated = analysis.duplicate({'name': 'Another'})
         self.assertNotEqual(analysis.id, duplicated.id)
         self.assertEqual(analysis.lost_time, duplicated.lost_time)
         self.assertEqual(analysis.models.count(),
                          duplicated.models.count())
예제 #10
0
 def test_duplicating_analysis_shallow(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         duplicated = analysis.duplicate({'ipp_latitude': 10})
         self.assertNotEqual(analysis.id, duplicated.id)
         self.assertEqual(analysis.name, duplicated.name)
         self.assertEqual(analysis.lost_time, duplicated.lost_time)
         self.assertNotEqual(duplicated.ipp_latitude, analysis.ipp_latitude)
         self.assertEqual(duplicated.ipp_latitude, 10)
예제 #11
0
 def test_analysis_updating_unfinished(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_simple_models_analysis(db.session, action.id)
         processing_id = ModelStatus.by_name(ModelStatus.PROCESSING).id
         for model in analysis.models:
             model.status_id = processing_id
         with self.assertRaises(ValueError):
             analysis_data = {'ipp_latitude': 1123123}
             analysis.update(analysis_data, None, None)
예제 #12
0
 def test_simple_model_types_available(self):
     with app.app_context():
         model_types_names = [
             'HorDistIPP', 'ElevChgIPP', 'HorChgIPP', 'DispAngle',
             'TrackOffset', 'FindLocation', 'Mobility'
         ]
         for mt in model_types_names:
             model_type = ModelType.query.filter_by(name=mt).first()
             self.assertIsNotNone(model_type.id)
             self.assertFalse(model_type.complex)
예제 #13
0
 def test_model_default_status(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         model_type = ModelType.query.filter_by(complex=False).first()
         model = Model(analysis_id=analysis.id, model_type_id=model_type.id)
         db.session.add(model)
         db.session.flush()
         model_status = ModelStatus.query.filter_by(name='draft').one()
         self.assertEquals(model.status_id, model_status.id)
예제 #14
0
 def setUp(self):
     self.app = app.test_client()
     with app.app_context():
         db.session.close()
         db.drop_all()
         db.create_all()
         setup_db(db.session)
         app.config['MONTRACKER_SERVER_ADDR'] = 'http://127.0.0.1:10000'
         app.config['MONTRACKER_SERVER_API_VERSION'] = 'v1'
         app.config['ARCGIS_PATH_PREFIX'] = 'http://127.0.0.1:11000'
         app.config['ARCGIS_PATH_SUFFIX'] = '/maps'
예제 #15
0
 def test_model_weight_for_complex_types(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         model_type = ModelType.query.filter_by(complex=True).first()
         model = Model(analysis_id=analysis.id, model_type_id=model_type.id)
         db.session.add(model)
         db.session.flush()
         self.assertEquals(analysis.models.count(), 1)
         self.assertIsNone(model.weight)
         with self.assertRaises(AssertionError):
             model.create_weights()
예제 #16
0
 def test_model_weight_must_be_associated_with_non_complex_types(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         model_type = ModelType.query.filter_by(complex=False).first()
         model = Model(analysis_id=analysis.id, model_type_id=model_type.id)
         db.session.add(model)
         db.session.flush()
         self.assertEquals(analysis.models.count(), 1)
         self.assertEquals(model.model_weights.count(), 0)
         with self.assertRaises(AssertionError):
             getattr(model, 'weight')
예제 #17
0
 def test_action_status_id_no_analyses(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analyses_count = Analysis.query.count()
         # only one analysis, no models
         self.assertEquals(analyses_count, 0)
         draft_id = ModelStatus.draft_id()
         # and the one has status draft on class level
         draft_count = Action.query.filter(
             Action.action_status_id == draft_id).count()
         self.assertEquals(draft_count, 1)
         # as well as on instance level
         self.assertEquals(action.action_status_id, draft_id)
예제 #18
0
 def test_analysis_inheriting_action_coordinates(self):
     with app.app_context():
         action = Action(name='Example', lost_time=datetime.datetime.now())
         db.session.add(action)
         db.session.flush()
         analysis = Analysis(name='Basic', action_id=action.id)
         db.session.add(analysis)
         db.session.flush()
         self.assertIsNone(analysis.ipp_latitude)
         self.assertIsNotNone(analysis.lost_time)
         self.assertEquals(analysis.lost_time, action.lost_time)
         example_ipp_latitude = 50
         action.ipp_latitude = example_ipp_latitude
         self.assertEquals(analysis.ipp_latitude, example_ipp_latitude)
예제 #19
0
 def test_analysis_status_id_finished(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_simple_models_analysis(db.session, action.id)
         finished_id = ModelStatus.by_name(ModelStatus.FINISHED).id
         for model in analysis.models:
             model.status_id = finished_id
         # only one analysis, all finished
         analyses_count = Analysis.query.count()
         self.assertEquals(analyses_count, 1)
         # and the one has status finished on class level
         analyses_status_count = Analysis.query.filter(
             Analysis.analysis_status_id == finished_id).count()
         self.assertEquals(analyses_status_count, 1)
         # as well as on instance level
         self.assertEquals(analysis.analysis_status_id, finished_id)
예제 #20
0
    def test_analysis_status_id_draft(self):
        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_simple_models_analysis(db.session, action.id)
            analyses_count = Analysis.query.count()
            draft_id = ModelStatus.draft_id()

            for model in analysis.models:
                model.status_id = draft_id
            # only one analysis, no models
            self.assertEquals(analyses_count, 1)
            # and the one has status draft on class level
            draft_count = Analysis.query.filter(
                Analysis.analysis_status_id == draft_id).count()
            self.assertEquals(draft_count, 1)
            # as well as on instance level
            self.assertEquals(analysis.analysis_status_id, draft_id)
예제 #21
0
    def test_updating_state(self):
        expected_content = {
            "status": "converting",
        }
        result_ids = {
            "HorDistIPP": "3897890975230495710",
            "ElevChgIPP": "4709831647259734695",
            "HorChgIPP": "4375692374598762347",
            "TrackOffset": "3476273469987234659",
            "DispAngle": "3892345235423495710",
            "FindLocation": "4709831647263434695",
            "Mobility": "4375692374598762346",
            "CombProb": "3897890975230495710",
            "SearchSeg": "3476273469987234659",
        }

        for id in result_ids.values():
            path = server_path('analysis/%s' % id)
            httpretty.register_uri(httpretty.GET,
                                   path,
                                   body=json.dumps(expected_content),
                                   content_type="application/json")

        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_complex_models_analysis(db.session, action.id)

            draft_id = ModelStatus.draft_id()
            for model in analysis.models:
                assert model.model_status.id == draft_id
            assert analysis.analysis_status_id == draft_id

            for model in analysis.models:
                model.update_result(result_ids[model.name])

            waiting_status_id = ModelStatus.by_name(ModelStatus.WAITING).id
            for model in analysis.models:
                assert model.status_id == waiting_status_id
            assert analysis.analysis_status_id == waiting_status_id

            analysis.update_result()

            processing_id = ModelStatus.by_name(ModelStatus.PROCESSING).id
            for model in analysis.models:
                assert model.status_id == processing_id
            assert analysis.analysis_status_id == processing_id
예제 #22
0
 def test_model_weight_for_non_complex_types(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         model_type = ModelType.query.filter_by(complex=False).first()
         model = Model(analysis_id=analysis.id, model_type_id=model_type.id)
         db.session.add(model)
         db.session.flush()
         model.create_weights()
         db.session.flush()
         self.assertEquals(analysis.models.count(), 1)
         self.assertEquals(model.model_weights.count(), 1)
         self.assertEquals(model.weight, app.config['DEFAULT_WEIGHT'])
         new_weight = 5
         model.update_weights(new_weight)
         self.assertEquals(model.model_weights.count(), 1)
         self.assertEquals(model.weight, new_weight)
예제 #23
0
 def test_model_weight_for_multiple_complex_analyses(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         model = add_simple_model(db.session, analysis.id)
         comb_model = add_complex_model_comb(db.session, analysis.id)
         seg_model = add_complex_model_seg(db.session, analysis.id)
         model.create_weights(parent_model_id=comb_model.id)
         model.create_weights(parent_model_id=seg_model.id)
         db.session.flush()
         self.assertEquals(analysis.models.count(), 3)
         self.assertEquals(model.model_weights.count(), 2)
         self.assertEquals(model.child_model_weights.count(), 0)
         self.assertEquals(comb_model.model_weights.count(), 0)
         self.assertEquals(seg_model.model_weights.count(), 0)
         self.assertEquals(comb_model.child_model_weights.count(), 1)
         self.assertEquals(seg_model.child_model_weights.count(), 1)
예제 #24
0
    def test_action_status_id_error(self):
        with app.app_context():
            action = add_simple_action(db.session)
            waiting_id = ModelStatus.by_name(ModelStatus.WAITING).id
            error_id = ModelStatus.by_name(ModelStatus.ERROR).id

            analysis = add_simple_models_analysis(db.session, action.id)
            for model in analysis.models:
                model.status_id = waiting_id

            analysis = add_simple_models_analysis(db.session, action.id)
            for model in analysis.models:
                model.status_id = error_id

            action_status_count = Action.query.filter(
                Action.action_status_id == error_id).count()
            self.assertEquals(action_status_count, 1)
            self.assertEquals(action.action_status_id, error_id)
예제 #25
0
    def test_action_status_id_processing(self):
        with app.app_context():
            action = add_simple_action(db.session)
            processing_id = ModelStatus.by_name(ModelStatus.PROCESSING).id
            finished_id = ModelStatus.by_name(ModelStatus.FINISHED).id

            analysis = add_simple_models_analysis(db.session, action.id)
            for model in analysis.models:
                model.status_id = finished_id

            analysis = add_simple_models_analysis(db.session, action.id)
            for model in analysis.models:
                model.status_id = processing_id

            action_status_count = Action.query.filter(
                Action.action_status_id == processing_id).count()
            self.assertEquals(action_status_count, 1)
            self.assertEquals(action.action_status_id, processing_id)
예제 #26
0
 def test_analysis_status_id_waiting(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_simple_models_analysis(db.session, action.id)
         processing_id = ModelStatus.by_name(ModelStatus.PROCESSING).id
         waiting_id = ModelStatus.by_name(ModelStatus.WAITING).id
         for model in analysis.models:
             model.status_id = processing_id
         analysis.models.first().status_id = waiting_id
         # only one analysis, all processing but one waiting
         analyses_count = Analysis.query.count()
         self.assertEquals(analyses_count, 1)
         # and the one has status waiting on class level
         analyses_status_count = Analysis.query.filter(
             Analysis.analysis_status_id == waiting_id).count()
         self.assertEquals(analyses_status_count, 1)
         # as well as on instance level
         self.assertEquals(analysis.analysis_status_id, waiting_id)
예제 #27
0
 def test_adding_analysis_with_basic_model(self):
     with app.app_context():
         action = Action(name='Example', lost_time=datetime.datetime.now())
         db.session.add(action)
         db.session.flush()
         analysis = Analysis(name='Some basic analysis',
                             action_id=action.id,
                             ipp_longitude=80,
                             ipp_latitude=70,
                             rp_latitude=30,
                             rp_longitude=80)
         db.session.add(analysis)
         db.session.flush()
         model_type = ModelType.query.filter_by(complex=False).first()
         self.assertIsNotNone(model_type.id)
         model = Model(analysis_id=analysis.id, model_type_id=model_type.id)
         db.session.add(model)
         db.session.flush()
         self.assertIsNotNone(model.id)
         self.assertEquals(analysis.models.count(), 1)
예제 #28
0
 def test_model_weight_for_child_model(self):
     with app.app_context():
         action = add_simple_action(db.session)
         analysis = add_analysis_with_coordinates(db.session, action.id)
         model_type = ModelType.query.filter_by(complex=False).first()
         complex_model_type = ModelType.query.filter_by(
             complex=True).first()
         model = Model(analysis_id=analysis.id, model_type_id=model_type.id)
         complex_model = Model(analysis_id=analysis.id,
                               model_type_id=complex_model_type.id)
         db.session.add(model)
         db.session.add(complex_model)
         db.session.flush()
         model.create_weights(parent_model_id=complex_model.id)
         db.session.flush()
         self.assertEquals(analysis.models.count(), 2)
         self.assertEquals(model.model_weights.count(), 1)
         self.assertEquals(model.child_model_weights.count(), 0)
         self.assertEquals(complex_model.model_weights.count(), 0)
         self.assertEquals(complex_model.child_model_weights.count(), 1)
예제 #29
0
    def test_cs_simple_models_representation(self):
        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_analysis_with_coordinates(db.session, action.id)

            # add simple models
            model_type_names = [
                'HorDistIPP', 'ElevChgIPP', 'HorChgIPP', 'DispAngle',
                'TrackOffset', 'FindLocation', 'Mobility'
            ]
            for mtn in model_type_names:
                model_type = ModelType.query.filter_by(name=mtn).first()
                model = Model(analysis_id=analysis.id,
                              model_type_id=model_type.id)
                db.session.add(model)
                db.session.flush()

            expected = model_type_names

            self.assertEquals(len(analysis.cs_simple_models()), len(expected))
            self.assertEquals(analysis.cs_simple_models(), expected)
예제 #30
0
    def test_starting_analysis_with_simple_models(self):
        expected_content = {
            "HorDistIPP": "3897890975230495710",
            "ElevChgIPP": "4709831647259734695",
            "HorChgIPP": "4375692374598762347",
            "TrackOffset": "3476273469987234659",
            "DispAngle": "3892345235423495710",
            "FindLocation": "4709831647263434695",
            "Mobility": "4375692374598762346",
        }

        httpretty.register_uri(httpretty.POST,
                               server_path('analysis'),
                               body=json.dumps(expected_content),
                               content_type="application/json")

        with app.app_context():
            action = add_simple_action(db.session)
            analysis = add_simple_models_analysis(db.session, action.id)
            analysis.start_computation()
            for model in analysis.simple_models():
                self.assertEquals(model.result_id,
                                  expected_content[model.name])