diff --git a/analyzere/resources.py b/analyzere/resources.py index 34a3a2a..5d928ea 100644 --- a/analyzere/resources.py +++ b/analyzere/resources.py @@ -195,6 +195,23 @@ def candidates(self, index=None): resp = request('get', path) return convert_to_analyzere_object(resp, Candidate, optimization_view_id=self.id) + def candidate_parameters(self, index=None): + if index is None: + path = '{}/candidate_parameters'.format(self._get_path(self.id)) + else: + try: + index = int(index) + except ValueError: + raise Exception('index argument provided to OptimizationView.candidate_parameters() must be an integer') + path = '{}/candidate_parameters/{}'.format(self._get_path(self.id), index) + resp = request('get', path) + return convert_to_analyzere_object(resp, Candidate, optimization_view_id=self.id) + + def candidate_metrics(self): + path = '{}/candidate_metrics'.format(self._get_path(self.id)) + resp = request('get', path) + return convert_to_analyzere_object(resp) + class OptimizationDomain(EmbeddedResource): pass diff --git a/tests/test_base_resources.py b/tests/test_base_resources.py index b0f7bc6..a156d0f 100644 --- a/tests/test_base_resources.py +++ b/tests/test_base_resources.py @@ -884,6 +884,27 @@ def test_candidates(self, reqmock): assert type(r[0]) == Candidate assert r[0].foo == 'bar' + def test_candidate_parameters(self, reqmock): + candidate_parameters_response = ('{' + ' "items": [{"foo": "bar"}],' + ' "meta": {"total_count": 1,"limit": 100,"offset": 0}' + '}') + reqmock.get('https://api/optimization_views/abc123/candidate_parameters', + status_code=200, + text=candidate_parameters_response) + r = OptimizationView(id='abc123').candidate_parameters() + assert isinstance(r, list) + assert len(r) == 1 + assert type(r[0]) == Candidate + assert r[0].foo == 'bar' + + def test_candidate_metrics(self, reqmock): + reqmock.get('https://api/optimization_views/abc123/candidate_metrics', + status_code=200, + text='{"num": 1.0}') + f = OptimizationView(id='abc123').candidate_metrics() + assert f.num == 1.0 + def test_initial_portfolio_metrics(self, reqmock): reqmock.get('https://api/optimization_views/abc123/initial_portfolio_metrics', status_code=200,