wip
authorShane Jaroch <nutratracker@protonmail.com>
Thu, 26 May 2022 20:48:28 +0000 (16:48 -0400)
committerShane Jaroch <nutratracker@protonmail.com>
Thu, 26 May 2022 20:51:14 +0000 (16:51 -0400)
.editorconfig [new file with mode: 0644]
README.rst
docs/nt.svg
sql/__init__.py
sql/tables.sql

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..39f8d0d
--- /dev/null
@@ -0,0 +1,42 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 4
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+max_line_length = 100
+
+
+[*.{py}]
+max_line_length = 88
+
+
+[*.sql]
+indent_size = 2
+
+
+[*.{yaml,yml}]
+indent_size = 2
+
+
+[Makefile]
+indent_style = tab
+max_line_length = 120
+
+
+[*.md]
+max_line_length = 90
+trim_trailing_whitespace = false
+
+
+[*.rst]
+max_line_length = 79
+
+
+[{COMMIT_EDITMSG,MERGE_MSG,SQUASH_MSG}]
+max_line_length = 72
+
index 34f2b371015c19fddfe62e04e52a710d93008925..3dd58c8921dc7e68ebdefed452f8af424f8556a5 100644 (file)
@@ -15,7 +15,8 @@ Pypi page:  https://pypi.org/project/nutra
 Building the database
 #########################
 
-1. If you are committing database changes, add a line to ``data/version.csv`` (e.g. ``id=4`` is the latest in this case),
+1. If you are committing database changes, add a line to ``data/version.csv``
+   (e.g. ``id=4`` is the latest in this case),
 
 +-----+----------+-------------+------------------+
 | id  | version  | created     | notes            |
@@ -41,7 +42,8 @@ Building the database
 
     make test
 
-4. If everything looks good, commit and update submodules in the ``cli`` (python) and ``nt-android`` (java) repos.
+4. If everything looks good, commit and update submodules in the
+   ``cli`` (python) and ``nt-android`` (java) repos.
 
 
 Tables (Relational Design)
index 5153e113ab60cadf70f9b8b426e743a7d829a7e1..4f1af3050604d43013921646370375433d6a539c 100644 (file)
 <!-- profiles -->
 <g id="node4" class="node">
 <title>profiles</title>
-<path fill="none" stroke="black" d="M413.74,-659.67C413.74,-659.67 533.74,-659.67 533.74,-659.67 539.74,-659.67 545.74,-665.67 545.74,-671.67 545.74,-671.67 545.74,-870.67 545.74,-870.67 545.74,-876.67 539.74,-882.67 533.74,-882.67 533.74,-882.67 413.74,-882.67 413.74,-882.67 407.74,-882.67 401.74,-876.67 401.74,-870.67 401.74,-870.67 401.74,-671.67 401.74,-671.67 401.74,-665.67 407.74,-659.67 413.74,-659.67"/>
-<text text-anchor="start" x="445.74" y="-862.27" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="13.00">profiles</text>
-<polyline fill="none" stroke="black" points="401.74,-852.67 545.74,-852.67 "/>
-<text text-anchor="start" x="408.74" y="-838.57" font-family="Helvetica,sans-Serif" font-size="12.00">id* </text>
-<text text-anchor="start" x="429.74" y="-838.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">integer</text>
-<text text-anchor="start" x="408.74" y="-821.57" font-family="Helvetica,sans-Serif" font-size="12.00">name </text>
-<text text-anchor="start" x="447.74" y="-821.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">text</text>
-<text text-anchor="start" x="408.74" y="-804.57" font-family="Helvetica,sans-Serif" font-size="12.00">eula </text>
-<text text-anchor="start" x="438.74" y="-804.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
-<text text-anchor="start" x="408.74" y="-787.57" font-family="Helvetica,sans-Serif" font-size="12.00">gender </text>
-<text text-anchor="start" x="455.74" y="-787.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">text</text>
-<text text-anchor="start" x="408.74" y="-770.57" font-family="Helvetica,sans-Serif" font-size="12.00">dob </text>
-<text text-anchor="start" x="435.74" y="-770.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">date</text>
-<text text-anchor="start" x="408.74" y="-753.57" font-family="Helvetica,sans-Serif" font-size="12.00">act_lvl </text>
-<text text-anchor="start" x="450.74" y="-753.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
-<text text-anchor="start" x="408.74" y="-736.57" font-family="Helvetica,sans-Serif" font-size="12.00">goal_wt </text>
-<text text-anchor="start" x="458.74" y="-736.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">real</text>
-<text text-anchor="start" x="408.74" y="-719.57" font-family="Helvetica,sans-Serif" font-size="12.00">goal_bf </text>
-<text text-anchor="start" x="456.74" y="-719.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">real</text>
-<text text-anchor="start" x="408.74" y="-702.57" font-family="Helvetica,sans-Serif" font-size="12.00">bmr_eq_id </text>
-<text text-anchor="start" x="475.74" y="-702.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
-<text text-anchor="start" x="408.74" y="-685.57" font-family="Helvetica,sans-Serif" font-size="12.00">bf_eq_id </text>
-<text text-anchor="start" x="462.74" y="-685.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
-<text text-anchor="start" x="408.74" y="-668.57" font-family="Helvetica,sans-Serif" font-size="12.00">created </text>
-<text text-anchor="start" x="458.74" y="-668.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
+<path fill="none" stroke="black" d="M413.74,-668.17C413.74,-668.17 533.74,-668.17 533.74,-668.17 539.74,-668.17 545.74,-674.17 545.74,-680.17 545.74,-680.17 545.74,-862.17 545.74,-862.17 545.74,-868.17 539.74,-874.17 533.74,-874.17 533.74,-874.17 413.74,-874.17 413.74,-874.17 407.74,-874.17 401.74,-868.17 401.74,-862.17 401.74,-862.17 401.74,-680.17 401.74,-680.17 401.74,-674.17 407.74,-668.17 413.74,-668.17"/>
+<text text-anchor="start" x="445.74" y="-853.77" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="13.00">profiles</text>
+<polyline fill="none" stroke="black" points="401.74,-844.17 545.74,-844.17 "/>
+<text text-anchor="start" x="408.74" y="-830.57" font-family="Helvetica,sans-Serif" font-size="12.00">id* </text>
+<text text-anchor="start" x="429.74" y="-830.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">integer</text>
+<text text-anchor="start" x="408.74" y="-813.57" font-family="Helvetica,sans-Serif" font-size="12.00">name </text>
+<text text-anchor="start" x="447.74" y="-813.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">text</text>
+<text text-anchor="start" x="408.74" y="-796.57" font-family="Helvetica,sans-Serif" font-size="12.00">gender </text>
+<text text-anchor="start" x="455.74" y="-796.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">text</text>
+<text text-anchor="start" x="408.74" y="-779.57" font-family="Helvetica,sans-Serif" font-size="12.00">dob </text>
+<text text-anchor="start" x="435.74" y="-779.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">date</text>
+<text text-anchor="start" x="408.74" y="-762.57" font-family="Helvetica,sans-Serif" font-size="12.00">act_lvl </text>
+<text text-anchor="start" x="450.74" y="-762.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
+<text text-anchor="start" x="408.74" y="-745.57" font-family="Helvetica,sans-Serif" font-size="12.00">goal_wt </text>
+<text text-anchor="start" x="458.74" y="-745.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">real</text>
+<text text-anchor="start" x="408.74" y="-728.57" font-family="Helvetica,sans-Serif" font-size="12.00">goal_bf </text>
+<text text-anchor="start" x="456.74" y="-728.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">real</text>
+<text text-anchor="start" x="408.74" y="-711.57" font-family="Helvetica,sans-Serif" font-size="12.00">bmr_eq_id </text>
+<text text-anchor="start" x="475.74" y="-711.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
+<text text-anchor="start" x="408.74" y="-694.57" font-family="Helvetica,sans-Serif" font-size="12.00">bf_eq_id </text>
+<text text-anchor="start" x="462.74" y="-694.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
+<text text-anchor="start" x="408.74" y="-677.57" font-family="Helvetica,sans-Serif" font-size="12.00">created </text>
+<text text-anchor="start" x="458.74" y="-677.57" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
 </g>
 <!-- profiles&#45;&gt;bmr_eqs -->
 <g id="edge2" class="edge">
 <!-- biometric_log&#45;&gt;profiles -->
 <g id="edge3" class="edge">
 <title>biometric_log&#45;&gt;profiles</title>
-<path fill="none" stroke="black" stroke-width="0.9" d="M543.09,-1047.44C531.86,-1002.69 516.93,-943.22 503.8,-890.92"/>
-<polygon fill="black" stroke="black" stroke-width="0.9" points="506.45,-890 501.79,-882.92 501.02,-891.36 506.45,-890"/>
+<path fill="none" stroke="black" stroke-width="0.9" d="M543.09,-1047.44C531.22,-1000.16 515.23,-936.45 501.59,-882.11"/>
+<polygon fill="black" stroke="black" stroke-width="0.9" points="504.26,-881.25 499.59,-874.17 498.83,-882.61 504.26,-881.25"/>
 </g>
 <!-- bio_log_entry -->
 <g id="node7" class="node">
 <!-- food_log&#45;&gt;profiles -->
 <g id="edge9" class="edge">
 <title>food_log&#45;&gt;profiles</title>
-<path fill="none" stroke="black" stroke-width="0.9" d="M443.24,-552.15C447.53,-583 452.45,-618.34 457.07,-651.51"/>
-<polygon fill="black" stroke="black" stroke-width="0.9" points="454.3,-651.9 458.18,-659.44 459.85,-651.13 454.3,-651.9"/>
+<path fill="none" stroke="black" stroke-width="0.9" d="M443.24,-552.15C447.9,-585.67 453.31,-624.5 458.26,-660.07"/>
+<polygon fill="black" stroke="black" stroke-width="0.9" points="455.5,-660.54 459.38,-668.08 461.05,-659.77 455.5,-660.54"/>
 </g>
 <!-- food_log&#45;&gt;meal_name -->
 <g id="edge8" class="edge">
 <text text-anchor="start" x="673.07" y="-614.54" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="13.00">food_costs</text>
 <polyline fill="none" stroke="black" points="640.07,-604.94 784.07,-604.94 "/>
 <text text-anchor="start" x="647.07" y="-590.84" font-family="Helvetica,sans-Serif" font-size="12.00">food_id* </text>
-<text text-anchor="start" x="701.07" y="-590.84" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">integer</text>
+<text text-anchor="start" x="701.07" y="-590.84" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
 <text text-anchor="start" x="647.07" y="-573.84" font-family="Helvetica,sans-Serif" font-size="12.00">profile_id* </text>
-<text text-anchor="start" x="711.07" y="-573.84" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">integer</text>
+<text text-anchor="start" x="711.07" y="-573.84" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">int</text>
 <text text-anchor="start" x="647.07" y="-556.84" font-family="Helvetica,sans-Serif" font-size="12.00">cost </text>
 <text text-anchor="start" x="676.07" y="-556.84" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="12.00">real</text>
 </g>
index 0c6c92e4c853ba69c428e0d82340e6db3628c4c5..64d209a41df0a13af8e458e7849508225ba99ed2 100755 (executable)
@@ -45,6 +45,8 @@ def build_ntsqlite(verbose=False):
             query = "INSERT INTO {0} VALUES ({1});".format(  # nosec: B608
                 table_name, values
             )
+            print(query)
+            exit()
             cur.executemany(query, reader)
 
     cur.close()
index 1770cf003e75fbe05142b916573e3089d1a7be2a..01cdf9f0449804fbe7b9d08000ca1223db601eb6 100644 (file)
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-CREATE TABLE version( id integer PRIMARY KEY AUTOINCREMENT, version text NOT NULL UNIQUE, created date NOT NULL, notes text
+CREATE TABLE `version` (
+  id integer PRIMARY KEY AUTOINCREMENT,
+  `version` text NOT NULL UNIQUE,
+  created date NOT NULL,
+  notes text
 );
 
 -- TODO: enforce FK constraint across two DBs?
@@ -25,12 +29,12 @@ CREATE TABLE version( id integer PRIMARY KEY AUTOINCREMENT, version text NOT NUL
 
 CREATE TABLE bmr_eqs (
   id integer PRIMARY KEY AUTOINCREMENT,
-  name text NOT NULL
+  name text NOT NULL UNIQUE
 );
 
 CREATE TABLE bf_eqs (
   id integer PRIMARY KEY AUTOINCREMENT,
-  name text NOT NULL
+  name text NOT NULL UNIQUE
 );
 
 --
@@ -41,7 +45,6 @@ CREATE TABLE bf_eqs (
 CREATE TABLE profiles (
   id integer PRIMARY KEY AUTOINCREMENT,
   name text NOT NULL UNIQUE,
-  eula int DEFAULT 0,
   gender text,
   dob date,
   act_lvl int DEFAULT 2, -- [1, 2, 3, 4, 5]
@@ -50,7 +53,6 @@ CREATE TABLE profiles (
   bmr_eq_id int DEFAULT 1,
   bf_eq_id int DEFAULT 1,
   created int DEFAULT (strftime ('%s', 'now')),
-  -- last_active timestamp?
   FOREIGN KEY (bmr_eq_id) REFERENCES bmr_eqs (id) ON UPDATE CASCADE,
   FOREIGN KEY (bf_eq_id) REFERENCES bf_eqs (id) ON UPDATE CASCADE
 );