Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gamesguru committed Feb 23, 2024
1 parent eedf676 commit cbf44f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions ntclient/core/nnest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, nut_id: int, name: str, hidden: bool = False):
self.nut_id = nut_id
self.name = name
self.hidden = hidden
self.rounded_rda = 0 # TODO: round day/recipe analysis to appropriate digit


nnest = {
Expand Down
8 changes: 7 additions & 1 deletion ntclient/core/nutprogbar.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
14 changes: 7 additions & 7 deletions ntclient/services/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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,
Expand All @@ -42,7 +43,6 @@ def print_header(header: str) -> None:
print()
print("=========================")
print(header)
print()
print("=========================")

##########################################################################
Expand Down Expand Up @@ -79,11 +79,11 @@ def print_header(header: str) -> None:
+ "==> {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
Expand All @@ -99,12 +99,11 @@ def print_header(header: str) -> None:
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
Expand All @@ -128,8 +127,9 @@ def print_header(header: str) -> None:
############
# 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
Expand Down

0 comments on commit cbf44f4

Please sign in to comment.