#
Generate a report
To create a summary of the resources used for a specific time period, you must request a report.
def generate_report(period_from, period_to):
request = {
'periodFrom': period_from,
'periodTo': period_to,
'includeDatasets': True,
'includeManipulations': True,
'includeModels': True,
'includeRentedDevices': True,
'includePredictions': True
}
response = requests.post(
f'{OSAI_URL}/Reports', headers=HEADERS, json=request
).json()
return response
#
Wait for response
Reports are not generated immediately, so you should check from time to time to see if a report has already been generated.
def check_report_status(report_id):
response = requests.get(
f'{OSAI_URL}/Reports/{report_id}',headers=HEADERS
).json()
return response
while True:
report_response = check_report_status(report_id)
if report_response['status'] == 0 or report_response['status'] == 1:
print_formatted_json(report_response)
break
time.sleep(2)
Status for report_response
means:
- -1 - in process of creation,
- 0 - report generated correctly,
- 1 - an error occurred during report generation.
#
Example
import requests
import json
import time
OSAI_URL = 'https://app-eu.onestepai.com/api'
API_TOKEN = 'OUR ACCESS TOKEN GENERATED IN OSAI'
HEADERS = {'Authorization': None}
def main():
token = sign_in()
global HEADERS
HEADERS = {'Authorization': f'Bearer {token.text}'}
print('-----Report generator------')
report = generate_report('2022-01-01T00:00:00.000Z', '2023-01-01T00:00:00.000')
print_formatted_json(report)
report_id = report['id']
print('---Waiting for generated report---')
while True:
report_response = check_report_status(report_id)
if report_response['status'] == 0 or report_response['status'] == 1:
print_formatted_json(report_response)
break
time.sleep(2)
def sign_in():
response = requests.post(
url=f'{OSAI_URL}/Users/SignIn', json=API_TOKEN)
return response
def generate_report(period_from, period_to):
request = {
'periodFrom': period_from,
'periodTo': period_to,
'includeDatasets': True,
'includeManipulations': True,
'includeModels': True,
'includeRentedDevices': True,
'includePredictions': True
}
response = requests.post(
f'{OSAI_URL}/Reports', headers=HEADERS, json=request
).json()
return response
def check_report_status(report_id):
response = requests.get(
f'{OSAI_URL}/Reports/{report_id}',headers=HEADERS
).json()
return response
def print_formatted_json(text):
print(json.dumps(text, indent=4))
if __name__ == '__main__':
main()
-----report generator------
{
"id": 16718,
"creationTime": "2023-02-10T14:33:33.7629037Z",
"status": -1
}
---Waiting for generated report---
{
"id": 16718,
"path": "https://onestepai.storage.onestepcloud.pl/s3/d4ae333b-1fa3-499a-bdb1-d941eaa7c37e/Reports/9c54caed-b3cf-4487-9748-68260b258234.json?AWSAccessKeyId=YXBw&Expires=1676041416&Signature=1R8DE2QHsA0pnwDKvD44d7od9Ng%3D",
"totalExistingImagesNum": 20356,
"totalDeletedImagesNum": 94853,
"totalImagesKBMin": 1.4956327299571348e+18,
"totalModelsKBMin": 722292409625.8818,
"totalManipulationSeconds": 11080535,
"totalTrainingSeconds8GB": 72631905,
"totalTrainingSeconds16GB": 0,
"totalConversionSeconds8GB": 251529937,
"totalConversionSeconds16GB": 0,
"totalDeviceRentalSeconds": 2392872,
"totalPredictionSeconds8GB": 146,
"totalPredictionSeconds16GB": 0,
"includeDatasets": true,
"includeManipulations": true,
"includeModels": true,
"includeRentedDevices": true,
"includePredictions": true,
"creationTime": "2023-02-10T14:33:33.762903Z",
"periodFrom": "2022-01-01T00:00:00Z",
"periodTo": "2023-01-01T00:00:00Z",
"read": false,
"status": 0
}