def run_achilles(hpo_id=None): """checks for full results and run achilles/heel :hpo_id: hpo on which to run achilles :returns: """ if hpo_id is not None: logging.info('running achilles for hpo_id %s' % hpo_id) achilles.create_tables(hpo_id, True) achilles.load_analyses(hpo_id) achilles.run_analyses(hpo_id=hpo_id) if hpo_id is not None: logging.info('running achilles_heel for hpo_id %s' % hpo_id) achilles_heel.create_tables(hpo_id, True) achilles_heel.run_heel(hpo_id=hpo_id)
def test_heel_analyses(self): # Long-running test self._load_dataset() # populate achilles first test_util.get_synpuf_results_files() test_util.populate_achilles(self.hpo_bucket, include_heel=False) achilles_heel.create_tables(FAKE_HPO_ID, True) achilles_heel.run_heel(hpo_id=FAKE_HPO_ID) cmd = validation.sql_wrangle.qualify_tables( 'SELECT COUNT(1) FROM %sachilles_heel_results' % validation.sql_wrangle.PREFIX_PLACEHOLDER, FAKE_HPO_ID) result = bq_utils.query(cmd) self.assertEqual(int(result['rows'][0]['f'][0]['v']), ACHILLES_HEEL_RESULTS_COUNT) cmd = validation.sql_wrangle.qualify_tables( 'SELECT COUNT(1) FROM %sachilles_results_derived' % validation.sql_wrangle.PREFIX_PLACEHOLDER, FAKE_HPO_ID) result = bq_utils.query(cmd) self.assertEqual(int(result['rows'][0]['f'][0]['v']), ACHILLES_RESULTS_DERIVED_COUNT)
def test_heel_analyses(self): # Long-running test self._load_dataset() # populate achilles first test_util.get_synpuf_results_files() test_util.populate_achilles(self.hpo_bucket, include_heel=False) achilles_heel.create_tables(FAKE_HPO_ID, True) achilles_heel.run_heel(hpo_id=FAKE_HPO_ID) cmd = validation.sql_wrangle.qualify_tables( 'SELECT COUNT(1) FROM %sachilles_heel_results' % validation.sql_wrangle.PREFIX_PLACEHOLDER, FAKE_HPO_ID) result = bq_utils.query(cmd) self.assertEqual(ACHILLES_HEEL_RESULTS_COUNT, int(result['rows'][0]['f'][0]['v'])) cmd = validation.sql_wrangle.qualify_tables( 'SELECT COUNT(1) FROM %sachilles_results_derived' % validation.sql_wrangle.PREFIX_PLACEHOLDER, FAKE_HPO_ID) result = bq_utils.query(cmd) self.assertEqual(ACHILLES_RESULTS_DERIVED_COUNT, int(result['rows'][0]['f'][0]['v'])) # test new heel re-categorization errors = [2, 4, 5, 101, 200, 206, 207, 209, 400, 405, 406, 409, 411, 413, 500, 505, 506, 509, 600, 605, 606, 609, 613, 700, 705, 706, 709, 711, 713, 715, 716, 717, 800, 805, 806, 809, 813, 814, 906, 1006, 1609, 1805] cmd = validation.sql_wrangle.qualify_tables( """SELECT analysis_id FROM {prefix}achilles_heel_results WHERE achilles_heel_warning like 'ERROR:%' GROUP BY analysis_id""".format(prefix=validation.sql_wrangle.PREFIX_PLACEHOLDER), FAKE_HPO_ID) result = bq_utils.query(cmd) # self.assertIsNone(result.get('analysis_id', None)) actual_result = [int(row['f'][0]['v']) for row in result['rows']] for analysis_id in actual_result: self.assertIn(analysis_id, errors) # self.assertEqual(ACHILLES_HEEL_RESULTS_ERROR_COUNT, int(result['rows'][0]['f'][0]['v'])) warnings = [4, 5, 7, 8, 9, 200, 210, 302, 400, 402, 412, 420, 500, 511, 512, 513, 514, 515, 602, 612, 620, 702, 712, 720, 802, 812, 820] cmd = validation.sql_wrangle.qualify_tables( """SELECT analysis_id FROM {prefix}achilles_heel_results WHERE achilles_heel_warning like 'WARNING:%' GROUP BY analysis_id""".format(prefix=validation.sql_wrangle.PREFIX_PLACEHOLDER), FAKE_HPO_ID) result = bq_utils.query(cmd) # self.assertIsNone(result.get('analysis_id', None)) actual_result = [int(row['f'][0]['v']) for row in result['rows']] for analysis_id in actual_result: self.assertIn(analysis_id, warnings) # self.assertEqual(ACHILLES_HEEL_RESULTS_WARNING_COUNT, int(result['rows'][0]['f'][0]['v'])) notifications = [101, 103, 105, 114, 115, 118, 208, 301, 410, 610, 710, 810, 900, 907, 1000, 1800, 1807] cmd = validation.sql_wrangle.qualify_tables( """SELECT analysis_id FROM {prefix}achilles_heel_results WHERE achilles_heel_warning like 'NOTIFICATION:%' and analysis_id is not null GROUP BY analysis_id""".format(prefix=validation.sql_wrangle.PREFIX_PLACEHOLDER), FAKE_HPO_ID) result = bq_utils.query(cmd) self.assertIsNone(result.get('analysis_id', None)) actual_result = [int(row['f'][0]['v']) for row in result['rows']] for analysis_id in actual_result: self.assertIn(analysis_id, notifications)
def test_heel_analyses(self, mock_hpo_bucket): # Long-running test mock_hpo_bucket.return_value = self.get_mock_hpo_bucket() # create randomized tables to bypass BQ rate limits random_string = str(randint(10000, 99999)) randomized_hpo_id = FAKE_HPO_ID + '_' + random_string # prepare self._load_dataset(randomized_hpo_id) test_util.populate_achilles(hpo_id=randomized_hpo_id, include_heel=False) # define tables achilles_heel_results = randomized_hpo_id + '_' + achilles_heel.ACHILLES_HEEL_RESULTS achilles_results_derived = randomized_hpo_id + '_' + achilles_heel.ACHILLES_RESULTS_DERIVED # run achilles heel achilles_heel.create_tables(randomized_hpo_id, True) achilles_heel.run_heel(hpo_id=randomized_hpo_id) # validate query = sql_wrangle.qualify_tables( 'SELECT COUNT(1) as num_rows FROM %s' % achilles_heel_results) response = bq_utils.query(query) rows = bq_utils.response2rows(response) self.assertEqual(ACHILLES_HEEL_RESULTS_COUNT, rows[0]['num_rows']) query = sql_wrangle.qualify_tables( 'SELECT COUNT(1) as num_rows FROM %s' % achilles_results_derived) response = bq_utils.query(query) rows = bq_utils.response2rows(response) self.assertEqual(ACHILLES_RESULTS_DERIVED_COUNT, rows[0]['num_rows']) # test new heel re-categorization errors = [ 2, 4, 5, 101, 200, 206, 207, 209, 400, 405, 406, 409, 411, 413, 500, 505, 506, 509, 600, 605, 606, 609, 613, 700, 705, 706, 709, 711, 713, 715, 716, 717, 800, 805, 806, 809, 813, 814, 906, 1006, 1609, 1805 ] query = sql_wrangle.qualify_tables( """SELECT analysis_id FROM {table_id} WHERE achilles_heel_warning LIKE 'ERROR:%' GROUP BY analysis_id""".format(table_id=achilles_heel_results)) response = bq_utils.query(query) rows = bq_utils.response2rows(response) actual_result = [row["analysis_id"] for row in rows] for analysis_id in actual_result: self.assertIn(analysis_id, errors) warnings = [ 4, 5, 7, 8, 9, 200, 210, 302, 400, 402, 412, 420, 500, 511, 512, 513, 514, 515, 602, 612, 620, 702, 712, 720, 802, 812, 820 ] query = sql_wrangle.qualify_tables( """SELECT analysis_id FROM {table_id} WHERE achilles_heel_warning LIKE 'WARNING:%' GROUP BY analysis_id""".format(table_id=achilles_heel_results)) response = bq_utils.query(query) rows = bq_utils.response2rows(response) actual_result = [row["analysis_id"] for row in rows] for analysis_id in actual_result: self.assertIn(analysis_id, warnings) notifications = [ 101, 103, 105, 114, 115, 118, 208, 301, 410, 610, 710, 810, 900, 907, 1000, 1800, 1807 ] query = sql_wrangle.qualify_tables( """SELECT analysis_id FROM {table_id} WHERE achilles_heel_warning LIKE 'NOTIFICATION:%' and analysis_id is not null GROUP BY analysis_id""".format(table_id=achilles_heel_results)) response = bq_utils.query(query) rows = bq_utils.response2rows(response) actual_result = [row["analysis_id"] for row in rows] for analysis_id in actual_result: self.assertIn(analysis_id, notifications)