数据统计

更新时间:2023-11-06 09:41:51下载pdf

本文介绍了当前设备的所有统计数据。

注意
1.请使用产品的归属账号提交工单,将目标产品加入后台管理系统统计类目。工单内容务必提供产品 ID 以及该产品 ID 下需要开通统计类功能的 DP ID(功能点 ID)。产品加入后,才可以使用统计类接口。
2.使用 commonApi 需先安装依赖,点击此处安装依赖。
3.日志类接口不需要开通统计功能。

获取 DP 点指定时间段上报日志

名称

getLogInSpecifiedTime

描述

获取 DP 点指定时间段上报日志。

请求参数

参数 数据类型 说明 是否必填
devId String 设备 ID
dpIds String DP 点 ID,可以是多个DP,用逗号隔开即可
offset Integer 查询返回结果时从指定序列后的结果开始返回
limit Integer 单页的最大值,offset + limit 要小于等于4000
startTime String 设备上报的时间,查询起始时间,单位为毫秒
endTime String 设备上报的时间,查询结束时间,单位为毫秒
sortType String DESC 倒序 或 ASC 顺序

返回参数

参数 数据类型 说明
total number 总数据
dps Dp[] 见Dp
hasNext boolean 是否有下一页

Dp

参数 数据类型 说明
timeStamp number 上报数据的时间戳格式
dpId number dp点的id
timeStr string 根据设备时区转换后的时间格式 yyyy-MM-dd HH:mm:ss
value string dp点的值

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getLogInSpecifiedTime({
      devId: TYSdk.devInfo.devId,
      dpIds: '25,20', // 多个DP
      offset: 1,
      limit: 3,
      startTime: '',
      endTime: '',
      sortType: 'ASC',
	})
  .then(response => {
  	console.log(response);
	})
  .catch();

返回示例

{
    "dps": [
        {
            "dpId": 20,
            "value": "false",
            "timeStamp": 1621392860,
            "timeStr": "2021-05-19 10:54:20"
        },
        {
            "dpId": 20,
            "value": "true",
            "timeStamp": 1621392861,
            "timeStr": "2021-05-19 10:54:21"
        },
        {
            "dpId": 20,
            "value": "false",
            "timeStamp": 1621393756,
            "timeStr": "2021-05-19 11:09:16"
        }
    ],
    "hasNext": true,
    "total": 8,
    "dpc": []
}

获取 DP 点上报日志

名称

getDpReportLog

描述

获取 DP 点上报日志。

请求参数

参数 数据类型 说明 是否必填
devId String 设备 ID
dpIds String DP 点 ID,可以是多个DP,用逗号隔开即可
offset Integer 查询返回结果时从指定序列后的结果开始返回
limit Integer 单页的最大值,offset + limit 要小于等于4000
sortType String DESC倒序 或者 ASC顺序

返回参数

参数 数据类型 说明
total number 总条数
dps Dp[] 见Dp
hasNext boolean 是否有下一页

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getDpReportLog({
      devId: TYSdk.devInfo.devId,
      dpIds: '20,30', // 多个DP
      offset: 1,
      limit: 3,
      sortType: 'ASC',
})
  .then(response => {
     console.log(response);
})
  .catch();

返回示例

{
    "dps": [
        {
            "dpId": 20,
            "value": "false",
            "timeStamp": 1621392860,
            "timeStr": "2021-05-19 10:54:20"
        },
        {
            "dpId": 20,
            "value": "true",
            "timeStamp": 1621392861,
            "timeStr": "2021-05-19 10:54:21"
        },
        {
            "dpId": 20,
            "value": "false",
            "timeStamp": 1621393756,
            "timeStr": "2021-05-19 11:09:16"
        }
    ],
    "hasNext": true,
    "total": 7,
    "dpc": []
}

获取用户操作的下发日志

名称

getLogUserAction

描述

获取用户操作的下发日志。

请求参数

参数 数据类型 说明 是否必填
devId String 设备 ID
dpIds String DP 点 ID,可以是多个DP,用逗号隔开即可
offset Integer 查询返回结果时从指定序列后的结果开始返回
limit Integer 单页的最大值,offset + limit 要小于等于4000
sortType String DESC or ASC

返回参数

参数 数据类型 说明
total number 数据总条数
dps Dp[] 见Dp
hasNext Boolean 是否有下一页

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
    .getLogUserAction({
    devId: TYSdk.devInfo.devId,
    dpIds: '20,21', // 多个DP
    offset: 1,
    limit: 3,
    sortType: 'ASC',
	})
  .then(response => {
  	console.log(response);
	})
  .catch();

返回示例

{
    "dps": [
        {
            "dpId": 20,
            "value": "false",
            "timeStamp": 1621392860,
            "timeStr": "2021-05-19 10:54:20"
        },
        {
            "dpId": 20,
            "value": "true",
            "timeStamp": 1621392861,
            "timeStr": "2021-05-19 10:54:21"
        },
        {
            "dpId": 20,
            "value": "false",
            "timeStamp": 1621393756,
            "timeStr": "2021-05-19 11:09:16"
        }
    ],
    "hasNext": true,
    "total": 15,
    "dpc": []
}

获取设备每日上报的数据统计

名称

getDpLogDays

描述

获取设备每日上报的数据统计。

请求参数

参数
数据类型
说明
是否必选
devId String 设备 ID
dpId String DP 点的 ID
type String 统计的类型,summinuxmax。请提交工单确保 API 统计类型和后台管理系统统计类型一致。
startDay String 开始日期
endDay String 结束日期

返回参数

参数 数据类型 说明
total string 总条数
values string 每天对应的值
days string 天的集合

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getDpLogDays({
  devId: 'vdevo161733425146241',
  dpId: '26',
  type: 'sum',
  startDay: '20210501',
  endDay: '20210530',
})
  .then(response => {
  console.log(response);
})
  .catch();

返回示例

{
    "total": "0.00",
    "values": [
        "0.00",
        "0.00"
    ],
    "days": [
        "05-18",
        "05-19"
    ]
}

按月(一年)获取 DP 点的统计结果

名称

getDpResultByMonth

描述

按月(一年)获取 DP 点的统计结果。

请求参数

参数 数据类型 说明 是否必填
devId String 设备 ID
dpId String DP 点的 ID
type String summinuxavgcount

type 为 count,表示上报数据的次数;
type 为 sum,表示上报数据的总和。

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getDpResultByMonth({
  devId: 'vdevo161733425146241',
  dpId: '26',
  type: 'sum',
})
  .then(response => {
  console.log(response);
})
  .catch();

返回示例

{
  "20180501": "4.00",
  "20180511": "805.00",
  "20180513": "213.00",
  "20180516": "822.00",
  "20180519": "119.00",
  "20180520": "165.00",
  "20180521": "164.00",
  "20180522": "142.00",
  "20180529": "140.00",
  "20180530": "116.00",
}

按小时获取 DP 点的统计结果

名称

getDpResultByHour

描述

按小时获取 DP 点的统计数据。

请求参数

参数
数据类型
说明
是否必选
devId String 设备 ID
dpId String DP 点的 ID
date String 日期,例如20170531
uid String 用户 ID
auto Integer auto=1 以及 auto=2 时,支持整刻时间上报的数据。
  • auto=1 :中间数据缺失时,使用上一时段的数据补充。
  • auto=2 :中间数据缺失时,使用#补充。
type String summinuxavg

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getDpResultByHour({
  devId: 'vdevo161733425146241',
  dpId: '26',
  date: '2018052910',
  auto: 1,
  type: 'sum',
  uid: '',
})
  .then(response => {
  console.log(response);
})
  .catch();

返回示例

{
  "2018052910": "4.00",
  "2018052911": "805.00",
  "2018052912": "11.00",
  "2018052913": "213.00",
  "2018052914": "417.00",
  "2018052915": "620.00",
  "2018052916": "822.00",
  "2018052917": "14.00",
  "2018052918": "94.00",
  "2018052919": "119.00",
  "2018052920": "165.00",
  "2018052921": "164.00",
  "2018052922": "142.00",
  "2018052923": "140.00",
  "2018053000": "116.00",
  "2018053001": "125.00",
  "2018053002": "116.00",
  "2018053003": "105.00",
  "2018053004": "104.00",
  "2018053005": "93.00",
  "2018053006": "96.00",
  "2018053007": "106.00",
  "2018053008": "120.00",
  "2018053009": "90.00",
  "2018053010": "105.00",
  "2018053011": "102.00",
  "2018053012": "109.00",
  "2018053013": "106.00",
  "2018053014": "164.00",
  "2018053015": "158.00",
  "2018053016": "206.00",
  "2018053017": "159.00"
}

获取指定天数范围内的数据

名称

getDataWithSpecified

描述

获取指定天数范围内的数据。

请求参数

参数
数据类型
说明
是否必选
devId String 设备 ID
dpId String DP 点的 ID
startDay String 开始日期
endDay String 结束日期
type String summinuxavg
uid String 用户 ID
| auto | Integer | `auto=1` 以及 `auto=2` 时,支持整刻时间上报的数据。
  • `auto=1 `:中间数据缺失时,使用上一时段的数据补充。
  • `auto=2` :中间数据缺失时,使用`#`补充。
| 否 |

返回参数

参数 数据类型 说明
result string 当天数据
min string 指定天数

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getDataWithSpecified({
  devId: 'vdevo161733425146241',
  dpId: '26',
  startDay: '20210510',
  endDay: '20210520',
  type: 'sum',
  uid: '',
})
  .then(response => {
  console.log(response);
})
  .catch();

返回示例

{
    "result": {
        "20210510": "0",
        "20210511": "0",
        "20210512": "0",
        "20210513": "0",
        "20210514": "0",
        "20210515": "0",
        "20210516": "0",
        "20210517": "0",
        "20210518": "0.00",
        "20210519": "0.00",
        "20210520": "0"
    },
    "min": "20210518"
}

获取指定周范围内的数据

说明:建议使用获取指定天数范围内的数据。

名称

getWeekWithSpecified

描述

获取指定周范围内的数据。

请求参数

参数 数据类型 说明 是否必填
devId String 设备 ID
dpId String DP 点的 ID
startWeek String 开始周
endWeek String 结束周
type String sum

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getWeekWithSpecified({
  devId: 'vdevo161733425146241',
  dpId: '26',
  startWeek: '202101',
  endWeek: '202105',
  type: 'sum',
})
  .then(response => {
  console.log(response);
})
  .catch();

返回示例

{
    "result": {
        "202101": "0",
        "202102": "0",
        "202103": "0",
        "202104": "0",
        "202105": "0"
    },
    "min": "202121"
}

获取指定月范围内的数据

名称

getMonthWithSpecified

描述

获取指定月范围内的数据。

请求参数

参数
数据类型
说明
是否必选
devId String 设备 ID
dpId String DP 点的 ID
type String summinuxavg
startMonth String 开始月
endMonth String 结束月
uid String 用户 ID
| auto | Integer | `auto=1` 以及 `auto=2` 时,支持整刻时间上报的数据。
  • `auto=1 `:中间数据缺失时,使用上一时段的数据补充。
  • `auto=2` :中间数据缺失时,使用`#`补充。
| 否 |

请求示例

import { commonApi } from '@tuya/tuya-panel-api';

commonApi.statApi
  .getMonthWithSpecified({
  devId: 'vdevo161733425146241',
  dpId: '26',
  startMonth: '202104',
  endMonth: '202105',
  type: 'sum',
})
  .then(response => {
  console.log(response);
})
  .catch();

返回示例

{
  "20210403":"0",
  "20210404":"0",
  "20210411":"0",
  "20210416":"0",
  "20210417":"0",
  "20210428":"0",
  "20210429":"0",
}