From 2cff93adc52f4bab4757840523d85d3089a077ab Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Sat, 6 Jan 2024 15:49:22 +0100 Subject: [PATCH] Allow querying splits. --- gym.conf | 7 +++++++ gym.css | 4 ++++ gym.sh | 10 ++++++++++ split.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 split.sh diff --git a/gym.conf b/gym.conf index 6d7f318..6537232 100644 --- a/gym.conf +++ b/gym.conf @@ -31,6 +31,13 @@ server { fastcgi_param SCRIPT_FILENAME ${dollar}document_root/insert.sh; } + location ~ ^/split(.*) { + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param DATE ${dollar}arg_date; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/split.sh; + } + location = / { include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; diff --git a/gym.css b/gym.css index 93e7928..37ce15f 100644 --- a/gym.css +++ b/gym.css @@ -10,3 +10,7 @@ fieldset { flex-direction: column; row-gap: 5px; } +table { + background-color: #f1d18a; + width: min(400px, 100%); +} diff --git a/gym.sh b/gym.sh index acdfabb..1d1ea72 100755 --- a/gym.sh +++ b/gym.sh @@ -87,6 +87,16 @@ PAGE=" + +
+
+ Exercise categories since (split) + +
+
" diff --git a/split.sh b/split.sh new file mode 100644 index 0000000..2c4299f --- /dev/null +++ b/split.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. + +. /etc/environment + +PAGE=" + + + + + + Gym + + + $(/usr/bin/psql --user=gym_tracker --html --dbname="${GYM_DB}" --command="\ +SELECT categories.name, COUNT(*) AS exercises_per_category +FROM workouts INNER JOIN workouts_exercises + ON workouts.id = workouts_exercises.workout_id +INNER JOIN exercises_categories + ON workouts_exercises.exercise_id = exercises_categories.exercise_id +INNER JOIN categories ON exercises_categories.category_id = categories.id +WHERE date >= '${DATE}' +GROUP BY categories.id +ORDER BY categories.id") + +" + +echo "HTTP/1.1 200 OK" +echo "Content-Type: text/html" +echo "${PAGE}" | sed 's/^[ \t]*//g' -- 2.39.5