diff --git a/app/src/main/java/com/sw/dualscreen/objbox/FoodModule.kt b/app/src/main/java/com/sw/dualscreen/objbox/FoodModule.kt index d9f958e..3c1b1d1 100644 --- a/app/src/main/java/com/sw/dualscreen/objbox/FoodModule.kt +++ b/app/src/main/java/com/sw/dualscreen/objbox/FoodModule.kt @@ -124,7 +124,7 @@ object FoodModule { suspend fun queryFoodNameScore( floatArray: FloatArray?, - queryCount: Int = 15 + queryCount: Int = 50 ): List { if (floatArray == null) return emptyList() val startTime = System.currentTimeMillis() @@ -151,7 +151,7 @@ object FoodModule { return nameScoreList } - suspend fun getFoodScoreList(bitmap: Bitmap, queryCount: Int = 15): List { + suspend fun getFoodScoreList(bitmap: Bitmap, queryCount: Int = 50): List { val startTime = System.currentTimeMillis() val floatArray = bitmap2FloatArray(bitmap, false) Timber.tag(TAG).d("bitmap2FloatArray,耗时:${System.currentTimeMillis() - startTime}") @@ -161,28 +161,26 @@ object FoodModule { return emptyList() } val maxScoreList = nameScoreList - .filter { it.score < 1 - THRESHOLD } +// .filter { it.score < 1 - THRESHOLD } .groupBy { it.name } .map { (_, value) -> value.minByOrNull { it.score }!! } .toMutableList() - val map = mutableMapOf() - nameScoreList.forEach { - val key = it.name - val count = map[key] ?: 0 - map[key] = count + 1 - } - val orderList = map.entries.sortedByDescending { it.value }.map { it.key }.toMutableList() - val firstFood = nameScoreList[0].name - orderList.remove(firstFood) - orderList.add(0, firstFood) - - val sortedScoreList = maxScoreList.sortedWith(compareBy { - orderList.indexOf(it.name) - }) - if (bitmap.isRecycled.not()) { - bitmap.recycle() - } - //Timber.tag("FoodModule").d("getFoodScoreList数据:${sortedScoreList.toJsonString()}") +// val map = mutableMapOf() +// nameScoreList.forEach { +// val key = it.name +// val count = map[key] ?: 0 +// map[key] = count + 1 +// } +// val orderList = map.entries.sortedByDescending { it.value }.map { it.key }.toMutableList() +// val firstFood = nameScoreList[0].name +// orderList.remove(firstFood) +// orderList.add(0, firstFood) +// +// val sortedScoreList = maxScoreList.sortedWith(compareBy { +// orderList.indexOf(it.name) +// }) + val sortedScoreList = maxScoreList.sortedBy { it.score } + Timber.tag("FoodModule").d("getFoodScoreList数据:${sortedScoreList.toString()}") return sortedScoreList }