营养数据计算优化;人脸增加数据处理;其它优化;
This commit is contained in:
@@ -35,6 +35,7 @@ import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.ext.gone
|
||||
import com.sw.dualscreen.ext.load
|
||||
import com.sw.dualscreen.ext.maskName
|
||||
import com.sw.dualscreen.ext.roundedDecimalPlace
|
||||
import com.sw.dualscreen.ext.visible
|
||||
import com.sw.dualscreen.model.response.DinnerType
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
@@ -61,6 +62,7 @@ import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import java.text.DecimalFormat
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -391,7 +393,7 @@ class MainScreenPresentation(
|
||||
}
|
||||
|
||||
private var isLoadUnbilledMode = false
|
||||
|
||||
private val df by lazy { DecimalFormat("#.##") }
|
||||
/**
|
||||
* 餐品识别成功,不计费模式
|
||||
*/
|
||||
@@ -411,8 +413,10 @@ class MainScreenPresentation(
|
||||
|
||||
//updateFoodInfo(foodInfo)
|
||||
binding.nutritionInclude.tvUserName.text = userNutrition?.name.maskName()
|
||||
binding.nutritionInclude.tvRecommendHeat.text =
|
||||
"推荐热量:${userNutrition?.recommendCalorie.format2String(2)}kcal"
|
||||
val recommendCalorie = userNutrition?.recommendCalorie ?: 0.0
|
||||
|
||||
binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${df.format(recommendCalorie)}kcal"
|
||||
// binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${recommendCalorie.removeTrailingZeros()}kcal"
|
||||
//updateWeight(lastWeight / 1000)
|
||||
// -------------------------------------------------
|
||||
// 删除userNutritionData,改为userNutrition
|
||||
|
||||
@@ -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