Adding bodymass support

This commit is contained in:
2025-10-21 11:21:57 +02:00
parent 090d869bad
commit 3a3d121511
5 changed files with 2604 additions and 4 deletions

26
db/readme.md Normal file
View File

@@ -0,0 +1,26 @@
## Joining to bodymass table by time
Data in the bodymass table can be transformed as (for account 1):
```sql
select kilos, time as start, (case when lead(time) over (order by time asc) is null then 'infinity'::timestamptz else lead(time) over (order by time asc) end) as end from bodymass where account=1;
```
Thereby giving a table with clear timespans. Joining can then be performed by a nested table:
```
with bm_report as (
select kilos, time as start,
(case when lead(time) over (order by time asc) is null
then 'infinity'::timestamptz
else lead(time) over (order by time asc) end) as end from bodymass
where account=1)
select
t.time, t.exercise, t.kilos, b.kilos as bodymass, round(100*t.kilos/b.kilos, 1) as ratio
from training t
inner join bm_report b on t.time >= b.start and t.time < b.end
where t.account=1 and exercise=1
order by 1;
```