# Statistics

> This interface is a cloud capability and requires authorization before use. For more information about cloud capabilities, please [refer to the documentation](/en/miniapp/common/desc/tech-stack/api) <br/>_**<font color="red">Currently, cloud capabilities cannot be used in the `Developer Tools` environment. They need to be packaged or debugged on real devices.</font>**_

> _**<font color="red">📢Note: To use statistical capabilities, you need to submit a work order to enable product data statistics. Please [submit a quick work order](https://service.console.tuya.com/8/3/list?source=support_center) before use.</font>**_

<Image src="/images/api/cloud/cloud_support.en.jpg" style={{width: 400}} />

## Interface Capabilities

For smart metering capabilities, we provide the following interface capabilities, which developers can directly call using the API to complete related business development.

**Note that the following APIs require the use of `MiniApp Basic Library >=2.18.1`.**

| Interface Name         | Description                                                                                       |
| ---------------------- | ------------------------------------------------------------------------------------------------- |
| getStatisticsConfig    | Get the configuration information for statistical data                                            |
| getStatisticsRang15min | Get the statistics data for the device in the specified period with a time interval of 15 minutes |
| getStatisticsRangHour  | Get the statistics data for the device in the specified period with a time interval of 1 hour     |
| exportStatisticsHour   | Export the statistics data for the device in the specified period with a time interval of 1 hour  |
| getStatisticsRangDay   | Get the statistics data for the device in the specified period with a time interval of 1 day      |
| exportStatisticsDay    | Export the statistics data for the device in the specified period with a time interval of 1 day   |
| getStatisticsRangMonth | Get the statistics data for the device in the specified period with a time interval of 1 month    |
| exportStatisticsMonth  | Export the statistics data for the device for the past month                                      |
| resetStatistics        | Reset the statistics data for the device                                                          |

## Explanation of the "type" Parameter in Statistical Interfaces for Chart-related Requirements

### Statistics Type Reference

> The time interval below is currently written as `1 hour`, but it can be replaced with `1 day` or `1 month`, which are supported.

#### sum

Sum the data reported within `1 hour` to get the **total** for that period. Use for cumulative values (e.g., energy consumption, water usage).

#### minux

Take the **maximum** value of data reported within `1 hour`, subtract the **maximum** of data reported in the **previous hour**, to get the **delta/usage** for this period. Use for meter/counter-style period usage (e.g., electricity or water usage per period).

- Tip: If there is no data for the `previous hour`, subtract the maximum reported data before that to obtain the data used for `this hour`.
- Tip: This type should have been named "minus," but due to a spelling mistake made initially (three years ago), it has been consistently used as `minux`.

#### avg

Sum the data reported within `1 hour`, then divide by the **number of reports** to get the **average** for that hour. Use for metrics where you need the average level (e.g., temperature, humidity).

#### min

The minimum value of data reported within `1 hour`. Use for lowest temperature, lowest power, valley power, etc.

#### max

The maximum value of data reported within `1 hour`. Use for peak temperature, peak power, peak load, etc.

#### count

The number of data reports within `1 hour`. Use for switch count, report frequency, event count, etc.

#### recent

The data point closest to the **hour boundary**. This type only supports hourly statistics, not daily or monthly. Use for charts that need one sample per hour aligned to the hour (e.g., line chart with one point per hour).

### Statistical Interval

#### Statistical by Hour

Simply put, it is to statistically analyze the data reported within `1 hour` based on the `statistical type` and then aggregate it into one point.

#### Statistical by Day

Simply put, it is to statistically analyze the data reported within `1 day` based on the `statistical type` and then aggregate it into one point.

#### Statistical by Month

Simply put, it is to statistically analyze the data reported within the month based on the `statistical type` and then aggregate it into one point.
