Browse Source

Added basic parsing rules for USDA sample and survey foods.

These could be fleshed out to be more comprehensive, but I'm not sure
by how much.  This will at least cover basic use-cases.
Thomas Flucke 2 years ago
parent
commit
7afbdce21a

+ 0 - 0
server/logs/application.log


+ 22 - 3
shared/shared/src/main/scala/com/weEat/shared/models/FoodNode.scala

@@ -374,7 +374,20 @@ object USDANodeNoId {
         nutr.calories.map(amt => ("208", amt))
       ).flatten.toMap
     )
-    case SurveyFoodItem(id, _, desc, _, _, _, _, _, _, port, _, _) => ???
+    case SurveyFoodItem(id, _, desc, _, _, _, _, _, _, port, _, _) => USDANodeNoId(
+      desc,
+      id,
+      getDefaultMeasure(port.map { (port) =>
+        val str = portionStr(port)
+        Measure(port, portionToMeasure(port, str), str)
+      }, VOLUME, None).map(_.conversion),
+      getDefaultMeasure(port.map { (port) =>
+        val str = portionStr(port)
+        Measure(port, portionToMeasure(port, str), str)
+      }, MASS, None).map(_.conversion),
+      0.0f,
+      Map()
+    )
     case SRLegacyFoodItem(id, _, dsc, _, _, _, _, _, _, nutr, _, _, _, port, _) =>
       USDANodeNoId(
         dsc,
@@ -392,7 +405,14 @@ object USDANodeNoId {
           .getOrElse(0.0f),
         nutr.flatMap(x => x.amount.map(amt => (x.nutrient.number, amt))).toMap
       )
-    case SampleFoodItem(id, _, desc, _, _, _) => ???
+    case SampleFoodItem(id, _, desc, _, _, _) => USDANodeNoId(
+      desc,
+      id,
+      None,
+      None,
+      0.0f,
+      Map()
+    )
   }
 
   implicit val config = JsonConfiguration(JsonNaming.SnakeCase)
@@ -445,7 +465,6 @@ object FoodNodeId {
     (requ match {
       case node: USDANodeId => Json.toJson(node)
       case node: RecipeNodeId => Json.toJson(node)
-      case node => println(node);???
     }).asInstanceOf[JsObject] + (("node_type", Json.toJson(requ.nodeType)))
   )