This commit is contained in:
2026-01-09 16:10:57 +08:00
parent a0452e985a
commit a6fa5f153a
3 changed files with 10 additions and 9 deletions
@@ -29,10 +29,10 @@ object UserNutritionUtils {
// 处理食物信息
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)
calorie = calculateValue2(foodInfo.calorie,weight)
grain = calculateValue2(foodInfo.stapleFood, weight)
fruitsVegetables = calculateValue2(foodInfo.fruitsVegetables, weight)
meatEggs = calculateValue2(foodInfo.meatEggs, weight)
}
// 合并用户数据
@@ -142,9 +142,9 @@ 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!!
private fun calculateValue2(nutrient: Double?, weight: Double): Double {
if ((nutrient?:0.0) == 0.0) return 0.0
return nutrient!! * weight / 100.0
}
/**
* 计算每百克含量