该请求应该向 Google Fit 查询过去 3 个月的汇总心率数据,按 1 天时间段分组。然而,我得到的是三个数据点,包括一天(5 月 29 日)的两个数据点。预期结果总共是两个数据点:一个是 5 月 25 日,一个是 5 月 29 日。这是什么原因,我该如何解决这个问题?
这是代码:
DateTime now = new DateTime();
DateTime start = now.minusMonths(3);
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.enableServerQueries()
.setTimeRange(start.getMillis(), now.getMillis(), TimeUnit.MILLISECONDS)
.build();
Fitness.HistoryApi.readData(googleApiClient, readRequest)
.setResultCallback(new ResultCallback<DataReadResult>() {
@Override public void onResult(@NonNull DataReadResult dataReadResult) {
ArrayList<DataPoint> dataPoints = new ArrayList<>();
for (Bucket bucket : dataReadResult.getBuckets()) {
List<DataSet> dataSets = bucket.getDataSets();
for (DataSet dataSet : dataSets) {
Timber.d("dataSet.dataType: %s", dataSet.getDataType().getName());
for (DataPoint dp : dataSet.getDataPoints()) {
dataPoints.add(dp);
Timber.d("Data point:");
Timber.d("Type: %s", dp.getDataType().getName());
Timber.d("Time: %s",
new DateTime(dp.getTimestamp(TimeUnit.MILLISECONDS)).toString());
for (Field field : dp.getDataType().getFields()) {
Timber.d("Field: %s. Value: %s", field.getName(), dp.getValue(field));
}
}
}
}
//...
}
});
这是输出:
05-30 19:34:05.516 13518-13518/com.test D/TestFragment$1$override: Data point:
05-30 19:34:05.516 13518-13518/com.test D/TestFragment$1$override: Type: com.google.heart_rate.summary
05-30 19:34:05.516 13518-13518/com.test D/TestFragment$1$override: Time: 2016-05-25T22:22:58.526+02:00
05-30 19:34:05.517 13518-13518/com.test D/TestFragment$1$override: Field: average. Value: 65.0
05-30 19:34:05.517 13518-13518/com.test D/TestFragment$1$override: Field: max. Value: 65.0
05-30 19:34:05.517 13518-13518/com.test D/TestFragment$1$override: Field: min. Value: 65.0
05-30 19:34:05.517 13518-13518/com.test D/TestFragment$1$override: Data point:
05-30 19:34:05.518 13518-13518/com.test D/TestFragment$1$override: Type: com.google.heart_rate.summary
05-30 19:34:05.518 13518-13518/com.test D/TestFragment$1$override: Time: 2016-05-29T20:33:37.170+02:00
05-30 19:34:05.519 13518-13518/com.test D/TestFragment$1$override: Field: average. Value: 90.80258
05-30 19:34:05.519 13518-13518/com.test D/TestFragment$1$override: Field: max. Value: 164.0
05-30 19:34:05.519 13518-13518/com.test D/TestFragment$1$override: Field: min. Value: 55.0
05-30 19:34:05.519 13518-13518/com.test D/TestFragment$1$override: Data point:
05-30 19:34:05.520 13518-13518/com.test D/TestFragment$1$override: Type: com.google.heart_rate.summary
05-30 19:34:05.520 13518-13518/com.test D/TestFragment$1$override: Time: 2016-05-29T20:48:37.321+02:00
05-30 19:34:05.520 13518-13518/com.test D/TestFragment$1$override: Field: average. Value: 86.78551
05-30 19:34:05.521 13518-13518/com.test D/TestFragment$1$override: Field: max. Value: 106.0
05-30 19:34:05.521 13518-13518/com.test D/TestFragment$1$override: Field: min. Value: 78.0