def get_asset_info(assetId): url = api_gateway + '/asset-service/v2.1/assets?' query_data = {'action': 'get', 'orgId': training_orgId, 'assetId': assetId} query_string = parser.urlencode(query_data) url += query_string req = poseidon.urlopen(app_access_key, app_secret_key, url) return req
def get_token(): global token url = 'https://beta-apim-cn4.eniot.io/apim-token-service/v2.0/token/get' hash = hashlib.sha256() hash.update((accessKey + str(millis) + secretKey).encode('utf-8')) data = { "appKey": accessKey, "encryption": hash.hexdigest(), "timestamp": millis } req = poseidon.urlopen(accessKey, secretKey, url, data) token = req.get('data').get('accessToken') print(token)
def get_asset_latest_data(assetIds, measurepoints): url = api_gateway + '/tsdb-service/v2.0/latest?' query_data = { 'orgId': training_orgId, 'assetIds': assetIds, 'measurepoints': measurepoints, 'timeWindow': '', 'accessKey': app_access_key } query_string = parser.urlencode(query_data) url += query_string req = poseidon.urlopen(app_access_key, app_secret_key, url) return req
def query_hive_data(masterid): header = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token } #data = {"sqlQuery": 'select * from `df_hive.data_o15632609593521.iris_tbl`', "queue": None, "itemFormat": None} data = { "sqlQuery": f'select * from df_hive.data_o15632609593521.`kmmlds1` where masterid=\'{masterid}\' and sequence<26000', "queue": None, "itemFormat": None } #data = {"sqlQuery": 'select * from df_hive.`iris_tbl`', "queue": None, "itemFormat": None} req = poseidon.urlopen(accessKey, secretKey, url, data, header) dataframe = pd.DataFrame(req.get('data').get('rows')) #print(dataframe) #print(req) return dataframe
def _get_asset_ai_raw_data(assetId, startTime, endTime): url = api_gateway + '/tsdb-service/v2.0/ai?' query_data = { 'orgId': training_orgId, 'modelId': '', 'assetIds': assetId, 'measurepoints': 'current,voltage,temp', 'startTime': startTime, 'endTime': endTime, 'pageSize': '', 'accessKey': app_access_key } query_string = parser.urlencode(query_data) url += query_string req = poseidon.urlopen(app_access_key, app_secret_key, url) # Arrange the returned data in array format time = [] current = [] voltage = [] temp = [] for item in req['data']['items']: if 'current' in item.keys(): time.append(item['localtime']) current.append(item['current']) elif 'voltage' in item.keys(): voltage.append(item['voltage']) elif 'temp' in item.keys(): temp.append(item['temp']) else: pass # Assemble the response structure resp = {} resp['time'] = time resp['voltage'] = voltage resp['current'] = current resp['temp'] = temp return resp
def get_asset_ai_raw_data(assetId, startTime, endTime): url = api_gateway + '/tsdb-service/v2.0/ai?' query_data = { 'orgId': training_orgId, 'modelId': '', 'assetIds': assetId, 'measurepoints': 'current,voltage,temp', 'startTime': startTime, 'endTime': endTime, 'pageSize': '', 'accessKey': app_access_key } query_string = parser.urlencode(query_data) url += query_string req = poseidon.urlopen(app_access_key, app_secret_key, url) return req
def set_battery_frequency(assetId, frequency): url = api_gateway + '/connect-service/v2.1/commands?' query_data = { 'action': 'invokeService', 'orgId': training_orgId, 'assetId': assetId, 'serviceId': 'high_frequency_report_service', 'pendingTtl': 1000 } query_string = parser.urlencode(query_data) url += query_string print(url) data = {"inputData": {"interval": frequency}} req = poseidon.urlopen(app_access_key, app_secret_key, url, data) return req
def get_active_alerts(): url = api_gateway + '/event-service/v2.1/active-alerts?' query_data = {'action': 'search', 'orgId': training_orgId} query_string = parser.urlencode(query_data) url += query_string data = { "scope": { "treeId": battery_provider_treeId # Specify the asset tree from which to search active alerts }, "pagination": { "pageNo": 1, "pageSize": 10 } } req = poseidon.urlopen(app_access_key, app_secret_key, url, data) return req
def get_child_asset_list(parentId): url = api_gateway + '/asset-tree-service/v2.1/asset-nodes?' query_data = { 'action': 'searchRelatedAsset', 'treeId': battery_provider_treeId, 'orgId': training_orgId } query_string = parser.urlencode(query_data) url += query_string data = { "filter": { "isChildOfAssetId": parentId # Specify the parent node Id for this query }, "projection": ["assetId", "name.defaultValue"] } # poseidon.urlopen is the function defined in our SDK to send an API request. req = poseidon.urlopen(app_access_key, app_secret_key, url, data) return req