def test_load_data_redis(mocker, key, data): mocker.patch('src.middleware.redis_client.redis_client.get', return_value=data) mocker.patch('json.loads', return_value=data) result = store_data_job.load_data_redis(key) assert result['data'] == data['data'] assert result['prediction'] == data['prediction']
def test_load_data_redis(mocker, key, data): mocker.patch("src.middleware.redis_client.redis_client.get", return_value=data) mocker.patch("json.loads", return_value=data) result = store_data_job.load_data_redis(key) assert result["data"] == data["data"] assert result["prediction"] == data["prediction"]
def _predict_from_redis_cache(job_id: str, data_class: callable = Data) -> Data: data_dict = store_data_job.load_data_redis(job_id) if data_dict is None: return None data = data_class(**data_dict) __predict(data) return data
def _predict_async_get(job_id: str) -> Dict[str, List[float]]: result = {job_id: {'prediction': []}} if PlatformConfigurations.platform == PLATFORM_ENUM.DOCKER_COMPOSE.value: data_dict = store_data_job.load_data_redis(job_id) result[job_id]['prediction'] = data_dict['prediction'] return result elif PlatformConfigurations.platform == PLATFORM_ENUM.KUBERNETES.value: data_dict = store_data_job.load_data_redis(job_id) result[job_id]['prediction'] = data_dict['prediction'] return result elif PlatformConfigurations.platform == PLATFORM_ENUM.TEST.value: data_dict = store_data_job.load_data_redis(job_id) result[job_id]['prediction'] = data_dict['prediction'] return result else: return result
def _predict_async_get_label( job_id: str) -> Dict[str, Dict[str, Dict[str, float]]]: result = {job_id: {'prediction': []}} if PlatformConfigurations.platform == PLATFORM_ENUM.DOCKER_COMPOSE.value: data_dict = store_data_job.load_data_redis(job_id) if result[job_id]['prediction'] is None: result[job_id]['prediction'] = data_dict['prediction'] return result argmax = int(np.argmax(np.array(data_dict['prediction'])[0])) result[job_id]['prediction'] = { data_dict['labels'][argmax]: data_dict['prediction'][0][argmax] } return result elif PlatformConfigurations.platform == PLATFORM_ENUM.KUBERNETES.value: data_dict = store_data_job.load_data_redis(job_id) if result[job_id]['prediction'] is None: result[job_id]['prediction'] = data_dict['prediction'] return result argmax = int(np.argmax(np.array(data_dict['prediction'])[0])) result[job_id]['prediction'] = { data_dict['labels'][argmax]: data_dict['prediction'][0][argmax] } return result elif PlatformConfigurations.platform == PLATFORM_ENUM.TEST.value: data_dict = store_data_job.load_data_redis(job_id) if result[job_id]['prediction'] is None: result[job_id]['prediction'] = data_dict['prediction'] return result argmax = int(np.argmax(np.array(data_dict['prediction'])[0])) result[job_id]['prediction'] = { data_dict['labels'][argmax]: data_dict['prediction'][0][argmax] } return result else: return result
def _predict_from_redis_cache(job_id: str, data_class: callable = Data) -> Data: data_dict = store_data_job.load_data_redis(job_id) if data_dict is None: return None if 'image_data' in data_dict.keys(): image_key = store_data_job.make_image_key(job_id) if isinstance(data_dict['image_data'], str) and data_dict['image_data'] == image_key: image_data = store_data_job.get_image_redis(image_key) data_dict['image_data'] = image_data data = data_class(**data_dict) __predict(data) return data