如何从Google健身历史中获取心率值? [英] How to get Heart Rate values from Google Fit History?

查看:362
本文介绍了如何从Google健身历史中获取心率值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到所有的心率测量值,而不是最小值,最大值和平均值,这正是我所能得到的。

这是



谢谢!

  private void readDataFitnessHistory()
{
//使用此刻之前1周的范围设置开始日期和结束日期。
日历cal = Calendar.getInstance();
现在的日期= new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();

cal.add(Calendar.WEEK_OF_YEAR,-1);
long startTime = cal.getTimeInMillis();

java.text.DateFormat dateFormat = getDateInstance();
Log.d(TAG,Range Start:+ dateFormat.format(startTime));
Log.d(TAG,Range End:+ dateFormat.format(endTime));

DataReadRequest readRequest = new DataReadRequest.Builder()
//数据请求可以指定多个数据类型返回,有效
//将多个数据查询合并为一个调用。
//在这个例子中,请求几乎不可能是数百个
//数据点,每个数据点都由几个步骤和一个时间戳组成。更可能的
//场景是想要查看7天内每天走多少步。
.aggregate(DataType.TYPE_HEART_RATE_BPM,DataType.AGGREGATE_HEART_RATE_SUMMARY)
//类似于SQL中的分组依据,定义了数据如何汇总。
// bucketByTime允许一个时间跨度,而bucketBySession允许
//通过会话分段,这需要在代码中定义。
.bucketByTime(1,TimeUnit.DAYS)
.enableServerQueries()
.setTimeRange(startTime,endTime,TimeUnit.MILLISECONDS)
.build();

//调用History API以查询数据并等待
//读取请求的结果。
DataReadResult dataReadResult =
Fitness.HistoryApi.readData(mApiClient,readRequest).await(1,TimeUnit.MINUTES);
DataSet dataSet = dataReadResult.getDataSet(DataType.TYPE_HEART_RATE_BPM);
showDataSet(dataSet);
displayBpmDataForToday();


}

回应:

 历史记录:类型:com.google.heart_rate.summary 
历史记录:开始日期:22 sept。 2017 10:40:06
D / DBGPRUEBA历史:结束:22 sept。 2017 10:40:06
D / DBGPRUEBA历史:领域:平均值:71.13179
D / DBGPRUEBA历史:领域:最大值:86.0
D / DBGPRUEBA历史:领域:最小值: 55.0


解决方案

我正在回答我自己的问题。



为了获得使用Google Fit API制作的所有数据点,要构建的对象DataRsult如下所示:

  final DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_STEP_COUNT_DELTA)
.read(DataType.TYPE_HEART_RATE_BPM)
。 enableServerQueries()
.setTimeRange(startTime,endTime,TimeUnit.MILLISECONDS)
.build();

它将返回指定范围内的所有数据点。


I need to get all the heart rate measurements, and not the minimum, maximum and average, which is what I have been able to get.

This is the code I use for reading from my java class.

Thank you!

private void readDataFitnessHistory()
{
    // Setting a start and end date using a range of 1 week before this moment.
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();

    cal.add(Calendar.WEEK_OF_YEAR, -1);
    long startTime = cal.getTimeInMillis();

    java.text.DateFormat dateFormat = getDateInstance();
    Log.d(TAG, "Range Start: " + dateFormat.format(startTime));
    Log.d(TAG, "Range End: " + dateFormat.format(endTime));

    DataReadRequest readRequest = new DataReadRequest.Builder()
            // The data request can specify multiple data types to return, effectively
            // combining multiple data queries into one call.
            // In this example, it's very unlikely that the request is for several hundred
            // datapoints each consisting of a few steps and a timestamp.  The more likely
            // scenario is wanting to see how many steps were walked per day, for 7 days.
            .aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY)
            // Analogous to a "Group By" in SQL, defines how data should be aggregated.
            // bucketByTime allows for a time span, whereas bucketBySession would allow
            // bucketing by "sessions", which would need to be defined in code.
            .bucketByTime(1, TimeUnit.DAYS)
            .enableServerQueries()
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();

    // Invoke the History API to fetch the data with the query and await the result of
    // the read request.
    DataReadResult dataReadResult =
            Fitness.HistoryApi.readData(mApiClient, readRequest).await(1, TimeUnit.MINUTES);
    DataSet dataSet = dataReadResult.getDataSet(DataType.TYPE_HEART_RATE_BPM);
    showDataSet(dataSet);
    displayBpmDataForToday();


}

The response:

History:    Type: com.google.heart_rate.summary
History:    Start: 22 sept. 2017 10:40:06
D/DBGPRUEBA History:    End: 22 sept. 2017 10:40:06
D/DBGPRUEBA History:    Field: average Value: 71.13179
D/DBGPRUEBA History:    Field: max Value: 86.0
D/DBGPRUEBA History:    Field: min Value: 55.0

解决方案

I'm answering my own question.

In order to obtain all the datapoints of the readings made with Google Fit Api, the object DataRsult to build would be as follows:

final DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_STEP_COUNT_DELTA)
.read(DataType.TYPE_HEART_RATE_BPM)
.enableServerQueries()
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();

It would return all datapoints within the specified range.

这篇关于如何从Google健身历史中获取心率值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆