营养数据计算优化;人脸增加数据处理;其它优化;
This commit is contained in:
@@ -24,14 +24,16 @@ object UserNutritionUtils {
|
||||
dinnerType: String
|
||||
): UserEnergy {
|
||||
// 初始化变量
|
||||
var totalKcal = 0.0
|
||||
//var totalKcal = 0.0
|
||||
var (calorie, grain, fruitsVegetables, meatEggs) = List(4) { 0.0 }
|
||||
|
||||
// 处理食物信息
|
||||
calorie = foodInfo.calorie ?: 0.0 //calculateValue(foodInfo.calorie, weight)
|
||||
grain = foodInfo.stapleFood ?: 0.0 //calculateValue(foodInfo.stapleFood, weight)
|
||||
fruitsVegetables = foodInfo.fruitsVegetables ?: 0.0 //calculateValue(foodInfo.fruitsVegetables, weight)
|
||||
meatEggs = foodInfo.meatEggs ?: 0.0 //calculateValue(foodInfo.meatEggs, weight)
|
||||
if (weight > 0.0) {
|
||||
calorie = calculateValue2(foodInfo.calorie,foodInfo.specWeight, weight)
|
||||
grain = calculateValue2(foodInfo.stapleFood, foodInfo.specWeight,weight)
|
||||
fruitsVegetables = calculateValue2(foodInfo.fruitsVegetables, foodInfo.specWeight,weight)
|
||||
meatEggs = calculateValue2(foodInfo.meatEggs, foodInfo.specWeight,weight)
|
||||
}
|
||||
|
||||
// 合并用户数据
|
||||
//val maxKcal = (nutrition.calorie?:0.0) * calculateDinnerTypeRatio(dinnerType) / 10.0
|
||||
@@ -40,7 +42,7 @@ object UserNutritionUtils {
|
||||
fruitsVegetables += nutrition.fruitsVegetables ?: 0.0
|
||||
meatEggs += nutrition.meatEggs ?: 0.0
|
||||
|
||||
totalKcal = max(calorie, 0.0)
|
||||
//totalKcal = max(calorie, 0.0)
|
||||
// 判断当餐最大热量
|
||||
//val maxKcal = userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
|
||||
//Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
|
||||
@@ -55,7 +57,7 @@ object UserNutritionUtils {
|
||||
// meat = parseRecommend(foodInfo.meatEggsRecommend, meatEggs)
|
||||
// )
|
||||
return UserEnergy(
|
||||
calorie = totalKcal,
|
||||
calorie = calorie,
|
||||
grain = grain,
|
||||
fruitsVegetables = fruitsVegetables,
|
||||
meatEggs = meatEggs
|
||||
@@ -140,7 +142,10 @@ object UserNutritionUtils {
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateValue2(nutrient: Double?, specWeight: Double?, weight: Double): Double {
|
||||
if ((nutrient?:0.0) == 0.0 || (specWeight?:0.0) == 0.0) return 0.0
|
||||
return nutrient!! * weight / specWeight!!
|
||||
}
|
||||
/**
|
||||
* 计算每百克含量
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user