Prechádzať zdrojové kódy

Fixed calorie calculations.

Thomas Flucke 1 rok pred
rodič
commit
6fbe4976c5

+ 14 - 4
shared/shared/src/main/scala/com/weEat/shared/models/FoodNode.scala

@@ -164,7 +164,17 @@ sealed trait RecipeNode extends FoodNode {
   )
 
   def nutrient(num: String) = ingredients.map({ ingr =>
-    ingr.food.map( (f) => 
+    ingr.food.map({ (f) =>
+      println(f.name)
+      println(num)
+      println(f.nutrient(num))
+      println(ingr.unit.convert(f, ingr.amount, f.defaultUnitType.defaultUnit))
+      f.nutrient(num)
+        .map(_ * (ingr.unit
+          .convert(f, ingr.amount, f.defaultUnitType.defaultUnit) match {
+            case Success(amt) => amt.toFloat
+            case Failure(e) => throw e
+          }) / UnitType.standardQuanity(f.defaultUnitType)).foreach(println _)
       f.nutrient(num)
         .map(_ * (ingr.unit
           .convert(f, ingr.amount, f.defaultUnitType.defaultUnit) match {
@@ -174,11 +184,11 @@ sealed trait RecipeNode extends FoodNode {
               // it in the data layer.  The UI should prevent this from ever
               // happening.
             case Failure(e) => throw e
-          }))
-    ).flatten
+          }) / UnitType.standardQuanity(f.defaultUnitType))
+    }).flatten
   }).fold(Future.successful(0.0f))({ case (a, b) =>
     a.zipWith(b) { case (x, y) => x + y }
-  }).map { _ / 100.0f }
+  })
 
   def nutrientPServing(num: String) = nutrient(num).map { _ / numServings }