Beispiel #1
0
 def test_get_plink_smoothing(self):
     with self.app.app_context():
         for idx in [1, 2]:
             flumodel = FluModel()
             flumodel.name = 'Test Model %d' % idx
             flumodel.is_public = True
             flumodel.is_displayed = True
             flumodel.source_type = 'google'
             flumodel.calculation_parameters = 'matlab_model,1'
             dates = [date(2018, 6, d) for d in range(1, 30)]
             datapoints = []
             for d in dates:
                 entry = ModelScore()
                 entry.region = 'e'
                 entry.score_date = d
                 entry.calculation_timestamp = datetime.now()
                 entry.score_value = 1.23 / d.day
                 entry.confidence_interval_lower = 0.81
                 entry.confidence_interval_upper = 1.65
                 datapoints.append(entry)
             flumodel.model_scores = datapoints
             model_function = ModelFunction()
             model_function.id = idx
             model_function.function_name = 'matlab_model'
             model_function.average_window_size = 1
             model_function.flu_model_id = idx
             model_function.has_confidence_interval = True
             flumodel.save()
             model_function.save()
         default_model = DefaultFluModel()
         default_model.flu_model_id = 1
         rate_thresholds = RateThresholdSet()
         rate_thresholds.low_value = 0.1
         rate_thresholds.medium_value = 0.2
         rate_thresholds.high_value = 0.3
         rate_thresholds.very_high_value = 0.4
         rate_thresholds.valid_from = date(2010, 1, 1)
         rate_thresholds.save()
         DB.session.add(default_model)
         DB.session.commit()
     response = self.client().get(
         '/plink?id=1&id=2&startDate=2018-06-01&endDate=2018-06-05&smoothing=3'
     )
     self.assertListEqual(response.get_json()['model_list'],
                          [{
                              'id': 1,
                              'name': 'Test Model 1'
                          }, {
                              'id': 2,
                              'name': 'Test Model 2'
                          }])
     self.assertEqual(
         len(response.get_json()['model_data'][0]['data_points']), 5)
     self.assertEqual(
         len(response.get_json()['model_data'][1]['data_points']), 5)
     expected = {
         'low_value': {
             'label': 'Low epidemic rate',
             'value': 0.1
         },
         'medium_value': {
             'label': 'Medium epidemic rate',
             'value': 0.2
         },
         'high_value': {
             'label': 'High epidemic rate',
             'value': 0.3
         },
         'very_high_value': {
             'label': 'Very high epidemic rate',
             'value': 0.4
         }
     }
     self.assertDictEqual(response.get_json()['rate_thresholds'], expected)
     list_expected = [0.252833, 0.321167, 0.444167, 0.751667, 0.922500]
     list_result = [
         round(s['score_value'], 6)
         for s in response.get_json()['model_data'][0]['data_points']
     ]
     self.assertListEqual(list_result, list_expected)
Beispiel #2
0
 def test_get_twlink_current_link(self):
     flumodel = FluModel()
     flumodel.id = 1
     flumodel.name = 'Test Model'
     flumodel.is_public = True
     flumodel.is_displayed = True
     flumodel.source_type = 'google'
     flumodel.calculation_parameters = 'matlab_model,1'
     flumodel.model_region_id = '1-e'
     dates = [date(2018, 6, d) for d in range(1, 30)]
     datapoints = []
     for d in dates:
         entry = ModelScore()
         entry.region = 'e'
         entry.score_date = d
         entry.calculation_timestamp = datetime.now()
         entry.score_value = 1.23
         entry.confidence_interval_lower = 0.81
         entry.confidence_interval_upper = 1.65
         datapoints.append(entry)
     flumodel.model_scores = datapoints
     model_function = ModelFunction()
     model_function.id = 1
     model_function.function_name = 'matlab_model'
     model_function.average_window_size = 1
     model_function.flu_model_id = 1
     model_function.has_confidence_interval = True
     default_model = DefaultFluModel()
     default_model.flu_model_id = 1
     rate_thresholds = RateThresholdSet()
     rate_thresholds.low_value = 0.1
     rate_thresholds.medium_value = 0.2
     rate_thresholds.high_value = 0.3
     rate_thresholds.very_high_value = 0.4
     rate_thresholds.valid_from = date(2010, 1, 1)
     with self.app.app_context():
         flumodel.save()
         model_function.save()
         rate_thresholds.save()
         DB.session.add(default_model)
         DB.session.commit()
     response = self.client().get(
         '/twlink?id=1&start=2018-06-01&end=2018-06-10')
     self.assertListEqual(response.get_json()['model_list'],
                          [{
                              'id': 1,
                              'name': 'Test Model'
                          }])
     self.assertEqual(
         len(response.get_json()['model_data'][0]['data_points']), 10)
     expected = {
         'low_value': {
             'label': 'Low epidemic rate',
             'value': 0.1
         },
         'medium_value': {
             'label': 'Medium epidemic rate',
             'value': 0.2
         },
         'high_value': {
             'label': 'High epidemic rate',
             'value': 0.3
         },
         'very_high_value': {
             'label': 'Very high epidemic rate',
             'value': 0.4
         }
     }
     self.assertDictEqual(response.get_json()['rate_thresholds'], expected)