"""Print macro-nutrients bar with details."""
_kcals = _fat * 9 + _net_carb * 4 + _pro * 4
- p_fat = (_fat * 9) / _kcals
- p_car = (_net_carb * 4) / _kcals
- p_pro = (_pro * 4) / _kcals
+ if _kcals == 0:
+ p_fat = 0.0
+ p_car = 0.0
+ p_pro = 0.0
+ else:
+ p_fat = (_fat * 9) / _kcals
+ p_car = (_net_carb * 4) / _kcals
+ p_pro = (_pro * 4) / _kcals
# TODO: handle rounding cases, tack on to, or trim off FROM LONGEST ?
mult = _kcals / _kcals_max
sql_nutrients_overview,
sql_servings,
)
+from ntclient.services.calculate import (
+ calculate_nutrient_totals,
+ calculate_scaling_multiplier,
+)
from ntclient.utils import CLI_CONFIG
Analyze a list of food_ids against stock RDA values
(NOTE: only supports a single food for now... add compare foods support later)
"""
+ # pylint: disable=too-many-locals
##########################################################################
# Get analysis
TODO: Should be a subset of foods_analyze (encapsulate/abstract/reuse code)
"""
+ # pylint: disable=too-many-locals,too-many-branches
# Get user RDAs from CSV file, if supplied
if rda_csv_path:
# Compute totals
nutrients_totals = []
total_grams_list = []
- from ntclient.services.calculate import calculate_nutrient_totals
for log in logs:
# Aggregate duplicates in log if any
total_weight: float = 0,
) -> None:
"""Formats day analysis for printing to console"""
-
- from ntclient.services.calculate import calculate_scaling_multiplier
+ # pylint: disable=too-many-arguments,too-many-locals
multiplier = calculate_scaling_multiplier(
scale, scale_mode, analysis, nutrients, total_weight
from collections import OrderedDict
from typing import Mapping
+from ntclient import NUTR_ID_KCAL
from ntclient.utils import Gender
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Determine the multiplier needed to scale the analysis values.
"""
multiplier = 1.0
- from ntclient import NUTR_ID_KCAL
-
- if not scale:
- return multiplier
-
if scale_mode == "kcal":
current_val = analysis.get(NUTR_ID_KCAL, 0)
multiplier = scale / current_val if current_val else 0
nutrient_id: int, by_kcal: bool, limit: int = DEFAULT_RESULT_LIMIT
) -> tuple:
"""Sort, by nutrient, either (amount / 100 g) or (amount / 200 kcal)"""
+ # pylint: disable=too-many-locals
# TODO: sub shrt_desc for long if available, and support config.FOOD_NAME_TRUNC
################################################################################
def search(words: list, fdgrp_id: int = 0, limit: int = DEFAULT_RESULT_LIMIT) -> tuple:
"""Searches foods for input"""
+ # pylint: disable=too-many-locals
def tabulate_search(_results: list) -> list:
"""Makes search results more readable"""
pytest.xfail("PermissionError, are you using Microsoft Windows?")
# mocks input, could also pass `-y` flag or set yes=True
- # pylint: disable=redefined-builtin
- usda.input = lambda x: "y"
+ setattr(usda, "input", lambda x: "y")
code, successful = init()
assert code == 0