营养接口调试、支付接口联调
This commit is contained in:
@@ -4,6 +4,7 @@ package com.sw.dualscreen.presentation
|
||||
import android.text.TextUtils
|
||||
import com.sw.dualscreen.ext.toSafeDouble
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.UserEnergy
|
||||
import com.sw.dualscreen.model.response.UserNutrition
|
||||
import com.sw.dualscreen.model.response.UserNutritionData
|
||||
import timber.log.Timber
|
||||
@@ -22,7 +23,7 @@ object UserNutritionUtils {
|
||||
nutrition: UserNutrition,
|
||||
weight: Double,
|
||||
dinnerType: String
|
||||
): CalcResultInfo {
|
||||
): UserEnergy {
|
||||
// 初始化变量
|
||||
var totalKcal = 0.0
|
||||
var (calorie, grain, fruitsVegetables, meatEggs) = List(4) { 0.0 }
|
||||
@@ -34,6 +35,7 @@ object UserNutritionUtils {
|
||||
meatEggs = calculateValue(foodInfo.meatEggs, weight)
|
||||
|
||||
// 合并用户数据
|
||||
//val maxKcal = (nutrition.calorie?:0.0) * calculateDinnerTypeRatio(dinnerType) / 10.0
|
||||
calorie += nutrition.calorie ?: 0.0
|
||||
grain += nutrition.stapleFood ?: 0.0
|
||||
fruitsVegetables += nutrition.fruitsVegetables ?: 0.0
|
||||
@@ -43,24 +45,22 @@ object UserNutritionUtils {
|
||||
// 判断当餐最大热量
|
||||
//val maxKcal = userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
|
||||
//Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
|
||||
// TODO: 测试数据-------------------------------
|
||||
val rate = calculateDinnerTypeRatio(dinnerType) / 10.0
|
||||
val maxKcal = totalKcal/ 0.26 / rate
|
||||
val grainRecommend = "0-100"
|
||||
val meatRecommend = "0-100"
|
||||
val fruitsRecommend = "0-100"
|
||||
// TODO: 测试数据-------------------------------
|
||||
val calcResult = CalcResultInfo(
|
||||
totalKcal = CalcInfo(
|
||||
max = maxKcal,
|
||||
min = 0.0,
|
||||
current = totalKcal
|
||||
),
|
||||
grain = parseRecommend(grainRecommend, grain),
|
||||
fruits = parseRecommend(fruitsRecommend, fruitsVegetables),
|
||||
meat = parseRecommend(meatRecommend, meatEggs)
|
||||
// val calcResult = CalcResultInfo(
|
||||
// totalKcal = CalcInfo(
|
||||
// max = maxKcal,
|
||||
// min = 0.0,
|
||||
// current = totalKcal
|
||||
// ),
|
||||
// grain = parseRecommend(foodInfo.stapleFoodRecommend, grain),
|
||||
// fruits = parseRecommend(foodInfo.fruitsVegetablesRecommend, fruitsVegetables),
|
||||
// meat = parseRecommend(foodInfo.meatEggsRecommend, meatEggs)
|
||||
// )
|
||||
return UserEnergy(
|
||||
calorie = totalKcal,
|
||||
grain = grain,
|
||||
fruitsVegetables = fruitsVegetables,
|
||||
meatEggs = meatEggs
|
||||
)
|
||||
return calcResult
|
||||
}
|
||||
|
||||
// fun calculateNutrition(
|
||||
@@ -121,7 +121,7 @@ object UserNutritionUtils {
|
||||
// }
|
||||
|
||||
fun parseRecommend(recommend: String?, current: Double): CalcInfo {
|
||||
var newCurrent = if (current < 0) 0.0 else current
|
||||
val newCurrent = if (current < 0) 0.0 else current
|
||||
if (TextUtils.isEmpty(recommend) || !recommend!!.contains("-")) {
|
||||
Timber.e("parseRecommend recommend 格式错误")
|
||||
return CalcInfo(
|
||||
@@ -154,6 +154,36 @@ object UserNutritionUtils {
|
||||
return max(max1, calcResultInfo.meat.max).toInt()
|
||||
}
|
||||
|
||||
fun getCalorieArray(left:String?, mid:String?, right: String?):DoubleArray {
|
||||
val leftArray = (left?.ifBlank { "0-0" } ?: "0-0").split("-").map { it.toSafeDouble() }
|
||||
val midArray = (mid?.ifBlank { "0-0" } ?: "0-0").split("-").map { it.toSafeDouble() }
|
||||
val rightArray = (right?.ifBlank { "0-0" } ?: "0-0").split("-").map { it.toSafeDouble() }
|
||||
return doubleArrayOf(
|
||||
0.0, leftArray[0], midArray[0], rightArray[0], rightArray[1]
|
||||
)
|
||||
}
|
||||
|
||||
fun findCalorieIndex(num: Double, array: DoubleArray): Int {
|
||||
if (array.isEmpty()) return 0
|
||||
if (num < array[0]) return 0
|
||||
if (num >= array[array.lastIndex]) return array.lastIndex
|
||||
|
||||
var left = 0
|
||||
var right = array.lastIndex
|
||||
while (left < right) {
|
||||
val mid = left + (right - left) / 2
|
||||
if (array[mid] <= num && num < array[mid + 1]) {
|
||||
return mid
|
||||
} else if (num < array[mid]) {
|
||||
right = mid
|
||||
} else {
|
||||
left = mid + 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
data class CalcInfo(
|
||||
var max: Double,
|
||||
var min: Double,
|
||||
|
||||
Reference in New Issue
Block a user