Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy of changes from fix-mirror-bugs branch #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions cognite/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@
def get_request(url, params=None, headers=None):
'''Perform a GET request with a predetermined number of retries.'''
for _ in range(_constants.RETRY_LIMIT + 1):
res = requests.get(url, params=params, headers=headers)
try:
res = requests.get(url, params=params, headers=headers)
except Exception as e:
raise _APIError(e)
if res.status_code == 200:
return res
raise _APIError(res.json()['error'])
try:
err_mess = res.json()['error']
except:
err_mess = res.content
raise _APIError(err_mess)

def post_request(url, body, headers=None):
'''Perform a POST request with a predetermined number of retries.'''
for _ in range(_constants.RETRY_LIMIT + 1):
res = requests.post(url, data=json.dumps(body), headers=headers)
try:
res = requests.post(url, data=json.dumps(body), headers=headers)
except Exception as e:
raise _APIError(e)
if res.status_code == 200:
return res
raise _APIError(res.json()['error'])
try:
err_mess = res.json()['error']
except:
err_mess = res.content
raise _APIError(err_mess)

def granularity_to_ms(time_string):
'''Returns millisecond representation of granularity time string'''
Expand Down
9 changes: 8 additions & 1 deletion cognite/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ def get_datapoints_frame(tag_ids, aggregates, granularity, start=None, end=None,
'''
api_key, project = config.get_config_variables(api_key, project)
url = config.get_base_url() + '/projects/{}/timeseries/dataframe'.format(project)
per_tag_limit = int(_constants.LIMIT / len(tag_ids))
num_aggregates = 0
num_agg_per_tag = len(aggregates)
for tag_id in tag_ids:
if isinstance(tag_id, str):
num_aggregates += num_agg_per_tag
else:
num_aggregates += len(tag_id['aggregates'])
per_tag_limit = int(_constants.LIMIT / num_aggregates)
body = {
'items': [{'tagId': '{}'.format(tag_id)}
if isinstance(tag_id, str)
Expand Down