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,
37,23,103
37,24,63
38,2,65.2
+39,3,17.5
+39,4,21.4
+40,1,178
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,
--- /dev/null
+#!/bin/bash
+
+cd "$(dirname "$0")"
+
+pg_format -s 2 tables.sql -o tables.sql
+pg_format -s 2 functions.sql -o functions.sql
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
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,