def save(self):
     id_ = getattr(self, "id", None)
     method = "put" if id_ else "post"
     resp = request(method, self._get_path(id_), data=self.to_dict())
     self.clear()
     self.update(convert_to_analyzere_object(resp))
     return self
Esempio n. 2
0
 def save(self):
     id_ = getattr(self, 'id', None)
     method = 'put' if id_ else 'post'
     resp = request(method, self._get_path(id_), data=self.to_dict())
     self.clear()
     self.update(convert_to_analyzere_object(resp))
     return self
Esempio n. 3
0
 def result(self):
     warnings.warn(
         "result() is deprecated, use candidates() instead to page over results",
         DeprecationWarning
     )
     path = '{}/result'.format(self._get_path(self.id))
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Esempio n. 4
0
 def initial_metrics(self):
     """
     The name of this method is chosen to avoid overlap with the initial_portfolio_metrics property of the
     OptimizationView
     """
     path = '{}/initial_portfolio_metrics'.format(self._get_path(self.id))
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Esempio n. 5
0
 def marginal(self, layer_views_to_add, layer_views_to_remove):
     path = 'portfolio_view_marginals'
     data = request('post', path, data={
         'portfolio_view_id': to_dict(self.reference()),
         'add_layer_view_ids': [to_dict(lv.reference()) for lv in layer_views_to_add],
         'remove_layer_view_ids': [to_dict(lv.reference()) for lv in layer_views_to_remove]
     })
     return load_reference('portfolio_views', data['portfolio_view']['ref_id'])
Esempio n. 6
0
 def currencies(self):
     path = '{}/currencies'.format(self._get_path(self.id))
     resp = request('get', path)
     # response will be an embedded object with currencies list
     # each element of the currencies list is again an embedded object with the structure like:
     #   {
     #       "code": "CAD"
     #   }
     return convert_to_analyzere_object(resp)
Esempio n. 7
0
 def sensitivity_analysis(self, candidates=[]):
     # candidates can be only non negative integers
     candidates = list(filter(lambda x: isinstance(x, int) and x >= 0, candidates))
     if len(candidates) == 0:
         path = '{}/sensitivity_analysis'.format(self._get_path(self.id))
     else:
         path = '{}/sensitivity_analysis?candidates={}'.format(self._get_path(self.id),
                                                               ','.join(str(c) for c in candidates))
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Esempio n. 8
0
 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)
Esempio n. 9
0
 def el(self, auto_retry=True, **params):
     path = '{}/el'.format(self._get_path(self.id))
     return float(request('get', path, params=params,
                          auto_retry=auto_retry))
Esempio n. 10
0
 def _get_metrics(self, path, params=None, auto_retry=True):
     resp = request('get', path, params=params, auto_retry=auto_retry)
     return convert_to_analyzere_object(resp)
Esempio n. 11
0
 def result(self):
     path = "%s/result" % self._get_path(self.id)
     resp = request("get", path)
     return convert_to_analyzere_object(resp)
Esempio n. 12
0
 def profile(self):
     path = '%s/profile' % self._get_path(self.id)
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Esempio n. 13
0
 def _get_metrics(self, path, params=None, auto_retry=True):
     resp = request("get", path, params=params, auto_retry=auto_retry)
     return convert_to_analyzere_object(resp)
Esempio n. 14
0
 def test_empty_str_response_deserialized(self, reqmock):
     reqmock.get('https://api/bar', status_code=200, text='')
     assert request('get', 'bar') == ''
Esempio n. 15
0
 def test_malformed_response(self, reqmock):
     reqmock.get('https://api/bar', status_code=200, text='{foo')
     with pytest.raises(ServerError):
         request('get', 'bar')
Esempio n. 16
0
 def test_empty_str_request_serialized(self, reqmock):
     reqmock.post('https://api/bar', status_code=201)
     request('post', 'bar', data='')
     assert reqmock.last_request.body == '""'
Esempio n. 17
0
 def test_response_deserialized(self, reqmock):
     reqmock.get('https://api/bar', status_code=200, text='{"foo": "bar"}')
     assert request('get', 'bar') == {'foo': 'bar'}
Esempio n. 18
0
 def test_none_request_serialized(self, reqmock):
     reqmock.post('https://api/bar', status_code=201)
     request('post', 'bar', data=None)
     assert reqmock.last_request.body is None
Esempio n. 19
0
 def test_request_serialized(self, reqmock):
     reqmock.post('https://api/bar', status_code=201)
     request('post', 'bar', data={'foo': 'bar'})
     assert reqmock.last_request.body == '{"foo": "bar"}'
Esempio n. 20
0
 def test_request_user_agent(self, reqmock):
     reqmock.post('https://api/bar', status_code=201)
     request('post', 'bar', data=None)
     assert (
         reqmock.last_request.headers['User-Agent'] == analyzere.user_agent)
Esempio n. 21
0
 def back_allocation(self, source_id, auto_retry=True, **params):
     params['source_id'] = source_id
     path = '{}/back_allocations'.format(self._get_path(self.id))
     data = request('get', path, auto_retry=auto_retry, params=params)
     return convert_to_analyzere_object(data)
Esempio n. 22
0
 def result(self):
     path = '%s/result' % self._get_path(self.id)
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Esempio n. 23
0
 def el(self, auto_retry=True, **params):
     path = "%s/el" % self._get_path(self.id)
     return float(request("get", path, params=params, auto_retry=auto_retry))
Esempio n. 24
0
 def test_request_serialized(self, reqmock):
     reqmock.post("https://api/bar", status_code=201)
     request("post", "bar", data={"foo": "bar"})
     assert reqmock.last_request.body == '{"foo": "bar"}'
Esempio n. 25
0
 def upload_status(self):
     resp = request("get", self._status_path)
     return convert_to_analyzere_object(resp)
Esempio n. 26
0
 def test_empty_str_request_serialized(self, reqmock):
     reqmock.post("https://api/bar", status_code=201)
     request("post", "bar", data="")
     assert reqmock.last_request.body == '""'
Esempio n. 27
0
 def candidate_metrics(self):
     path = '{}/candidate_metrics'.format(self._get_path(self.id))
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Esempio n. 28
0
 def test_empty_str_response_deserialized(self, reqmock):
     reqmock.get("https://api/bar", status_code=200, text="")
     assert request("get", "bar") == ""
Esempio n. 29
0
 def portfolio_view(self):
     path = '{}/candidates/{}/portfolio_view'.format(OptimizationView._get_path(self.optimization_view_id),
                                                     self.index)
     resp = request('get', path)
     return convert_to_analyzere_object(resp, PortfolioView)
Esempio n. 30
0
 def list(cls, **params):
     resp = request("get", cls._get_path(), params=params)
     return convert_to_analyzere_object(resp, cls)
Esempio n. 31
0
 def retrieve(cls, id_):
     resp = request('get', cls._get_path(id_))
     return convert_to_analyzere_object(resp, cls)
Esempio n. 32
0
 def back_allocation(self, source_id, auto_retry=True, **params):
     params["source_id"] = source_id
     path = "%s/back_allocations" % self._get_path(self.id)
     data = request("get", path, auto_retry=auto_retry, params=params)
     return convert_to_analyzere_object(data)
Esempio n. 33
0
 def test_none_request_serialized(self, reqmock):
     reqmock.post("https://api/bar", status_code=201)
     request("post", "bar", data=None)
     assert reqmock.last_request.body is None
Esempio n. 34
0
 def list(cls, **params):
     resp = request('get', cls._get_path(), params=params)
     return convert_to_analyzere_object(resp, cls)
Esempio n. 35
0
 def test_response_deserialized(self, reqmock):
     reqmock.get("https://api/bar", status_code=200, text='{"foo": "bar"}')
     assert request("get", "bar") == {"foo": "bar"}
Esempio n. 36
0
 def upload_status(self):
     resp = request('get', self._status_path)
     return convert_to_analyzere_object(resp)
Esempio n. 37
0
 def test_malformed_response(self, reqmock):
     reqmock.get("https://api/bar", status_code=200, text="{foo")
     with pytest.raises(ServerError):
         request("get", "bar")
Esempio n. 38
0
 def retrieve(cls, id_):
     resp = request("get", cls._get_path(id_))
     return convert_to_analyzere_object(resp, cls)