Data Statistics

Last Updated on : 2023-11-06 09:41:51download

This topic describes APIs related to statistical data.

Note:
1.You need to submit a service ticket with the product-associated account to add the target product to the statistical category of the background management system. To use statistic APIs, your service ticket must include the product ID (PID) and the data point (DP) ID that requires statistic functions.
2.To use commonApi, you need to install dependencies first, click here to install dependencies.
3.Log interfaces do not need to enable the statistics function.

Get DP logs for a specified time period

Name

getLogInSpecifiedTime

Description

Get logs of DP status for a specified time period.

Request parameter

Parameter Data type Description Required
devId String The device ID. Yes
dpIds String The DP ID. Multiple DP IDs are separated by a comma (,). Yes
offset Integer The query results are returned from the one after the specified sequence. Yes
limit Integer The maximum number of results on a single page. The sum of offset and limit must be less than or equal to 4,000. Yes
startTime String The time when DP status reporting starts, in milliseconds. No
endTime String The time when DP status reporting ends, in milliseconds. No
sortType String The results are sorted in descending or ascending order. No

Return parameter

Parameter Data type Description
total number The total number of results.
dps DP[] See the DP table below.
hasNext Boolean Whether there is a next page of results.

DP

Parameter Data type Description
timeStamp number The timestamp format of the reported data.
dpId string The DP ID.
timeStr string The date and time converted to the local timezone, in the format yyyy-MM-dd HH:mm:ss.
value string The DP value.

Sample request

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

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

Sample response

{
    "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": []
}

Get DP logs

Name

getDpReportLog

Description

Get logs of DP status.

Request parameter

Parameter Data type Description Required
devId String The device ID. Yes
dpIds String The DP ID. Multiple DP IDs are separated by a comma (,). Yes
offset Integer The query results are returned from the one after the specified sequence. Yes
limit Integer The maximum number of results on a single page. The sum of offset and limit must be less than or equal to 4,000. Yes
sortType String The results are sorted in descending or ascending order. No

Return parameter

Parameter Data type Description
total number The total number of results.
dps DP[] See the DP table below.
hasNext Boolean Whether there is a next page of results.

Sample request

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

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

Sample response

{
    "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": []
}

Get DP logs of user actions

Name

getLogUserAction

Description

Get DP logs of user actions.

Request parameter

Parameter Data type Description Required
devId String The device ID. Yes
dpIds String The DP ID. Multiple DP IDs are separated by a comma (,). Yes
offset Integer The query results are returned from the one after the specified sequence. Yes
limit Integer The maximum number of results on a single page. The sum of offset and limit must be less than or equal to 4,000. Yes
sortType String The results are sorted in descending or ascending order. No

Return parameter

Parameter Data type Description
total number The total number of results.
dps DP[] See the DP table below.
hasNext Boolean Whether there is a next page of results.

Sample request

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

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

Sample response

{
    "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": []
}

Get statistics of daily reported data

Name

getDpLogDays

Description

Get statistics of daily reported data.

Request parameter

Parameter
Data type
Description
Required
devId String The device ID. Yes
dpId String The DP ID. Yes
type String The statistic metrics can be sum, minux, or max. Submit a service ticket to confirm that the API statistic metrics are consistent with those registered in the background management system. No
startDay String The start date. Yes
endDay String The end date. Yes

Return parameter

Parameter Data type Description
total string The total number of results.
values string The statistical values of a specified day.
days string The collection of days.

Sample request

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();

Sample response

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

Get yearly DP statistics by month

Name

getDpResultByMonth

Description

Get yearly DP statistics by month.

Request parameter

Parameter Data type Description Required
devId String The device ID. Yes
dpId String The DP ID. Yes
type String The statistic metrics can be sum, minux, avg or count. Yes

Sample request

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

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

Sample response

{
  "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",
}

Get DP statistics by hour

Name

getDpResultByHour

Description

Get DP statistics by hour.

Request parameter

Parameter
Data type
Description
Required
devId String The device ID. Yes
dpId String The DP ID. Yes
date String The date, such as 20170531. Yes
uid String The user ID. No
auto Integer When auto = 1 or auto = 2, the data reported on the hour is supported.
  • auto = 1: If the intermediate data is lost, data of the previous time period will be added.
  • auto = 2: If the intermediate data is lost, # will be added.
No
type String The statistic metrics can be sum, minux, or avg. No

Sample request

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);
  console.log(JSON.stringify(response));
})
  .catch();

Sample response

{
  "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"
}

Get data within specified days

Name

getDataWithSpecified

Description

Get data within specified days.

Request parameter

Parameter
Data type
Description
Required
devId String The device ID. Yes
dpId String The DP ID. Yes
startDay String The start date. Yes
endDay String The end date. Yes
type String The statistic metrics can be sum, minux, or avg. No
uid String The user ID. No
| auto | Integer | When `auto = 1` or `auto = 2`, the data reported on the hour is supported.
  • `auto = 1`: If the intermediate data is lost, data of the previous time period will be added.
  • `auto = 2`: If the intermediate data is lost, `#` will be added.
| No |

Return parameter

Parameter Data type Description
result string Data of the current day.
min string The specified days.

Sample request

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();

Sample response

{
    "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"
}

Get data within specified weeks

Note: We recommend that you get data within specified days.

Name

getWeekWithSpecified

Description

Get data within specified weeks.

Request parameter

Parameter Data type Description Required
devId String The device ID. Yes
dpId String The DP ID. Yes
startWeek String The start week. Yes
endWeek String The end week. Yes
type String sum Yes

Sample request

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();

Sample response

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

Get data within specified months

Name

getMonthWithSpecified

Description

Get data within specified months.

Request parameter

Parameter
Data type
Description
Required
devId String The device ID. Yes
dpId String The DP ID. Yes
type String The statistic metrics can be sum, minux, or avg. Yes
startMonth String The start month. Yes
endMonth String The end month. Yes
uid String The user ID. No
| auto | Integer | When `auto = 1` or `auto = 2`, the data reported on the hour is supported.
  • `auto = 1`: If the intermediate data is lost, data of the previous time period will be added.
  • `auto = 2`: If the intermediate data is lost, `#` will be added.
| No |

Sample request

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();

Sample response

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