---
name: "getPetBehaviorStatistics"
mode: "api"
versionRequirements:
  - { name: "@ray-js/ray", version: "1.6.27" }
title: "getPetBehaviorStatistics - 获取宠物行为指标统计"
---

## getPetBehaviorStatistics

> [VERSION] @ray-js/ray >= 1.6.27

### 描述

获取宠物行为指标统计

### 参数

`Params`

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `data` | `GetPetBehaviorStatistics` | 是 | 请求参数：可选设备、宠物、日期范围；dateType、timeAggrType、indicatorCode 等聚合条件 |

### 返回值

类型: `Promise<PetBehaviorStatistics>`

Promise，resolve 值为统计项（datetime、value）

##### PetBehaviorStatistics

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `datetime` | `string` | 统计日期 |
| `value` | `number` | 指标值 |

### 引用对象

##### `type` GetPetBehaviorStatistics

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `devId` | `string` | 设备id（按设备的uuid查询） |
| `petId` | `number` | 宠物id |
| `beginDate` | `string` | 查询开始时间，如'2025072500' |
| `endDate` | `string` | 查询结束时间，如'2025072523' |
| `dateType` | `string` | 聚合时间，小时-hour，日-day，月-week |
| `timeAggrType` | `string` | 聚合类型，和-SUM，平均-AVG，次数-NUM |
| `indicatorCode` | `string` | 指标，如厕-defecation |


### 示例代码

#### 请求示例

```typescript
import { getPetBehaviorStatistics } from '@ray-js/ray';

getPetBehaviorStatistics({
  devId: 'vdevo******',
  petId: 1,
  beginDate: '2025072500',
  endDate: '2025072523',
  dateType: 'hour',
  timeAggrType: 'NUM',
  indicatorCode: 'defecation',
})
  .then((res) => {
    console.log(res);
  })
  .catch(console.error);
```

#### 返回示例

```json
{
  "datetime": "2025072500",
  "value": 3
}
```
