Get Asset AI Data with Aggregation Logic

获取指定设备的指定测点在某段时间内的AI分钟级归一化数据,并支持对查询到的数据进行聚合处理。

操作权限

需授权的资源 所需操作权限
资产 Read

有关各资源及其对应的权限,参考 策略,角色,与权限>>

请求格式

POST https://{apigw-address}/tsdb-service/v2.1/ai-normalized

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织ID。如何获取orgId信息>>

请求参数(Body)

名称 必需/可选 数据类型 描述
modelId 可选 String 资产所属模型ID。如何获取modelId信息>>
assetIds 必需 String 资产ID,支持查询多个资产,多个资产ID之间用英文逗号隔开。如何获取Asset ID信息>>
pointIdsWithLogic 必需 String 测点数据聚合逻辑,支持的聚合计算方式有count, avg, sum, max, min, first, last。聚合查询的时间区间为 [startTime,endTime),即聚合操作数包含 startTime 时刻的数据,但不包含 endTime 时刻的数据。格式为:函数(测点标识符),例如:sum(pointId)如何获取pointId信息>>
interval 必需 Integer 聚合算法作用的时间间隔,有效值为0-1440,单位是分钟。当间隔为0,测点不能带聚合逻辑;当间隔值大于0,测点必须带聚合逻辑。
startTime 必需 String 采样数据开始时间,支持local时间和UTC时间。local时间的格式为 YYYY-MM-DD HH:MM:SS。当格式为local时间时,使用设备所在地的当地时间进行查询。UTC时间格式需要加入时区信息,例如:2019-06-01T00:00:00+08:00。当格式为UTC时间时,对所有资产按照统一的开始时间和结束时间进行查询。
endTime 必需 String 采样数据结束时间,格式必须与开始时间保持一致。
pageSize 可选 Integer 单次查询返回记录条数的上限,默认为1000。
localTimeAccuracy 可选 Boolean 指定查询结果是否包含毫秒级结果。true 表示需要毫秒格式,false 表示不需要毫秒格式。
localTimeFormat 可选 Integer 指定返回数据的local时间是否包含设备时区信息。0:不包含设备时区信息;1:包含设备时区信息;默认值为0。
itemFormat 可选 Integer 指定返回结果中测点数据的显示格式。可选值为0,1,2,默认值为0。对每种显示格式的详细介绍,参见 Item Format 示例>>

响应参数

名称 数据类型 描述
data List<JSONObject> 资产数据列表。单设备单点的返回数据按时间升序排列。详见 items

items

示例

{
        "count(yourPointId)": 4,
        "assetId": "yourAssetId",
        "timestamp": 1587312600000,
        "localtime": "2020-04-20 00:10:00"
}

参数

名称 数据类型 描述
pointIdsWithLogic Double 此参数是变量,表示测点标识符(带聚合逻辑或不带)与对应数据。
assetId String 资产ID。
timestamp Long 数据时间戳,UNIX时间,精确到秒。
localtime String 数据本地时间标记,精确到秒。返回结果是否包含设备时区信息,由 localTimeFormat 参数指定。

错误码

有关错误码的描述,参见通用错误码

示例 1

请求示例

Local时间格式:

url: https://{apigw-address}/tsdb-service/v2.1/ai-normalized?orgId=yourOrgId

method: POST

Content-Type: application/json

requestBody:
{
  "assetIds": "yourAssetIds",
  "pointIdsWithLogic": "count(yourPointId)",
  "startTime": "2020-04-20 00:00:00",
  "endTime": "2020-04-21 00:00:00",
  "interval": 10,
  "pageSize": 10,
  "localTimeAccuracy": false,
  "localTimeFormat": 0,
  "itemFormat": 0
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "submsg": null,
  "data": {
    "items": [
      {
        "count(yourPointId)": 5,
        "assetId": "yourAssetId",
        "timestamp": 1587312600000,
        "localtime": "2020-04-20 00:10:00"
      }
    ]
  }
}

示例 2

请求示例

UTC时间格式:

url: https://{apigw-address}/tsdb-service/v2.1/ai-normalized?orgId=yourOrgId

method: POST

Content-Type: application/json

requestBody:
{
  "assetIds": "yourAssetIds",
  "pointIdsWithLogic": "count(yourPointId)",
  "startTime": "2020-04-20T00:00:00+08:00",
  "endTime": "2020-04-21T00:00:00+08:00",
  "interval": 10,
  "pageSize": 10,
  "localTimeAccuracy": false,
  "localTimeFormat": 1,
  "itemFormat": 0
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "submsg": null,
  "data": {
    "items": [
      {
        "count(yourPointId)": 5,
        "assetId": "yourAssetId",
        "timestamp": 1587312600000,
        "localtime": "2020-04-20T00:10:00+08:00"
      }
    ]
  }
}

Java SDK调用示例

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;

public class GetAssetAiDataWithAggregationLogic {
     private static final String API_GATEWAY_URL = "https://{apigw-address}";

     private static class Request extends PoseidonRequest {

          public void setBodyParams(String key, Object value) {
               bodyParams().put(key, value);
          }

          public void setMethod(String method) {
               this.method = method;
          }

          private String method;

          @Override
          public String baseUri() {
               return "";
          }

          @Override
          public String method() {
               return method;
          }
     }

     public static void main(String[] args) {
          //1.在EnOS管理门户的左边导航栏中点击应用注册。
          //2.点击需调用API的应用,查看基本信息中的AccessKey和SecretKey
          Poseidon poseidon = Poseidon.config(
                  PConfig.init()
                          .appKey("AccessKey of your APP")
                          .appSecret("SecretKey of your APP")
          ).method("POST").header("Content-Type", "application/json");

          Request request = new Request();
          request.setBodyParams("assetIds", "yourAssetId");
          request.setBodyParams("pointIdsWithLogic", "count(yourPointId)");
          request.setBodyParams("startTime", "2020-04-20 00:00:00");
          request.setBodyParams("endTime", "2020-04-21 00:00:00");
          request.setBodyParams("interval", 10);
          request.setBodyParams("pageSize", 10);
          request.setBodyParams("localTimeAccuracy", false);
          request.setBodyParams("localTimeFormat", 0);
          request.setBodyParams("itemFormat", 0);

          JSONObject response = poseidon
                  .url(API_GATEWAY_URL + "/tsdb-service/v2.1/ai-normalized")
                  .queryParam("orgId", "yourOrgId")
                  .getResponse(request, JSONObject.class);
          System.out.println(response);
     }
}