]> git.ekhem.eu.org Git - gym.git/commitdiff
Allow querying splits.
authorJakub Czajka <jakub@ekhem.eu.org>
Sat, 6 Jan 2024 14:49:22 +0000 (15:49 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Sat, 6 Jan 2024 14:59:07 +0000 (15:59 +0100)
gym.conf
gym.css
gym.sh
split.sh [new file with mode: 0644]

index 6d7f3182f45742260ef6e3b2698efc06f9bd764e..653723233cdfe9e8b22d05fdf628fe638ebbdfc0 100644 (file)
--- 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 93e7928ab632bb50cdf90ea35273cc569dc74140..37ce15f493a9d9088a6ccc1982254c749fb2c190 100644 (file)
--- 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 acdfabb4a754c3c94d670f2c6b3c522d00d1eeee..1d1ea728d33ff84f5b99154e046393ae8f3446be 100755 (executable)
--- a/gym.sh
+++ b/gym.sh
@@ -87,6 +87,16 @@ PAGE="
       <button type='submit'>Associate</button>
     </fieldset>
   </form>
+
+  <form action='/split'>
+    <fieldset>
+      <legend>Exercise categories since (split)</legend>
+      <label>
+        &#128197;<input type='date' id='date' name='date' required />
+      </label>
+      <button type='submit'>Record</>
+    </fieldset>
+  </form>
 </body>
 </html>"
 
diff --git a/split.sh b/split.sh
new file mode 100644 (file)
index 0000000..2c4299f
--- /dev/null
+++ b/split.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+# Copyright (c) 2024 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+. /etc/environment
+
+PAGE="
+<!DOCTYPE html>
+<html>
+<meta name='viewport' content='width=device-width'>
+<link rel='stylesheet' href='gym.css'>
+<head>
+  <title>Gym</title>
+</head>
+<body>
+  $(/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")
+</body>
+</html>"
+
+echo "HTTP/1.1 200 OK"
+echo "Content-Type: text/html"
+echo "${PAGE}" | sed 's/^[ \t]*//g'