]> Nutra Git (v2) - nutratech/cli.git/commitdiff
wip
authorShane Jaroch <chown_tee@proton.me>
Fri, 23 Feb 2024 22:03:36 +0000 (17:03 -0500)
committerShane Jaroch <chown_tee@proton.me>
Fri, 23 Feb 2024 22:03:36 +0000 (17:03 -0500)
ntclient/core/nnest.py
ntclient/core/nutprogbar.py
ntclient/services/analyze.py

index 515ca484f5c91a53730801dc8caae01756c3bd9c..f3a75f21af7a59a55ae978d0b573016c84efcd4f 100644 (file)
@@ -18,6 +18,7 @@ class Nutrient:
         self.nut_id = nut_id
         self.name = name
         self.hidden = hidden
+        self.rounded_rda = 0  # TODO: round day/recipe analysis to appropriate digit
 
 
 nnest = {
index 21ced4f9120a583425846a4da6738147dff1abb2..f62b922b0cf999cd64a9913a5b5b05a13ed982e6 100644 (file)
@@ -1,7 +1,13 @@
 """Temporary [wip] module for more visual (& colorful) RDA output"""
 
 
-def nutprogbar(food_amts: dict, food_analyses: list, nutrients: dict) -> dict:
+def nutprogbar(
+    food_amts: dict,
+    food_analyses: list,
+    nutrients: dict,
+    grams: float = 100,
+    width: int = 50,
+) -> dict:
     """Returns progress bars, colorized, for foods analyses"""
 
     def tally() -> None:
index b05a72abfb1dba73a0c4bd251f93206f617d5c3a..4bcd71fe0e9999ce104bc178c06755ba0c521a63 100644 (file)
@@ -18,6 +18,7 @@ from ntclient import (
     NUTR_ID_KCAL,
     NUTR_ID_PROTEIN,
 )
+from ntclient.core.nutprogbar import nutprogbar
 from ntclient.persistence.sql.usda.funcs import (
     sql_analyze_foods,
     sql_food_details,
@@ -42,7 +43,6 @@ def foods_analyze(food_ids: set, grams: float = 0) -> tuple:
         print()
         print("=========================")
         print(header)
-        print()
         print("=========================")
 
     ##########################################################################
@@ -79,11 +79,11 @@ def foods_analyze(food_ids: set, grams: float = 0) -> tuple:
             + "==> {0} ({1})\n".format(food_name, food_id)
             + "======================================\n"
         )
-        print_header("SERVINGS")
 
         ######################################################################
         # Serving table
         ######################################################################
+        print_header("SERVINGS")
         headers = ["msre_id", "msre_desc", "grams"]
         serving_rows = [(x[1], x[2], x[3]) for x in serving if x[0] == food_id]
         # Print table
@@ -99,12 +99,11 @@ def foods_analyze(food_ids: set, grams: float = 0) -> tuple:
             print(refuse[0])
             print("    ({0}%, by mass)".format(refuse[1]))
 
-        print_header("NUTRITION")
-
         ######################################################################
         # Nutrient colored RDA tree-view
         ######################################################################
-        headers = ["id", "nutrient", "rda", "amount", "units"]
+        print_header("NUTRITION")
+        # headers = ["id", "nutrient", "rda", "amount", "units"]
         nutrient_rows = []
         for nutrient_id, amount in nut_val_tuples:
             # TODO: skip small values (<1% RDA), report as color bar if RDA is available
@@ -128,8 +127,9 @@ def foods_analyze(food_ids: set, grams: float = 0) -> tuple:
         ############
         # Print view
         # TODO: nested, color-coded tree view
-        table = tabulate(nutrient_rows, headers=headers, tablefmt="presto")
-        print(table)
+        nutprogbar(food_amts, food_analyses, nutrients)
+        # table = tabulate(nutrient_rows, headers=headers, tablefmt="presto")
+        # print(table)
         nutrients_rows.append(nutrient_rows)
 
     return 0, nutrients_rows, servings_rows