better function
authorgamesguru <mathmuncher11@gmail.com>
Tue, 29 Sep 2020 20:14:24 +0000 (16:14 -0400)
committergamesguru <mathmuncher11@gmail.com>
Tue, 29 Sep 2020 20:20:11 +0000 (16:20 -0400)
sql/data/bio_log_entry.csv
sql/data/biometric_log.csv
sql/format.sh [new file with mode: 0755]
sql/functions.sql

index 5bd12c63d24c41b8bad733c4fce8102a384375a4..4961acf6a291dfd639c6680e89d2a6fa0cfb2870 100644 (file)
@@ -26,7 +26,10 @@ log_id,biometric_id,value
 9,22,62
 9,23,108
 9,24,65
+10,1,177
 10,2,67
+10,3,17.2
+10,4,21.6
 10,5,
 10,6,
 10,7,
@@ -123,3 +126,6 @@ log_id,biometric_id,value
 37,23,103
 37,24,63
 38,2,65.2
+39,3,17.5
+39,4,21.4
+40,1,178
index fae6cfee2b9fb3162ece24dea6b26857139e9fce..23c94ec0bd7804b0133e8fde5b7647ad6697b254 100644 (file)
@@ -33,7 +33,9 @@ id,guid,user_id,date,tags,notes
 32,f4cf78ea8e2c7a03892e4b0268481b59,2,Thu 24 Sep 2020 05:05:51 PM EDT,illness,
 33,63239cac4d86f57a69cf9a9c7799a13c,1,Thu 24 Sep 2020 05:05:51 PM EDT,,
 34,0ebe7d5f9214f2e62c2952696caaadd9,2,Thu 24 Sep 2020,,
-35,7a4692cf15f960c1384210fb477367a9,1,Fri 25 Sep 2020,,gym scale
+35,7a4692cf15f960c1384210fb477367a9,1,Fri 25 Sep 2020,gym scale,
 36,67e1a2d244afb9924d1999d792264109,2,Sat 26 Sep 2020,,
 37,6f61f3010e4cae1e4d46cc85302ab4d6,2,Sat 26 Sep 2020 11:54:17 AM EDT,,
-38,180eed8bc3094f634895c13331cef858,1,Tue 29 Sep 2020 03:40:37 PM EDT,,no clothes
+38,180eed8bc3094f634895c13331cef858,1,Tue 29 Sep 2020 03:40:37 PM EDT,nude,
+39,356726361e8910c5228cb659dc8fec02,1,Tue 29 Sep 2020 03:40:37 PM EDT,test,
+40,2fba6de7d11ca3337efff83b376380aa,1,Tue 29 Sep 2020 03:40:37 PM EDT,test,
diff --git a/sql/format.sh b/sql/format.sh
new file mode 100755 (executable)
index 0000000..0c90d08
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+cd "$(dirname "$0")"
+
+pg_format -s 2 tables.sql -o tables.sql
+pg_format -s 2 functions.sql -o functions.sql
index e04058761fcf2d9996247b237f3be2f711f07df6..a503c2808a365b9fdda803169328ba71f3e55152 100644 (file)
@@ -5,14 +5,7 @@
 SELECT
   users.name,
   date,
-  (
-    SELECT
-      ROUND(value * 2.204, 1)
-    FROM
-      bio_log_entry
-    WHERE
-      biometric_id = 2
-      AND log_id = biometric_log.id) AS weight,
+  ROUND(bio_log_entry.value * 2.204, 1) AS weight,
   tags,
   notes
 FROM
@@ -32,39 +25,48 @@ SELECT DISTINCT
   users.name,
   tags,
   notes,
-  (
-    SELECT
-      CAST(value AS int)
-    FROM
-      bio_log_entry
-    WHERE
-      biometric_id = 23
-      AND log_id = biometric_log.id) || '/' || (
-    SELECT
-      CAST(value AS int)
-    FROM
-      bio_log_entry
-    WHERE
-      biometric_id = 24
-      AND log_id = biometric_log.id) AS pressure,
-  (
-    SELECT
-      CAST(value AS int)
-    FROM
-      bio_log_entry
-    WHERE
-      biometric_id = 22
-      AND log_id = biometric_log.id) AS pulse
+  CAST(sys.value AS int) || '/' || CAST(dia.value AS int) AS pressure,
+  CAST(pulse.value AS int) AS pulse
 FROM
   biometric_log
   INNER JOIN users ON user_id = users.id
-  INNER JOIN bio_log_entry ON biometric_id IN (22,
-    23,
-    24)
-    AND log_id = biometric_log.id
+  INNER JOIN bio_log_entry pulse ON pulse.biometric_id = 22
+    AND pulse.log_id = biometric_log.id
+  INNER JOIN bio_log_entry sys ON sys.biometric_id = 23
+    AND sys.log_id = biometric_log.id
+  INNER JOIN bio_log_entry dia ON dia.biometric_id = 24
+    AND dia.log_id = biometric_log.id
 WHERE
   users.name = 'Mark';
 
+--------------------------------
+-- Meas, skinfolds, statics
+--------------------------------
+
+SELECT
+  date,
+  users.name,
+  height.value AS height,
+  wrist.value AS wrist,
+  ankle.value AS ankle
+FROM
+  biometric_log
+  INNER JOIN users ON user_id = users.id
+  LEFT JOIN bio_log_entry height ON height.biometric_id = 1
+    AND height.log_id = biometric_log.id
+  LEFT JOIN bio_log_entry wrist ON wrist.biometric_id = 3
+    AND wrist.log_id = biometric_log.id
+  LEFT JOIN bio_log_entry ankle ON ankle.biometric_id = 4
+    AND ankle.log_id = biometric_log.id
+WHERE
+  height.value
+  OR wrist.value
+  OR ankle.value;
+
+--------------------------------
+-- OLD: pulse/bp
+--------------------------------
+
 SELECT
   date,
   users.name,