def test_multi_task_prediction_list_to_json(self): featurized_jsons = glob( os.path.join(MULTI_TASK_FEATURES_PATH, "*features.json")) json_obj = { "mode": self.events_mode, "file_list": featurized_jsons, 'run_list': list(range(len(featurized_jsons))) } json_string = json.dumps(json_obj) newjsonpaths = process_file_list_from_json( json_string, model_dir=MODEL_DIR, processed_dir=MULTI_TASK_FEATURES_PATH, predict_only=True) reloaded = json.loads(newjsonpaths) prediction_reloaded = loadfn(reloaded['file_list'][0]) self.assertIsInstance(prediction_reloaded['cycle_number'], np.ndarray) self.assertGreater(len(prediction_reloaded['cycle_number']), 1) # Testing error output self.assertIsInstance(prediction_reloaded['fractional_error'], np.ndarray) self.assertEqual(len(prediction_reloaded['fractional_error']), 1) # for now just a single fractional error predictions = glob( os.path.join(MULTI_TASK_FEATURES_PATH, "*predictions.json")) for file in predictions: os.remove(file)
def test_serialized_prediction(self): # Testing nominal capacity calculation feature_json_path = os.path.join( TEST_FILE_DIR, "2017-06-30_2C-10per_6C_CH10_full_model_multi_features.json") json_obj = { "mode": self.events_mode, "file_list": [feature_json_path, feature_json_path], 'run_list': [0, 1] } json_string = json.dumps(json_obj) newjsonpaths = process_file_list_from_json(json_string, model_dir=MODEL_DIR, processed_dir=TEST_FILE_DIR) reloaded = json.loads(newjsonpaths) prediction_reloaded = loadfn(reloaded['file_list'][0]) features = loadfn(feature_json_path) self.assertEqual(features.nominal_capacity, 1.0628421000000001) self.assertFalse((prediction_reloaded['discharge_capacity'] - np.around(np.arange(.98, 0.78, -0.03), 2) * features.nominal_capacity).any()) os.remove( os.path.join( TEST_FILE_DIR, '2017-06-30_2C-10per_6C_CH10_full_model_multi_predictions.json' ))
def test_single_task_prediction_list_to_json(self): featurized_jsons = glob( os.path.join(SINGLE_TASK_FEATURES_PATH, "*features.json")) json_obj = { "mode": self.events_mode, "file_list": featurized_jsons, "run_list": list(range(len(featurized_jsons))), } json_string = json.dumps(json_obj) newjsonpaths = process_file_list_from_json( json_string, model_dir=MODEL_DIR, processed_dir=SINGLE_TASK_FEATURES_PATH, predict_only=True, ) reloaded = json.loads(newjsonpaths) # Ensure first is correct prediction_reloaded = loadfn(reloaded["file_list"][0]) self.assertIsInstance(prediction_reloaded["cycle_number"], np.ndarray) # Testing error output self.assertIsInstance(prediction_reloaded["fractional_error"], np.ndarray) predictions = glob( os.path.join(SINGLE_TASK_FEATURES_PATH, "*predictions.json")) for file in predictions: os.remove(file)
def test_single_task_prediction_list_to_json(self): featurized_jsons = glob( os.path.join(single_task_features_path, "*features.json")) json_obj = { "mode": self.events_mode, "file_list": featurized_jsons, 'run_list': list(range(len(featurized_jsons))) } json_string = json.dumps(json_obj) newjsonpaths = process_file_list_from_json( json_string, model_dir=TEST_FILE_DIR, processed_dir=single_task_features_path, predict_only=True) reloaded = json.loads(newjsonpaths) # Ensure first is correct prediction_reloaded = loadfn(reloaded['file_list'][0]) self.assertIsInstance(prediction_reloaded['cycle_number'], np.ndarray) # Testing error output self.assertIsInstance(prediction_reloaded['fractional_error'], np.ndarray) predictions = glob( os.path.join(single_task_features_path, "*predictions.json")) for file in predictions: os.remove(file)
def test_python(self): """Python script for end to end test""" # Copy mapped = collate.process_files_json() rename_output = json.loads(mapped) rename_output['mode'] = self.events_mode # mode run|test|events_off rename_output['run_list'] = list(range(len( rename_output['file_list']))) mapped = json.dumps(rename_output) # Validation validated = validate.validate_file_list_from_json(mapped) validated_output = json.loads(validated) validated_output['mode'] = self.events_mode # mode run|test|events_off validated_output['run_list'] = list( range(len(validated_output['file_list']))) validated = json.dumps(validated_output) # Data structuring structured = structure.process_file_list_from_json(validated) structured_output = json.loads(structured) structured_output[ 'mode'] = self.events_mode # mode run|test|events_off structured_output['run_list'] = list( range(len(structured_output['file_list']))) structured = json.dumps(structured_output) # Featurization featurized = featurize.process_file_list_from_json(structured) featurized_output = json.loads(featurized) featurized_output[ 'mode'] = self.events_mode # mode run|test|events_off featurized_output['run_list'] = list( range(len(featurized_output['file_list']))) featurized = json.dumps(featurized_output) # Prediction predictions = run_model.process_file_list_from_json( featurized, model_dir=MODEL_DIR) # Validate output files self._check_result_file_validity()