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