Last Updated on : 2025-11-24 07:28:53download
A specialized statistics API suite is designed for chart data visualization, providing device data statistics interfaces across four different time granularities to help you quickly implement:
To utilize the statistics capabilities, you must first submit a ticket to subscribe to the product data statistics service.
| Interface | Time granularity | Typical use case | Data points |
|---|---|---|---|
| get15MinData | 15 minutes | Real-time monitoring, detailed analytics | 96 points/day |
| getHourData | Hourly | Intra-day trends, hourly comparison | 24 points/day |
| getDayData | Daily | Weekly/Monthly reports | Custom range |
| getMonthData | Monthly | Annual reports, long-term trends | Custom range |
| Statistical type | Enum value | Description | Scenario |
|---|---|---|---|
| SUM | sum | Summation | Total energy consumption, usage statistics |
| MAX | max | Maximum value | Peak analytics, maximum temperature |
| MIN | min | Minimum value | Valley analytics, minimum temperature |
| AVG | avg | Average value | Average power, average temperature |
| MINUX | minux | Differential value | Increment calculation |
| COUNT | count | Count | Switch cycles, trigger events |
| RECENT | recent | Most recent value | Real-time status (hourly only) |
// Use sum for energy consumption statistics
type = StatType.SUM.value
// Use avg for temperature analytics
type = StatType.AVG.value
// Use max for peak power analytics
type = StatType.MAX.value
Get device data statistics at 15-minute intervals within a single day, suitable for real-time monitoring charts and detailed data analytics.
YYYYMMDDhhmm. For example, 202411130000 and 202411130015.fun get15MinData(
devId: String, // Device ID
dpId: String, // Data point ID (integer)
date: String, // Date: YYYYMMDD
type: String = "sum", // Statistical type (default: sum)
auto: Int = 0, // Data imputation strategy
keepScalaPoint: Boolean = false, // Retain decimal points
callback: IThingDataCallback<String?> )
| Parameter | Type | Required | Default value | Description |
|---|---|---|---|---|
| devId | String | Yes | - | The device ID obtained from the device object. |
| dpId | String | Yes | - | The ID of the specified data point. |
| date | String | Yes | - | The query date in a format like 20241113. |
| type | String | No | sum | The statistical type. It is recommended to use StatType enum. |
| auto | Int | No | 0 |
|
| keepScalaPoint | Boolean | No | false | Specifies whether to retain decimal points. |
| callback | IThingDataCallback | Yes | - | The callback interface. |
Scenario: Draw a line chart of today’s electricity consumption at a 15-minute interval.
// Kotlin example
class PowerConsumptionChart : Fragment() {
private fun loadChartData() {
val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault())
.format(Date())
ThingSmartBusinessRequest.get15MinData(
devId = deviceId,
dpId = 101, // Assume 101 is the power consumption DP
date = today,
type = StatType.SUM.value, // Using enum is safer
auto = 0, // Fill with 0 for missing data
keepScalaPoint = true, // Retain decimal places
callback = object : IThingDataCallback<String?> {
override fun onSuccess(result: String?) {
parseAndDrawChart(result)
}
override fun onError(errorCode: String?, errorMessage: String?) {
showError("Loading failed: $errorMessage")
}
}
)
}
private fun parseAndDrawChart(json: String?) {
try {
val data = JSONObject(json)
val result = data.getJSONObject("result")
// Parse data points
val entries = mutableListOf<Entry>()
result.keys().forEach { timeKey ->
val value = result.getString(timeKey).toFloat()
entries.add(Entry(timeKey, value))
}
// Draw chart (using libraries like MPAndroidChart)
drawLineChart(entries)
} catch (e: Exception) {
Log.e(TAG, "Data parsing failed", e)
}
}
}
{
"result": {
"202411130000": "12.34",
"202411130015": "11.89",
"202411130030": "13.45",
"202411130045": "12.01",
"202411130100": "14.23",
"202411130115": "13.67",
...
"202411132345": "10.12"
},
"t": 1699862400000,
"success": true,
"status": "ok"
}
YYYYMMDDhhmm)Get device data statistics aggregated by hour within a single day. This is the most commonly used chart data interface.
YYYYMMDDhh. For example, 2024111300 and 2024111301.fun getHourData(
devId: String, // Device ID
dpId: String, // Data point ID
date: String, // Date: YYYYMMDD
auto: Int = 0, // Data imputation strategy
type: String = "sum", // Statistical type
keepScalaPoint: Boolean = false,
callback: IThingDataCallback<String?>
)
Scenario: Draw today’s 24-hour temperature curve.
class TemperatureChart : Fragment() {
private fun load24HourTemperature() {
ThingSmartBusinessRequest.getHourData(
devId = deviceId,
dpId = "102",
date = "20241113",
type = StatType.AVG.value, // Use the average temperature value
auto = 1, // Fill the gaps with the previous value
callback = object : IThingDataCallback<String?> {
override fun onSuccess(result: String?) {
drawTemperatureChart(result)
}
override fun onError(errorCode: String?, errorMessage: String?) {
Toast.makeText(context, "Loading failed", Toast.LENGTH_SHORT).show()
}
}
)
}
}
{
"result": {
"2024111300": "22.5",
"2024111301": "22.3",
"2024111302": "22.1",
...
"2024111323": "21.8"
},
"t": 1699862400000,
"success": true,
"status": "ok"
}
Get device data statistics aggregated by day within a specified date range, suitable for weekly and monthly reports.
YYYYMMDD. For example, 20241101 and 20241102.fun getDayData(
devId: String,
dpId: String,
type: String = "sum",
startDay: String, // Start date: YYYYMMDD
endDay: String, // End date: YYYYMMDD
auto: Int? = null,
keepScalaPoint: Boolean = false,
callback: IThingDataCallback<String?>
)
Scenario: Draw a bar chart of this week’s 7-day electricity consumption.
class WeeklyConsumption : Fragment() {
private fun loadWeeklyData() {
val calendar = Calendar.getInstance()
val endDay = SimpleDateFormat("yyyyMMdd").format(calendar.time)
calendar.add(Calendar.DAY_OF_YEAR, -6)
val startDay = SimpleDateFormat("yyyyMMdd").format(calendar.time)
ThingSmartBusinessRequest.getDayData(
devId = deviceId,
dpId = 101,
type = StatType.SUM.value,
startDay = startDay, // 7 days ago
endDay = endDay, // Today
auto = 0,
callback = object : IThingDataCallback<String?> {
override fun onSuccess(result: String?) {
drawWeeklyBarChart(result)
}
override fun onError(errorCode: String?, errorMessage: String?) {
Log.e(TAG, "Failed to load weekly data: $errorMessage")
}
}
)
}
}
{
"result": {
"result": {
"20241107": "45.67",
"20241108": "52.34",
"20241109": "48.90",
"20241110": "51.23",
"20241111": "49.56",
"20241112": "53.78",
"20241113": "47.89"
},
"min": "20241113"
},
"t": 1699862400000,
"success": true,
"status": "ok"
}
Get device data statistics aggregated by month within a specified month range, suitable for annual reports and long-term trend analytics.
YYYYMM. For example, 202401 and 202402.fun getMonthData(
devId: String,
dpId: String,
type: String = "sum",
startMonth: String, // Start month: YYYYMM
endMonth: String, // End month: YYYYMM
auto: Int? = null,
keepScalaPoint: Boolean = false,
callback: IThingDataCallback<String?>
)
Scenario: Draw a comparison chart of this year’s 12-month electricity consumption.
class YearlyConsumption : Fragment() {
private fun loadYearlyData() {
val currentYear = Calendar.getInstance().get(Calendar.YEAR)
ThingSmartBusinessRequest.getMonthData(
devId = deviceId,
dpId = 101,
type = StatType.SUM.value,
startMonth = "${currentYear}01", // January
endMonth = "${currentYear}12", // December
callback = object : IThingDataCallback<String?> {
override fun onSuccess(result: String?) {
drawYearlyChart(result)
}
override fun onError(errorCode: String?, errorMessage: String?) {
showError("Failed to load annual data")
}
}
)
}
}
{
"result": {
"result": {
"202401": "1234.56",
"202402": "1156.78",
"202403": "1289.90",
"202404": "1345.67",
"202405": "1298.45",
"202406": "1423.89",
"202407": "1567.23",
"202408": "1489.01",
"202409": "1376.54",
"202410": "1298.76",
"202411": "1234.00",
"202412": "0"
},
"min": "202412"
},
"t": 1699862400000,
"success": true,
"status": "ok"
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback