]> Nutra Git (v2) - nutratech/cli.git/commitdiff
general cleanups 14/head
authorShane Jaroch <chown_tee@proton.me>
Thu, 28 Jul 2022 09:02:08 +0000 (05:02 -0400)
committerShane Jaroch <chown_tee@proton.me>
Mon, 8 Aug 2022 18:17:57 +0000 (14:17 -0400)
    remove unused _age() function

    remove main() in tree.py [wip]

    setup.cfg stuff, types, read perms

    try removing scripts, same approach on both OSes

    don't use kwargs in setup() [checks typing]

    non-executable script

    add types-* packages (psycopg2, colorama)

    fix error in orm_brzycki equation (same in, same out)

19 files changed:
.github/workflows/install-linux.yml
.github/workflows/lint.yml
.github/workflows/test.yml
.gitignore
CHANGELOG.rst
README.rst
ntclient/__init__.py [changed mode: 0755->0644]
ntclient/__main__.py
ntclient/core/nnest.py [changed mode: 0755->0644]
ntclient/core/nnr2.py [changed mode: 0755->0644]
ntclient/services/analyze.py [changed mode: 0755->0644]
ntclient/services/calculate.py
ntclient/utils/tree.py [changed mode: 0755->0644]
requirements-lint.txt
scripts/n [deleted file]
scripts/nutra [deleted file]
setup.cfg
setup.py
tests/services/test_calculate.py [new file with mode: 0644]

index 40a08a4e2976cc510e8bd8bdb627dd4da804fe51..6d283a69bc60d7fabcce6527d09f1016cb7be896 100644 (file)
@@ -4,6 +4,9 @@ name: install-linux
 "on":
   push: {}
 
+permissions:
+  contents: read
+
 jobs:
   python:
     runs-on: ubuntu-18.04
index ffff075e37ee6f89a036537fea19a9d13fa13a34..0776699d4076904138ed6bdae9e3fd2025dd3c98 100644 (file)
@@ -4,6 +4,9 @@ name: lint
 "on":
   push: {}
 
+permissions:
+  contents: read
+
 jobs:
   lint:
     runs-on: ubuntu-latest
index ebac87d906973ecd104298d387c2354c6fb8b175..1ce797d209c9b89f59c7da0a780ee93e09d4e276 100644 (file)
@@ -4,6 +4,9 @@ name: test
 "on":
   push: {}
 
+permissions:
+  contents: read
+
 jobs:
   test:
     runs-on: [self-hosted, dev-east]
index a57656af3a3cdbd9e28c82ffa0c1135becddc605..7a30ff7ba958cfc10e788df58133b9fde5102f4a 100644 (file)
@@ -1,6 +1,7 @@
 # macOS/backup files
 .~*
 ._*
+~$*
 .DS_Store
 *.swp
 
@@ -11,6 +12,11 @@ __sha__.py
 *.sqlite
 .nutra*
 
+
+# Temporary
+docs*
+
+
 ####################
 ## Python Ignores ##
 ####################
index 892dea3bf310a1727b0deb50594e03315d05105a..bcebacb3cf07fdfd7c933ff149093401c0b8e586 100644 (file)
@@ -21,6 +21,7 @@ Added
 - Example recipe ``csv`` files.
 - ``unittest`` compatibility, not sure this will stay.
   May revert to ``pytest``.
+- Dedicated test file for calculate service.
 
 Changed
 ~~~~~~~
index c6dfbfd50f74e7d1cf9683b618102058f7e2c384..e49ab118a8e997693199278983fc97a2c86a23c5 100644 (file)
@@ -29,14 +29,14 @@ Details
   * - Category
     -
     -
-  * - Test / Linux
-    - .. image:: https://github.com/nutratech/cli/actions/workflows/test-linux.yml/badge.svg
-        :target: https://github.com/nutratech/cli/actions/workflows/test-linux.yml
+  * - Install / Linux
+    - .. image:: https://github.com/nutratech/cli/actions/workflows/install-linux.yml/badge.svg
+        :target: https://github.com/nutratech/cli/actions/workflows/install-linux.yml
         :alt: Test status unknown (Linux)
     -
-  * - Test / Windows
-    - .. image:: https://github.com/nutratech/cli/actions/workflows/test-win32.yml/badge.svg
-        :target: https://github.com/nutratech/cli/actions/workflows/test-win32.yml
+  * - Install / Windows
+    - .. image:: https://github.com/nutratech/cli/actions/workflows/install-win32.yml/badge.svg
+        :target: https://github.com/nutratech/cli/actions/workflows/install-win32.yml
         :alt: Test status unknown (Windows)
     -
   * - Other checks
old mode 100755 (executable)
new mode 100644 (file)
index 6f5494fe2875b2158e5c324dcf6279019bfff780..73e11166f2dd848ea87dfe4321b463e33ad75a64 100644 (file)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# PYTHON_ARGCOMPLETE_OK
 """
 Main module which is called by scripts.
 Top-level argument parsing logic; error handling.
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 818631bdceee93a277989e6690c17a720919428e..7bbda91da1f30728c936001d1696bf5179c2e173 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 """
-Calculate service for one rep max, BMR, body fat.
+Calculate service for one rep max, BMR, body fat, lean body limit, etc.
 
 Created on Tue Aug 11 20:53:14 2020
 
@@ -8,7 +8,6 @@ Created on Tue Aug 11 20:53:14 2020
 """
 import argparse
 import math
-from datetime import datetime
 
 from ntclient import Gender
 
@@ -58,7 +57,7 @@ def orm_brzycki(weight: float, reps: float) -> dict:
     one_rm = _one_rm()
 
     def weight_max_reps(target_reps: float) -> float:
-        _un_rounded_result = one_rm / (1 + (target_reps - 1) / 30)
+        _un_rounded_result = one_rm * (37 - target_reps) / 36
         return round(_un_rounded_result, 1)
 
     maxes = {n_reps: weight_max_reps(n_reps) for n_reps in common_n_reps}
@@ -467,18 +466,3 @@ def lbl_casey_butt(height: float, args: argparse.Namespace) -> dict:
         "thigh": round(1.3868 * ankle + 0.1805 * height, 2),
         "calf": round(0.9298 * ankle + 0.1210 * height, 2),
     }
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Misc functions
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-def _age(dob: int) -> float:
-    """
-    Calculate age based on birthday.
-
-    @param dob: birth time in UNIX seconds
-    @return: age in years
-    """
-    now = datetime.now().timestamp()
-    years = (now - dob) / (365 * 24 * 3600)
-    return years
old mode 100755 (executable)
new mode 100644 (file)
index cb72461..0bc8402
@@ -1,5 +1,4 @@
-#!/usr/bin/env python3
-"""Python 3 reimplementation of the linux 'tree' utility"""
+"""Python 3 re-implementation of the Linux 'tree' utility"""
 
 import os
 import sys
@@ -70,7 +69,7 @@ def print_dir(_dir: str, pre: str = str()) -> tuple:
     Prints the whole tree
 
     TODO: integrate with data sources to display more than just filenames
-    TODO: filter hidden files, non-CSV files, and hide *.csv extension from files
+    TODO: hide non-CSV files, and don't show *.csv extension (just file name)
     """
     n_dirs = 0
     n_files = 0
@@ -82,7 +81,7 @@ def print_dir(_dir: str, pre: str = str()) -> tuple:
     dir_len = len(os.listdir(_dir)) - 1
     for i, file in enumerate(sorted(os.listdir(_dir), key=str.lower)):
         path = os.path.join(_dir, file)
-        if file[0] == "." and not SHOW_HIDDEN:
+        if file.startswith(".") and not SHOW_HIDDEN:
             continue
         if os.path.isdir(path):
             print(pre + strs[2 if i == dir_len else 1] + colorize(path))
@@ -131,7 +130,3 @@ def main_tree(_args: list = None) -> int:
         )
     )
     return 0
-
-
-if __name__ == "__main__":
-    sys.exit(main_tree())
index 7cb15758a780f67338f84bfb6b82ea0b81e22219..e4826db6e12f0b0a9a131243eebe47f02cea0d30 100644 (file)
@@ -5,5 +5,8 @@ doc8>=0.11
 flake8>=4.0
 mypy>=0.960
 pylint>=2.13
+types-colorama>=0.4.15
+types-psycopg2>=2.9.18
+types-setuptools>=57.4.0
 types-tabulate>=0.8.11
 yamllint>=1.27
diff --git a/scripts/n b/scripts/n
deleted file mode 100755 (executable)
index a1b3619..0000000
--- a/scripts/n
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/python3
-# -*- coding: utf-8 -*-
-# PYTHON_ARGCOMPLETE_OK
-"""Executable script, copied over by pip"""
-import re
-import sys
-
-from ntclient.__main__ import main
-
-if __name__ == "__main__":
-    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
-    sys.exit(main())
diff --git a/scripts/nutra b/scripts/nutra
deleted file mode 100755 (executable)
index a1b3619..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/python3
-# -*- coding: utf-8 -*-
-# PYTHON_ARGCOMPLETE_OK
-"""Executable script, copied over by pip"""
-import re
-import sys
-
-from ntclient.__main__ import main
-
-if __name__ == "__main__":
-    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
-    sys.exit(main())
index aa3344d1a5ce95bc7bdf537f13996e006258e2a8..33f211e4ddddcf255d15ddb1b213150974dd9e78 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -70,5 +70,5 @@ disallow_untyped_defs = False
 ignore_missing_imports = True
 
 # 3rd party packages missing types
-[mypy-argcomplete,colorama,coverage,fuzzywuzzy,psycopg2.*,setuptools]
+[mypy-argcomplete,coverage,fuzzywuzzy]
 ignore_missing_imports = True
index cd14570bb058dbbfd383689330db511eb0354e3a..4a9f1ec227d3e4361f362949d42348c552d987e1 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -4,8 +4,6 @@ Created on Sat Oct 13 16:30:30 2018
 
 @author: shane
 """
-
-import glob
 import os
 import platform
 
@@ -57,32 +55,25 @@ if PLATFORM_SYSTEM != "Windows" or int(os.getenv("NUTRA_OS_FORCE_OPT_REQS", str(
         optional_reqs = file.read().split()
     REQUIREMENTS.extend(optional_reqs)
 
-# Prepare setup() inputs (OS dependent)
-kwargs = {
-    "name": __title__,
-    "author": __author__,
-    "author_email": __email__,
-    "classifiers": CLASSIFIERS,
-    "install_requires": REQUIREMENTS,
-    "python_requires": ">=%s" % PY_MIN_STR,
-    "zip_safe": False,
-    "packages": find_packages(exclude=["tests", "ntclient.docs"]),
-    "include_package_data": True,
-    "platforms": ["linux", "darwin", "win32"],
-    "description": "Home and office nutrient tracking software",
-    "long_description": README,
-    "long_description_content_type": "text/x-rst",
-    "url": "https://github.com/nutratech/cli",
-    "license": "GPL v3",
-    "version": __version__,
-}
-
-if PLATFORM_SYSTEM == "Windows":
-    kwargs["entry_points"] = {
-        "console_scripts": ["nutra=ntclient.__main__:main", "n=ntclient.__main__:main"]
-    }
-else:
-    kwargs["scripts"] = glob.glob("scripts/*")
-
 # Setup method
-setup(**kwargs)
+setup(
+    name=__title__,
+    author=__author__,
+    author_email=__email__,
+    classifiers=CLASSIFIERS,
+    install_requires=REQUIREMENTS,
+    python_requires=">=%s" % PY_MIN_STR,
+    zip_safe=False,
+    packages=find_packages(exclude=["tests", "ntclient.docs"]),
+    include_package_data=True,
+    entry_points={
+        "console_scripts": ["nutra=ntclient.__main__:main", "n=ntclient.__main__:main"]
+    },
+    platforms=["linux", "darwin", "win32"],
+    description="Home and office nutrient tracking software",
+    long_description=README,
+    long_description_content_type="text/x-rst",
+    url="https://github.com/nutratech/cli",
+    license="GPL v3",
+    version=__version__,
+)
diff --git a/tests/services/test_calculate.py b/tests/services/test_calculate.py
new file mode 100644 (file)
index 0000000..299258e
--- /dev/null
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Aug  8 12:13:01 2022
+
+@author: shane
+
+Tests the "calculate service" for any anomalies.
+"""
+import pytest
+
+import ntclient.services.calculate as calc
+
+
+@pytest.mark.parametrize("_eq", ["epley", "brzycki", "dos_remedios"])
+@pytest.mark.parametrize(
+    "weight,reps",
+    [
+        (50.0, 1),
+        (50.0, 2),
+        (50.0, 3),
+        (50.0, 5),
+        (50.0, 6),
+        (50.0, 8),
+        (50.0, 10),
+        (50.0, 12),
+        (50.0, 15),
+        (50.0, 20),
+    ],
+)
+def test_000_orm_same_in_same_out(_eq: str, weight: float, reps: int) -> None:
+    """Test one rep max: Epley"""
+    if _eq == "epley":
+        result = calc.orm_epley(weight, reps)
+
+    elif _eq == "brzycki":
+        result = calc.orm_brzycki(weight, reps)
+
+    else:  # _eq == "dos_remedios"
+        result = calc.orm_dos_remedios(weight, reps)
+
+    try:
+        # Check results
+        assert result[reps] == weight
+    except KeyError:
+        # dose Remedios does not work for 20 reps currently
+        assert _eq == "dos_remedios"
+        assert reps == 20