---
name: "getStatisticsConfig"
mode: "api"
versionRequirements:
  - { name: "@tuya-miniapp/cloud-api", version: "1.0.5" }
title: "getStatisticsConfig - 获取统计配置，获取开通智能计量的 dp 点及配置。"
---

## getStatisticsConfig

> [VERSION] @tuya-miniapp/cloud-api >= 1.0.5

> 💡 该接口为云能力，需开通授权后使用，关于云能力可[查看文档](/cn/miniapp/common/desc/tech-stack/api)。
> 注意：目前云能力在「开发者工具」环境无法使用，需要打包后或真机调试使用。

### 描述

获取统计配置，获取开通智能计量的 DP 点及配置。

### 参数

`Params`

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `data` | `IDevId` | 是 | 请求体 |

### 返回值

类型: `Promise<IStatisticsConfig[]>`

IStatisticsConfig[]（字段含义见类型定义与 minituya 返回值表）

### 引用对象

##### `type` IDevId

仅含设备 ID 的请求体（如 `getStatisticsConfig`、`resetStatistics`）。

| 属性 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `devId` | `string` | 是 | 设备 ID |

##### `interface` IStatisticsConfig

`getStatisticsConfig` 单条配置；与 minituya 返回值表及 `index` 中返回示例字段一致。

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `algorithmType` | `"sum" \| "avg" \| "minux" \| "max" \| "min" \| "count" \| "recent"` | 统计类型 统计聚合算法，与 minituya「统计类型说明」一致。 - `sum`：时段内上报值累加，适用于累计量。 - `minux`：本时段最大值减去上一时段最大值，表示增量/用量（历史拼写，非 `minus`）。 - `avg`：累加后除以上报次数，得平均值。 - `min` / `max`：时段内最小值 / 最大值。 - `count`：时段内上报次数。 - `recent`：最近一次统计值。 |
| `dpId` | `number \| string` | 已开通统计的 DP ID |
| `productId` | `string` | 产品 ID |
| `statisticInterval` | `number` | 统计间隔（与云端枚举一致）：`1` 天、`2` 小时、`4` 月、`16` 表示 15 分钟粒度。 |
| `storageDuration` | `number` | 该类统计数据在云端保留的天数 |


### 合法值

##### `IStatisticsConfig.algorithmType`

| 值 | 说明 | 最低版本 |
| --- | --- | --- |
| `sum` | - | - |
| `avg` | - | - |
| `minux` | - | - |
| `max` | - | - |
| `min` | - | - |
| `count` | - | - |
| `recent` | - | - |


### 示例代码

#### 请求示例

```typescript
import { getStatisticsConfig } from '@tuya-miniapp/cloud-api';

getStatisticsConfig({
  devId: 'vdevo166789063330437',
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### 返回示例

```json
[
  {
    "storageDuration": 365,
    "productId": "lcrxzqjqojafatrv",
    "dpId": 18,
    "statisticInterval": 1,
    "algorithmType": "avg"
  },
  {
    "storageDuration": 365,
    "productId": "lcrxzqjqojafatrv",
    "dpId": 1,
    "statisticInterval": 1,
    "algorithmType": "count"
  },
  {
    "storageDuration": 7,
    "productId": "lcrxzqjqojafatrv",
    "dpId": 1,
    "statisticInterval": 2,
    "algorithmType": "count"
  }
]
```
