anl analyze food(s)
day analyze a DAY.csv file, RDAs optional
recipe list and analyze recipes
- bio view, add, remove biometric logs
build_analyze_subcommand(subparsers)
build_day_subcommand(subparsers)
build_recipe_subcommand(subparsers)
- build_biometric_subcommand(subparsers)
################################################################################
recipe_delete_parser.set_defaults(func=parser_funcs.recipe_delete)
recipe_parser.set_defaults(func=parser_funcs.recipes)
-
-
-def build_biometric_subcommand(subparsers) -> None:
- """View biometrics, and view, add, edit, delete log entries"""
- bio_parser = subparsers.add_parser("bio", help="view, add, remove biometric logs")
- bio_subparsers = bio_parser.add_subparsers(title="biometric subcommands")
-
- bio_log_parser = bio_subparsers.add_parser("log", help="manage biometric logs")
- bio_log_subparsers = bio_log_parser.add_subparsers(
- title="biometric log subcommands"
- )
- bio_log_parser.set_defaults(func=parser_funcs.bio_log)
-
- bio_log_add_parser = bio_log_subparsers.add_parser(
- "add", help="add a biometric log"
- )
- bio_log_add_parser.add_argument(
- "biometric_val", help="id,value pairs, e.g. 22,59 23,110 24,65 ", nargs="+"
- )
- bio_log_add_parser.set_defaults(func=parser_funcs.bio_log_add)
-
- bio_parser.set_defaults(func=parser_funcs.bio)
return services.analyze.day_analyze(day_csv_paths, rda_csv_path=rda_csv_path)
-################################################################################
-# Biometrics
-################################################################################
-def bio():
- """List biometrics"""
- return services.biometrics.biometrics()
-
-
-def bio_log():
- """List biometric logs"""
- return services.biometrics.biometric_logs()
-
-
-def bio_log_add(args):
- """Add a biometric log entry"""
- bio_vals = {
- int(x.split(",")[0]): float(x.split(",")[1]) for x in args.biometric_val
- }
-
- return services.biometrics.biometric_add(bio_vals)
-
-
################################################################################
# Recipes
################################################################################
-Subproject commit a2455748d628963df01afeecd2b058b2cdd8344a
+Subproject commit 14a02e2ce2a26dc218a43b60d3151e4cf7e352a0
query = """
"""
return sql(query)
-
-
-################################################################################
-# Biometric functions
-################################################################################
-def sql_biometrics():
- """Selects biometrics"""
- query = "SELECT * FROM biometrics;"
- return sql(query, headers=True)
-
-
-def sql_biometric_logs(profile_id):
- """Selects biometric logs"""
- query = "SELECT * FROM biometric_log WHERE profile_id=?"
- return sql(query, values=(profile_id,), headers=True)
-
-
-def sql_biometric_add(bio_vals):
- """Insert biometric log item"""
- con = nt_sqlite_connect()
- cur = con.cursor()
-
- # TODO: finish up
- query1 = "INSERT INTO biometric_log(profile_id, tags, notes) VALUES (?, ?, ?)"
- sql(query1, (PROFILE_ID, "", ""))
- log_id = cur.lastrowid
- print(log_id)
- query2 = "INSERT INTO bio_log_entry(log_id, biometric_id, value) VALUES (?, ?, ?)"
- records = [
- (log_id, biometric_id, value) for biometric_id, value in bio_vals.items()
- ]
- cur.executemany(query2, records)
- return log_id
from ntclient.ntsqlite.sql import build_ntsqlite
from ntclient.persistence.sql.nt import nt_ver
from ntclient.persistence.sql.usda import usda_init
-from ntclient.services import analyze, biometrics, recipe, usda
+from ntclient.services import analyze, recipe, usda
from ntclient.utils.exceptions import SqlInvalidVersionError
+++ /dev/null
-"""Biometrics SQL functions"""
-from tabulate import tabulate
-
-from ntclient.persistence import PROFILE_ID
-from ntclient.persistence.sql.nt.funcs import (
- sql_biometric_add,
- sql_biometric_logs,
- sql_biometrics,
-)
-
-
-def biometrics():
- """Shows biometrics"""
- headers, rows = sql_biometrics()
- table = tabulate(rows, headers=headers, tablefmt="presto")
- print(table)
- return 0, rows
-
-
-def biometric_logs():
- """Shows biometric logs"""
- headers, rows = sql_biometric_logs(PROFILE_ID)
-
- table = tabulate(rows, headers=headers, tablefmt="presto")
- print(table)
- return 0, rows
-
-
-def biometric_add(bio_vals):
- """Add a biometric type"""
- print()
- # print("New biometric log: " + name + "\n")
-
- bio_names = {x[0]: x for x in sql_biometrics()[1]}
-
- results = []
- for biometric_id, value in bio_vals.items():
- bio = bio_names[biometric_id]
- results.append(
- {"id": biometric_id, "name": bio[1], "value": value, "unit": bio[2]}
- )
-
- table = tabulate(results, headers="keys", tablefmt="presto")
- print(table)
-
- # TODO: print current profile and date?
-
- confirm = input("\nConfirm add biometric? [Y/n] ")
-
- if confirm.lower() == "y":
- sql_biometric_add(bio_vals)
- print("not implemented ;]")
- return 1, False
version = nt_ver()
assert version == __db_target_nt__
- headers, rows = nt_funcs.sql_biometrics()
- assert headers == ["id", "name", "unit", "created"]
- assert len(rows) == 29
+ # TODO: add more tests, it used to poll biometrics
def test_300_argparser_debug_no_paging():
def test_600_sql_integrity_error__service_wip():
"""Provokes IntegrityError in nt.sqlite3"""
- from ntclient.services import biometrics # pylint: disable=import-outside-toplevel
-
- args = arg_parser.parse_args(args=["-d", "bio", "log", "add", "12,12"])
- biometrics.input = (
- lambda x: "y"
- ) # mocks input, could also pass `-y` flag or set yes=True
-
- with pytest.raises(sqlite3.IntegrityError) as integrity_error:
- args.func(args)
- assert (
- integrity_error.value.args[0]
- == "NOT NULL constraint failed: biometric_log.profile_id"
- )
+
+ # TODO: replace with non-biometric test
+ # from ntclient.services import biometrics # pylint: disable=import-outside-toplevel
+ #
+ # args = arg_parser.parse_args(args=["-d", "bio", "log", "add", "12,12"])
+ # biometrics.input = (
+ # lambda x: "y"
+ # ) # mocks input, could also pass `-y` flag or set yes=True
+ #
+ # with pytest.raises(sqlite3.IntegrityError) as integrity_error:
+ # args.func(args)
+ # assert (
+ # integrity_error.value.args[0]
+ # == "NOT NULL constraint failed: biometric_log.profile_id"
+ # )
def test_700_build_ntsqlite_succeeds():