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)
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)
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')
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()
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)
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)
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)
def test_cs_complex_models_representation(self): with app.app_context(): action = add_simple_action(db.session) analysis = add_analysis_with_coordinates(db.session, action.id) # add comb model model_type = ModelType.query.filter_by(name='CombProb').first() comb_model = Model(analysis_id=analysis.id, model_type_id=model_type.id) db.session.add(comb_model) db.session.flush() # add search seg model model_type = ModelType.query.filter_by(name='SearchSeg').first() seg_model = Model(analysis_id=analysis.id, model_type_id=model_type.id) db.session.add(seg_model) db.session.flush() # add simple models model_type_names = ['HorDistIPP', 'FindLocation', 'Mobility'] result_ids = ['213', '543', '234'] weight = 4 for mtn, result_id in zip(model_type_names, result_ids): 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() model.create_weights(parent_model_id=comb_model.id, weight=weight) model.create_weights(parent_model_id=seg_model.id, weight=weight) model.update_result(result_id) expected_complex_analyses = ['CombProb', 'SearchSeg'] expected_model_weights = { 'HorDistIPP': { 'id': '213', 'weight': weight }, 'FindLocation': { 'id': '543', 'weight': weight }, 'Mobility': { 'id': '234', 'weight': weight }, } cs_complex_models = analysis.cs_complex_models() cs_model_weights = analysis.cs_complex_model_weights() self.assertEquals(len(cs_complex_models), len(expected_complex_analyses)) self.assertEquals(sorted(cs_complex_models), sorted(expected_complex_analyses)) self.assertEquals(len(cs_model_weights), len(expected_model_weights)) self.assertEquals(sorted(cs_model_weights), sorted(expected_model_weights))
def test_adding_complete_analysis(self): with app.app_context(): # add action action = Action(name='Rysy', lost_time=datetime.datetime.now()) db.session.add(action) db.session.flush() # add analysis 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) # add comb model model_type = ModelType.query.filter_by(name='CombProb').first() comb_model = Model(analysis_id=analysis.id, model_type_id=model_type.id) db.session.add(comb_model) db.session.flush() # add search seg model model_type = ModelType.query.filter_by(name='SearchSeg').first() seg_model = Model(analysis_id=analysis.id, model_type_id=model_type.id) db.session.add(seg_model) db.session.flush() # 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() model.create_weights(parent_model_id=comb_model.id) model.create_weights(parent_model_id=seg_model.id) # add chosen profiles 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() self.assertEquals(analysis.profiles.count(), 2) self.assertEquals(analysis.models.count(), 9) self.assertEquals(comb_model.child_model_weights.count(), 7) self.assertEquals(seg_model.child_model_weights.count(), 7)