I get empty Aggregated Heart Rate Data from Google Fitness Api.

I get empty Aggregated Heart Rate Data from Google Fitness Api.

Hey guys, I am writing my thesis and I have this task to get aggregated Heart Rate data from my Google Fit Account and print them. My code works if I want to print heart rate data from an hour during the day. But I cannot for the love of god print the values of the aggregated heart rate for each day of the week. I am a novice as far as the Google Fit Api is concerned so bare with me. I will post my builder and data dumper. If you need any more code lmk.

Builder Function:

private fun queryFitnessData2(): DataReadRequest { val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")) val now = Date() calendar.time = now val endTime = calendar.timeInMillis calendar.add(Calendar.WEEK_OF_YEAR, -1) val startTime = calendar.timeInMillis Log.i(TAG, "Range Start: ${dateFormat.format(startTime)}") Log.i(TAG, "Range End: ${dateFormat.format(endTime)}") return DataReadRequest.Builder() .enableServerQueries() .bucketByTime(1, TimeUnit.DAYS) .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS) .aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY) .build(); }

Data Printer:

private fun printData(dataReadResult: DataReadResponse) { // [START parse_read_data_result] // If the DataReadRequest object specified aggregated data, dataReadResult will be returned // as buckets containing DataSets, instead of just DataSets. if (dataReadResult.buckets.isNotEmpty()) { Log.i(TAG, "Number of returned buckets of DataSets is: " + dataReadResult.buckets.size) for (bucket in dataReadResult.buckets) { val dataSets = bucket.dataSets bucket.dataSets.forEach { dumpDataSet(it) } } } else if (dataReadResult.dataSets.isNotEmpty()) { Log.i(TAG, "Number of returned DataSets is: " + dataReadResult.dataSets.size) dataReadResult.dataSets.forEach { dumpDataSet(it) } } // [END parse_read_data_result] }

Dataset Parser Function:

// [START parse_dataset] private fun dumpDataSet(dataSet: DataSet) { Log.i(TAG, "Data returned for Data type: ${dataSet.dataType.name}") val dateFormat: DateFormat = getTimeInstance() //INTERESTING PART dataSet.dataType.fields.forEach { Log.i(TAG, "tField: ${it.name} Value:${dataSet.dataPoints.getValue(it)}") } } // [END parse_dataset]

In the interesting part section, I can log the Min, Max, Average sections but I fail to get the values from those fields. Any help would be greatly appreciated.

submitted by /u/Ntdark
[link] [comments]