gpt4 book ai didi

android - 营养数据谷歌适合

转载 作者:行者123 更新时间:2023-11-30 01:41:48 25 4
gpt4 key购买 nike

读取营养数据有延迟吗?我插入了营养数据并试图读取它们,但数据点的大小仍然等于 0...

我这样插入数据:

long now = System.currentTimeMillis();

DataSource nutritionSource = new DataSource.Builder()
.setAppPackageName(getApplicationContext().getPackageName())
.setType(DataSource.TYPE_RAW)
.setDataType(DataType.TYPE_NUTRITION)
.build();

DataSet dataSet = DataSet.create(nutritionSource);

DataPoint dataPoint = DataPoint.create(nutritionSource);
dataPoint.setTimestamp(now, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_FOOD_ITEM).setString(name_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_CALORIES, calorie_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_SUGAR,sugar_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_TOTAL_FAT,fat_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_PROTEIN,protein_food);
dataPoint.getValue(Field.FIELD_MEAL_TYPE).setInt(Field.MEAL_TYPE_UNKNOWN);


dataSet.add(dataPoint);

然后,我试着像这样阅读它们:

DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_NUTRITION, DataType.AGGREGATE_NUTRITION_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.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(mClient, readRequest).await(1, TimeUnit.MINUTES);

if(dataReadResult.getStatus().isSuccess()){
Log.i("TAG","isSuccess to read nutrition data");
if(dataReadResult.getDataSet(DataType.TYPE_NUTRITION).getDataPoints().size() > 0){
Log.i("TAG","calorie : "+dataReadResult.getDataSet(DataType.TYPE_NUTRITION).getDataPoints().get(0).getValue(Field.FIELD_CALORIES));
}
}

我想获取当天的所有数据点并使用它们,但我不知道如何做??

谢谢,

Camel

最佳答案

不确定这对您来说是否仍然是个问题,但尝试使用它来获取聚合数据的每个“桶”。

        List<Bucket> buckets = dataReadResult.getBuckets();
for (int a = buckets.size() - 1; a > -1; a--) {
Bucket bucket = buckets.get(a);
for (DataSet dataSet : bucket.getDataSets()) {
if(dataSet.getDataType().getName().equals(DataType.TYPE_NUTRITION.getName())){
for (DataPoint dp : dataSet.getDataPoints()) {
Log.i(TAG, "Data point:");
Log.i(TAG, "\tType: " + dp.getDataType().getName());
for(Field field : dp.getDataType().getFields()) {
Log.i(TAG, "\tField: " + field.getName() +
" Value: " + dp.getValue(field));
}
}
}
}
}

关于android - 营养数据谷歌适合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34398824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com