def test_new_match_should_set_header_in_psm(self): job = Job(user=self.user, covariate_variables='ttime_min,slope', outcome_variables='forest_cov') abstractfeature = AbstractFeature() data = Data(abstractfeature) sma = job.process(data) self.assertEqual(sma.names, job.covariate_variables.split(','))
def test_job_process_should_return_Statistical_Matching_Adapter(self): job = Job(user=self.user, covariate_variables='forest_cov', outcome_variables='forest_cov') abstractfeature = AbstractFeature() data = Data(abstractfeature) sma = job.process(data) self.assertIsInstance(sma, StatisticalMatchingAdapter)
def test_get_matched_should_return_ids(self): job = Job(user=self.user, covariate_variables='forest_cov', outcome_variables='forest_cov') abstractfeature = AbstractFeature() data = Data(abstractfeature) sma = job.process(data) self.assertTrue( all([(match in self.control_set) for match in sma.matches]))
def create_job(request): body = json.loads(request.body) user_map = Map.objects.get(pk=request.session['mid']) _clear_job(user_map) caliper = body['caliper'] support = body['support'] covariates = body['covariates'] estimator = body['estimator'] method = body['method'] outcome = body['outcome'] low_outcome_year = body['low_outcome_year'] high_outcome_year = body['high_outcome_year'] error_type = body['error_type'] country = body['country'].encode('latin1') region_type = body['region_type'] state = body['state'] min_forest_cover = body['min_forest_cover'] max_forest_cover = body['max_forest_cover'] agroforest = body['agroforest'] agriculture = body['agriculture'] forest = body['forest'] treatment_area_option = body['treatment_area_option'] control_area_option = body['control_area_option'] session_start = datetime.fromtimestamp( int(body['user_start_time']) / 1000, timezone.utc) # Convert epoch ms to seconds # This user instance does not affect other user identification since we use usermap for identification user = User.objects.get(username='******') layer_services.clear_matched_points(user_map) job = Job(user=user, usermap=user_map, caliper_distance=caliper, common_support=support, covariate_variables=covariates, matching_estimator=estimator, matching_method=method, outcome_variables=outcome, standard_error_type=error_type, low_outcome_year=low_outcome_year, high_outcome_year=high_outcome_year, current=True) job.save() job_stats = JobStats(job_id=job, country=country, session_start=session_start, region_type=region_type, state=state, min_forest_cover=min_forest_cover, max_forest_cover=max_forest_cover, agroforest=agroforest, agriculture=agriculture, forest=forest, treatment_area_option=treatment_area_option, control_area_option=control_area_option) job_stats.save() abstractfeature = AbstractFeature() data = Data(abstractfeature) data.retrieve(user_map, job.outcome_variables, job.covariate_variables) stat_match = job.process(data) matched_feature_ids = stat_match.matches layer_services.set_matched_points(user_map, matched_feature_ids) # While the outcome variable could be assigned to stat_match, # this lets us change the outcome without refitting the match results = stat_match.results( data.outcome_column(job.low_outcome_year, job.high_outcome_year)) balance_statistics = stat_match.balance_statistics() bounds = stat_match.bounds( data.outcome_column(job.low_outcome_year, job.high_outcome_year)) CBSmeans.objects.create_table(job, balance_statistics) CBStests.objects.create_table(job, balance_statistics) # Results.objects.create_table(job, results, data.outcome_names[0]) Results.objects.create_table(job, results, "Forest Loss") # ResultsChart.objects.create_table(job, results, data.outcome_names[0]) ResultsChart.objects.create_table(job, results, "Forest Loss") CheckSensitivity.objects.create_table(job, bounds) return HttpResponse('success', status=200)