Exemplo n.º 1
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
Exemplo 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
Exemplo 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)
Exemplo 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)
Exemplo 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'])
Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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))
Exemplo 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)
Exemplo n.º 11
0
 def result(self):
     path = "%s/result" % self._get_path(self.id)
     resp = request("get", path)
     return convert_to_analyzere_object(resp)
Exemplo n.º 12
0
 def profile(self):
     path = '%s/profile' % self._get_path(self.id)
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Exemplo 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)
Exemplo n.º 14
0
 def test_empty_str_response_deserialized(self, reqmock):
     reqmock.get('https://api/bar', status_code=200, text='')
     assert request('get', 'bar') == ''
Exemplo 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')
Exemplo 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 == '""'
Exemplo 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'}
Exemplo 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
Exemplo 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"}'
Exemplo 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)
Exemplo 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)
Exemplo n.º 22
0
 def result(self):
     path = '%s/result' % self._get_path(self.id)
     resp = request('get', path)
     return convert_to_analyzere_object(resp)
Exemplo 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))
Exemplo 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"}'
Exemplo n.º 25
0
 def upload_status(self):
     resp = request("get", self._status_path)
     return convert_to_analyzere_object(resp)
Exemplo 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 == '""'
Exemplo 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)
Exemplo n.º 28
0
 def test_empty_str_response_deserialized(self, reqmock):
     reqmock.get("https://api/bar", status_code=200, text="")
     assert request("get", "bar") == ""
Exemplo 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)
Exemplo n.º 30
0
 def list(cls, **params):
     resp = request("get", cls._get_path(), params=params)
     return convert_to_analyzere_object(resp, cls)
Exemplo n.º 31
0
 def retrieve(cls, id_):
     resp = request('get', cls._get_path(id_))
     return convert_to_analyzere_object(resp, cls)
Exemplo 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)
Exemplo 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
Exemplo n.º 34
0
 def list(cls, **params):
     resp = request('get', cls._get_path(), params=params)
     return convert_to_analyzere_object(resp, cls)
Exemplo 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"}
Exemplo n.º 36
0
 def upload_status(self):
     resp = request('get', self._status_path)
     return convert_to_analyzere_object(resp)
Exemplo 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")
Exemplo n.º 38
0
 def retrieve(cls, id_):
     resp = request("get", cls._get_path(id_))
     return convert_to_analyzere_object(resp, cls)