Initial commit.
This commit is contained in:
+303
@@ -0,0 +1,303 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.wow.st/gmp/logbook"
|
||||
"git.wow.st/gmp/logbook/parser"
|
||||
"git.wow.st/gmp/logbook/review"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
func expandPath(path string) string {
|
||||
if strings.HasPrefix(path, "~/") {
|
||||
home, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
return filepath.Join(home, path[2:])
|
||||
}
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, `Usage:
|
||||
lb [flags] <command> [args]
|
||||
|
||||
Commands:
|
||||
import [file] Import workouts from DSL file (or stdin if no file)
|
||||
list List all workouts in the database
|
||||
list-measurements List all measurements in the database
|
||||
performances [exercise] [variation] List past performances on specified exercise
|
||||
predict date variable Predict the value of variable on date
|
||||
delete [all][workouts][measurements] delete specified items
|
||||
|
||||
Flags:
|
||||
-db <path> Path to BoltDB database file (default: ~/.config/logbook/logbook.db)
|
||||
`)
|
||||
}
|
||||
|
||||
func getPerformances(wr *logbook.WorkoutRepository, mr *logbook.MeasurementRepository) ([]review.Performance, error) {
|
||||
pr := review.NewPerformanceRepository(wr, mr)
|
||||
filter := func(p review.Performance) bool { return true }
|
||||
switch flag.NArg() {
|
||||
case 1:
|
||||
case 2:
|
||||
filter = func(p review.Performance) bool {
|
||||
if p.Exercise == flag.Arg(1) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
filter = func(p review.Performance) bool {
|
||||
if p.Exercise == flag.Arg(1) && p.Type == flag.Arg(2) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
default:
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ps, err := pr.FindPerformances(filter)
|
||||
return ps, err
|
||||
}
|
||||
func main() {
|
||||
defaultDB := "~/.config/logbook/logbook.db"
|
||||
var dbPath string
|
||||
flag.StringVar(&dbPath, "db", defaultDB, "Path to BoltDB database file")
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbPath = expandPath(dbPath)
|
||||
|
||||
db, err := bolt.Open(dbPath, 0600, nil)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error opening database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer db.Close()
|
||||
wr, err := logbook.NewWorkoutRepository(db)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error opening workout repository: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
mr, err := logbook.NewMeasurementRepository(db)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error opening measurement repository: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cmd := flag.Arg(0)
|
||||
switch cmd {
|
||||
case "import":
|
||||
var input io.Reader
|
||||
if flag.NArg() > 1 {
|
||||
f, err := os.Open(flag.Arg(1))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error opening file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
input = f
|
||||
} else {
|
||||
input = os.Stdin
|
||||
}
|
||||
|
||||
dslBytes, err := io.ReadAll(input)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
dslText := string(dslBytes)
|
||||
|
||||
workouts, measurements, err := parser.ParseDSL(dslText)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Parse error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := wr.AddWorkoutsFromIR(workouts); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Database write error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := mr.AddMeasurementsFromIR(measurements); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Database write error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Successfully imported %d workout(s) and %d measurement(s).\n", len(workouts), len(measurements))
|
||||
|
||||
case "list":
|
||||
workouts, _, err := wr.FindWorkouts(func(w *parser.Workout) bool { return true })
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reading workouts: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(workouts) == 0 {
|
||||
fmt.Println("No workouts found.")
|
||||
return
|
||||
}
|
||||
|
||||
for _, w := range workouts {
|
||||
dateStr := w.Date.Format("2 Jan 2006")
|
||||
fmt.Printf("Workout: %s (%s) %d SetGroups.", dateStr, w.Type, len(w.SetGroups))
|
||||
if w.Note != "" {
|
||||
fmt.Printf(" \"%s\"", w.Note)
|
||||
}
|
||||
fmt.Println()
|
||||
for _, sg := range w.SetGroups {
|
||||
fmt.Printf("Setgroup: %s", sg.Exercise)
|
||||
if sg.Type != "" {
|
||||
fmt.Printf(" (%s)", sg.Type)
|
||||
}
|
||||
fmt.Printf(" %d planned sets.", len(sg.PlannedSets))
|
||||
if sg.Note != "" {
|
||||
fmt.Printf(" \"%s\"", sg.Note)
|
||||
}
|
||||
fmt.Println()
|
||||
for _, s := range sg.PlannedSets {
|
||||
fmt.Printf("Planned Set: %.0fx%d", s.Weight, s.Reps)
|
||||
if s.Note != "" {
|
||||
fmt.Printf(" (%s)", s.Note)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
if len(sg.ActualSets) > 0 {
|
||||
for _, s := range sg.ActualSets {
|
||||
fmt.Printf("Actual Set: %.0fx%d (%d RIR)", s.Weight, s.Reps, s.RIR)
|
||||
if s.Note != "" {
|
||||
fmt.Printf(" (%s)", s.Note)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "list-measurements":
|
||||
ms, err := mr.FindAll()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error finding measurements: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _,m := range(ms) {
|
||||
dateStr := m.Date.Format("2 Jan 2006")
|
||||
fmt.Printf("Measurement: %s %s = %0.1f\n", dateStr, m.Variable, m.Value)
|
||||
}
|
||||
case "performances":
|
||||
ps, err := getPerformances(wr, mr)
|
||||
if err != nil {
|
||||
fmt.Printf("Error finding performance: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, p := range (ps) {
|
||||
fmt.Printf("Performance: %v\n", p)
|
||||
}
|
||||
case "estimate": // show rep chart for an exercise
|
||||
ps, err := getPerformances(wr, mr)
|
||||
if err != nil {
|
||||
fmt.Printf("Error finding performance: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var weights, reps []float64
|
||||
var date []time.Time
|
||||
isbw := review.IsBodyweight(ps[0].Exercise, ps[0].Type)
|
||||
|
||||
for _, p := range (ps) {
|
||||
for i, w := range (p.Weights) {
|
||||
if isbw {
|
||||
w = w + p.Bodyweight
|
||||
}
|
||||
if p.RIR[i] == 0 {
|
||||
weights = append(weights, w)
|
||||
reps = append(reps, float64(p.Reps[i]))
|
||||
date = append(date, p.Times[i].UTC())
|
||||
fmt.Printf("Set: weight %0.0f, reps %0.0f\n", w, float64(p.Reps[i]))
|
||||
}
|
||||
}
|
||||
}
|
||||
a, b := review.FitPowerLaw(weights, reps, date, 14.0)
|
||||
for i := 1; i<=10; i++ {
|
||||
adj := 0.0
|
||||
if isbw {
|
||||
adj = ps[len(ps)-1].Bodyweight
|
||||
}
|
||||
fmt.Printf("%d: %0.0f\n", i, review.EstimateMaxWeight(a, b, float64(i)) - adj)
|
||||
}
|
||||
case "predict":
|
||||
if flag.NArg() != 3 {
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
dateStr := flag.Arg(1)
|
||||
date, err := time.Parse("2006-01-02", dateStr)
|
||||
if err != nil {
|
||||
fmt.Printf("Invalid date: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
variable := flag.Arg(2)
|
||||
fmt.Printf("Predicting %s for date %s\n", variable, date.Format("2006-01-02"))
|
||||
|
||||
p, err := mr.Predict(variable, date, 0.75)
|
||||
if err != nil {
|
||||
fmt.Printf("Prediction error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("%f\n",p)
|
||||
case "delete":
|
||||
if flag.NArg() != 2 {
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
switch flag.Arg(1) {
|
||||
case "workouts":
|
||||
_, ids, err := wr.FindWorkouts(func(*parser.Workout) bool { return true })
|
||||
if err != nil {
|
||||
fmt.Printf("Error finding workouts: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, id := range(ids) {
|
||||
err = wr.DeleteWorkout(id)
|
||||
if err != nil {
|
||||
fmt.Printf("Error deleting workout: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Printf("%d workouts deleted.\n", len(ids))
|
||||
case "measurements":
|
||||
ms, err := mr.FindAll()
|
||||
if err != nil {
|
||||
fmt.Printf("Error finding measurements: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, m := range(ms) {
|
||||
err = mr.Delete(m.ID)
|
||||
if err != nil {
|
||||
fmt.Printf("Error deleting workout: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Printf("%d measurements deleted.\n", len(ms))
|
||||
}
|
||||
default:
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
2025-05-05 measurement bodyweight=170.4
|
||||
2025-05-02 measurement bodyweight=170.5
|
||||
2025-04-30 measurement bodyweight=172
|
||||
2025-04-28 measurement bodyweight=173.8
|
||||
2025-04-25 measurement bodyweight=170.2
|
||||
2025-04-23 measurement bodyweight=174.8
|
||||
2025-04-21 measurement bodyweight=174.5
|
||||
2025-04-16 measurement bodyweight=170.5
|
||||
2025-04-14 measurement bodyweight=172
|
||||
2025-04-11 measurement bodyweight=173
|
||||
2025-04-09 measurement bodyweight=173
|
||||
2025-04-07 measurement bodyweight=175
|
||||
2025-04-04 measurement bodyweight=174
|
||||
2025-04-02 measurement bodyweight=173
|
||||
2025-04-01 measurement bodyweight=173.5
|
||||
2025-03-27 measurement bodyweight=171
|
||||
2025-03-26 measurement bodyweight=174
|
||||
2025-03-24 measurement bodyweight=175
|
||||
2025-03-21 measurement bodyweight=174
|
||||
2025-03-19 measurement bodyweight=172
|
||||
2025-03-17 measurement bodyweight=176
|
||||
2025-03-14 measurement bodyweight=175
|
||||
2025-03-12 measurement bodyweight=175
|
||||
2025-03-10 measurement bodyweight=177
|
||||
2025-03-07 measurement bodyweight=174
|
||||
2025-03-05 measurement bodyweight=173
|
||||
2025-03-04 measurement bodyweight=175
|
||||
2025-02-28 measurement bodyweight=178
|
||||
2025-02-26 measurement bodyweight=176
|
||||
2025-02-24 measurement bodyweight=181
|
||||
2025-02-20 measurement bodyweight=176
|
||||
2025-02-14 measurement bodyweight=177
|
||||
2025-02-12 measurement bodyweight=176
|
||||
2025-02-10 measurement bodyweight=179
|
||||
2025-02-07 measurement bodyweight=178
|
||||
2025-02-05 measurement bodyweight=179
|
||||
2025-02-03 measurement bodyweight=178
|
||||
2025-01-31 measurement bodyweight=179
|
||||
2025-01-29 measurement bodyweight=178
|
||||
2025-01-27 measurement bodyweight=177
|
||||
2025-01-24 measurement bodyweight=179
|
||||
2025-01-22 measurement bodyweight=179
|
||||
2025-01-19 measurement bodyweight=176.5
|
||||
2025-01-17 measurement bodyweight=175.5
|
||||
2025-01-15 measurement bodyweight=178
|
||||
2025-01-13 measurement bodyweight=177
|
||||
2025-01-10 measurement bodyweight=176
|
||||
2025-01-08 measurement bodyweight=175.5
|
||||
2025-01-06 measurement bodyweight=177
|
||||
2025-01-03 measurement bodyweight=174
|
||||
2025-01-01 measurement bodyweight=176
|
||||
2024-12-23 measurement bodyweight=175
|
||||
2024-12-20 measurement bodyweight=173
|
||||
2024-12-18 measurement bodyweight=173
|
||||
2024-12-17 measurement bodyweight=174
|
||||
2024-12-16 measurement bodyweight=173
|
||||
2024-12-13 measurement bodyweight=171.5
|
||||
2024-12-11 measurement bodyweight=172.5
|
||||
2024-12-09 measurement bodyweight=173
|
||||
2024-12-06 measurement bodyweight=172
|
||||
2024-12-04 measurement bodyweight=171
|
||||
2024-11-22 measurement bodyweight=174
|
||||
2024-11-20 measurement bodyweight=173.5
|
||||
2024-11-18 measurement bodyweight=174
|
||||
2024-11-16 measurement bodyweight=173
|
||||
2024-11-12 measurement bodyweight=173.5
|
||||
2024-11-09 measurement bodyweight=175
|
||||
2024-11-04 measurement bodyweight=175
|
||||
2024-11-01 measurement bodyweight=174
|
||||
2024-10-30 measurement bodyweight=173.5
|
||||
2024-10-28 measurement bodyweight=175
|
||||
2024-10-25 measurement bodyweight=174
|
||||
2024-10-23 measurement bodyweight=174
|
||||
2024-10-21 measurement bodyweight=173
|
||||
2024-10-18 measurement bodyweight=172
|
||||
2024-10-15 measurement bodyweight=173
|
||||
2024-10-11 measurement bodyweight=173
|
||||
2024-10-09 measurement bodyweight=170
|
||||
2024-10-07 measurement bodyweight=171
|
||||
2024-10-02 measurement bodyweight=169.5
|
||||
2024-09-30 measurement bodyweight=171
|
||||
2024-09-27 measurement bodyweight=170.5
|
||||
2024-09-25 measurement bodyweight=169
|
||||
2024-09-23 measurement bodyweight=169
|
||||
2024-09-20 measurement bodyweight=169
|
||||
2024-09-18 measurement bodyweight=170
|
||||
2024-09-16 measurement bodyweight=172
|
||||
2024-09-13 measurement bodyweight=168
|
||||
2024-09-09 measurement bodyweight=169
|
||||
2024-09-06 measurement bodyweight=170
|
||||
2024-09-03 measurement bodyweight=170
|
||||
2024-09-02 measurement bodyweight=170
|
||||
2024-08-23 measurement bodyweight=170
|
||||
2024-08-21 measurement bodyweight=169
|
||||
2024-08-19 measurement bodyweight=170
|
||||
2024-08-16 measurement bodyweight=169
|
||||
2024-08-13 measurement bodyweight=168.5
|
||||
2024-08-09 measurement bodyweight=169
|
||||
2024-08-07 measurement bodyweight=170
|
||||
2024-08-05 measurement bodyweight=169
|
||||
2024-08-02 measurement bodyweight=167
|
||||
2024-07-31 measurement bodyweight=169
|
||||
2024-07-29 measurement bodyweight=167
|
||||
2024-07-25 measurement bodyweight=165
|
||||
2024-07-12 measurement bodyweight=168
|
||||
2024-07-08 measurement bodyweight=166
|
||||
2024-07-01 measurement bodyweight=168
|
||||
2024-06-28 measurement bodyweight=166
|
||||
2024-06-26 measurement bodyweight=167
|
||||
2024-06-24 measurement bodyweight=167
|
||||
2024-06-21 measurement bodyweight=165
|
||||
2024-06-18 measurement bodyweight=165
|
||||
2024-06-14 measurement bodyweight=167
|
||||
2024-06-12 measurement bodyweight=166
|
||||
2024-06-05 measurement bodyweight=166
|
||||
2024-06-03 measurement bodyweight=166
|
||||
2024-05-31 measurement bodyweight=169
|
||||
2024-05-13 measurement bodyweight=166
|
||||
2024-05-10 measurement bodyweight=164
|
||||
2024-05-06 measurement bodyweight=165
|
||||
2024-05-03 measurement bodyweight=164
|
||||
2024-05-01 measurement bodyweight=164
|
||||
2024-04-29 measurement bodyweight=164
|
||||
2024-04-26 measurement bodyweight=163
|
||||
2024-04-16 measurement bodyweight=164
|
||||
2024-03-16 measurement bodyweight=162
|
||||
@@ -0,0 +1,684 @@
|
||||
2025-05-09 workout
|
||||
dip 110 1x8 (AMRAP)
|
||||
8 max failed rep 9
|
||||
pushdown 65 2x12
|
||||
13-5 failed 6
|
||||
dip 70 3x8
|
||||
10 easy
|
||||
10 last rep a little hard at the top
|
||||
7 failed 8 trying to lock out each rep all the way
|
||||
chinup 75 1x5 or 6
|
||||
5 max failed rep 6 very close to the bar
|
||||
chinup 50 3x8
|
||||
8-7 failed rep 8 near the top
|
||||
6
|
||||
|
||||
2025-05-07 workout
|
||||
hack squat 90 2x10 (ATG)
|
||||
70x3-70x3-70x3
|
||||
hamstring curl 80 2x12 (single leg)
|
||||
12 max
|
||||
9
|
||||
cable crunch 150 2x12
|
||||
20 not to failure
|
||||
20
|
||||
|
||||
2025-05-05 workout (pull)
|
||||
rack pull 225 2x3
|
||||
3-3
|
||||
pullup 25 3x8
|
||||
8-8-8
|
||||
hack squat 90 2x10
|
||||
10-10
|
||||
cable crunch 150 2x10
|
||||
12-12
|
||||
hamstring curl 80 2x10 (single leg)
|
||||
12 max
|
||||
9
|
||||
|
||||
2025-05-02 workout (dip-chin)
|
||||
dip 100 1x1 AMRAP
|
||||
10 max. Failed rep 11 close to lockout
|
||||
pushdown 65 2x12
|
||||
11 max
|
||||
7
|
||||
dip 70 2x10
|
||||
8-10
|
||||
chinup 65 1x1 AMRAP
|
||||
7 max
|
||||
chinup 45 3x8
|
||||
8-8-8
|
||||
chest-supported row 135 2x15
|
||||
15-12
|
||||
|
||||
2025-04-30 workout (legs)
|
||||
hack squat 90 2x10 (ATG)
|
||||
10-10
|
||||
supine leg extension 55 2x15
|
||||
15-15
|
||||
cable crunch 140 2x15
|
||||
18-16
|
||||
hamstring curls 150 2x15
|
||||
18 max partial reps 19 and 20
|
||||
15 partial reps 16 and 17
|
||||
|
||||
2025-04-28 workout (hinge)
|
||||
deadlift 275 1x3
|
||||
3
|
||||
pullup 25 3x8
|
||||
8 easy, good control and ROM
|
||||
8 easy again
|
||||
8 hard but got chin over the bar
|
||||
chest-supported row 115 2x15
|
||||
15-15
|
||||
hack squat 110 2x0
|
||||
10-10
|
||||
hamstring curls 150 2x15
|
||||
17 max partial 18
|
||||
19 max
|
||||
cable crunch 130 2x16
|
||||
20 max
|
||||
16 partial 17
|
||||
|
||||
2025-04-25 workout (dip-chin)
|
||||
dip 90 1x1 AMRAP
|
||||
13 max
|
||||
chinup 70 1x5 AMRAP
|
||||
6 max
|
||||
chinup 45 3x8
|
||||
8-8-8
|
||||
pushdown 65 2x12
|
||||
10 max partial 11
|
||||
4 partial 5
|
||||
dip 45 1x10
|
||||
10 easy (after pushdowns)
|
||||
hack squat 110 2x10
|
||||
10-10
|
||||
supine leg extension 55 2x15
|
||||
12-15
|
||||
|
||||
2025-04-23 workout (hinge)
|
||||
deadlift 315 2x1
|
||||
1 very hard but good form
|
||||
1 grind
|
||||
RDL 225 2x8
|
||||
8 hard but not to failure
|
||||
8 hard but ok, good ROM
|
||||
hack squat 70 3x5
|
||||
5-5-5
|
||||
cable crunch 130 2x15
|
||||
20 max
|
||||
15 partial 16
|
||||
|
||||
2025-04-21 workout
|
||||
dip 150 1x1
|
||||
1 max
|
||||
dip 115 2x3
|
||||
3-3 max
|
||||
pullup 20 3x8
|
||||
8-8-8
|
||||
|
||||
2025-04-16 workout (legs)
|
||||
hack squat 105 2x10
|
||||
10-10
|
||||
cable crunch 130 2x15
|
||||
15-15
|
||||
hamstring curl 150 2x15
|
||||
17 max
|
||||
12 partial reps 13 and 14
|
||||
calf raise 270 1x40
|
||||
40
|
||||
|
||||
2025-04-14 workout (deload)
|
||||
pushdown 65 2x12
|
||||
11 max partial 12
|
||||
11 max partial 12
|
||||
cable crunch 120 2x20
|
||||
20-20
|
||||
supine leg extension 50 2x15
|
||||
20-20
|
||||
|
||||
2025-04-11 workout (dip-chin)
|
||||
dip 50 3x5
|
||||
5-5-5
|
||||
chinup 110 1x1
|
||||
1 max
|
||||
chinup 90 2x3
|
||||
3 max
|
||||
hack squat 100 2x10
|
||||
10-10
|
||||
hamstring curl 150 1x15
|
||||
14 max partial 15
|
||||
supine leg extension 50 2x15
|
||||
15
|
||||
|
||||
2025-04-09 workout (legs)
|
||||
seated leg extension 160 2x15
|
||||
20
|
||||
supine leg extension 50 1x15
|
||||
15
|
||||
reverse hyper 180 2x15
|
||||
15-15
|
||||
calf raise 270 3x30
|
||||
30-30-30
|
||||
|
||||
2025-04-07 workout
|
||||
pullup 20 3x8
|
||||
8-8-8
|
||||
hack squat 100 2x10
|
||||
10-10
|
||||
hamstring curl 140 2x15
|
||||
19 max partial 20
|
||||
13 at failure
|
||||
|
||||
2025-04-04 workout
|
||||
dip 140 1x1
|
||||
1 max
|
||||
dip 115 2x3
|
||||
3 max
|
||||
110x4 max
|
||||
chinup 105 1x1
|
||||
1 max
|
||||
chinup 90 2x3
|
||||
2 chin touched the bar but not over
|
||||
3 max
|
||||
chinup 50 3x8
|
||||
8-8 max
|
||||
6 partial 7
|
||||
hack squat 100 2x10
|
||||
10-10
|
||||
hamstring curl 140 2x15
|
||||
19 max partial 20
|
||||
16 failure partial reps 17, 18 and 19
|
||||
seated leg extension 150 2x20
|
||||
20-20
|
||||
|
||||
2025-04-02 workout stairmaster warmup, 12 minutes at level 5
|
||||
seated leg extension 150 2x15
|
||||
20-20
|
||||
hamstring curl 130 2x15
|
||||
20 max partial 21
|
||||
19 failure partial 20
|
||||
cable crunch 120 2x16
|
||||
16-16
|
||||
prayer pulldown 70 2x12
|
||||
12-12
|
||||
|
||||
2025-04-01 workout (pull)
|
||||
deadlift 275 2x1
|
||||
1 felt good but a little slow
|
||||
1 a little bit of a grind, back is ok but feels harder than it should
|
||||
RDL 225 1x5
|
||||
5
|
||||
RDL 135 1x10 (deficit)
|
||||
10
|
||||
pullup 20 2x8
|
||||
8 max
|
||||
7 failure partial 8
|
||||
hack squat 100 2x10
|
||||
10-10
|
||||
pushdown 65 2x12
|
||||
13 max partial 14
|
||||
10 at failure
|
||||
|
||||
2025-03-27 workout
|
||||
dip 135 1x1
|
||||
1 max
|
||||
dip 115 2x3
|
||||
3-3 max
|
||||
chinup 115 1x1
|
||||
0
|
||||
chinup 90 2x3
|
||||
3-3 max
|
||||
chinup 45 3x8
|
||||
8-8-9 max
|
||||
hack squat 95 2x10
|
||||
10-10
|
||||
hamstring curl 130 2x15
|
||||
18
|
||||
12 partial reps 13 and 14
|
||||
seated leg extension 150 2x15
|
||||
15-15
|
||||
cable crunch 110 2x15
|
||||
15-15
|
||||
|
||||
2025-03-26 workout
|
||||
jefferson curl 90 2x5 on blue plate
|
||||
5-5
|
||||
suitcase deadlift 90 1x5
|
||||
5
|
||||
barbell side bend 90 1x5
|
||||
5
|
||||
cable crunch 100 2x20
|
||||
15-20
|
||||
hack squat 90 2x10
|
||||
10-10
|
||||
hamstring curl 130 2x15
|
||||
20 max
|
||||
14 failure partial 15
|
||||
seated leg extension 140 2x20
|
||||
20-20
|
||||
|
||||
2025-03-24 workout
|
||||
chinup 25 3x9
|
||||
10-10 max
|
||||
hack squat 85 2x10
|
||||
10-10
|
||||
dumbbell row 120 3x12
|
||||
12-12-12 max
|
||||
|
||||
2025-03-21 workout
|
||||
dip 125 1x1
|
||||
1
|
||||
dip 45 2x10
|
||||
10-10
|
||||
jefferson curl 132 2x10
|
||||
10-10
|
||||
cable crunch 100 1x12
|
||||
12
|
||||
hack squat 80 2x10
|
||||
10-10
|
||||
hamstring curl 130 2x20
|
||||
20 max
|
||||
12 failure partial 13
|
||||
seated leg extension 140 2x15
|
||||
15-15
|
||||
|
||||
2025-03-19 workout
|
||||
jefferson curl 130 2x10
|
||||
10-10
|
||||
hack squat 80 2x10
|
||||
10-10
|
||||
hamstring curl 130 2x18
|
||||
18 max
|
||||
14 failure partial 15
|
||||
cable crunch 80 3x10
|
||||
10-10-10
|
||||
seated leg extension 140 2x15
|
||||
15-15
|
||||
|
||||
2025-03-17 workout
|
||||
jefferson curl 130 1x10
|
||||
10
|
||||
hack squat 70 2x10
|
||||
10-10
|
||||
dumbbell row 120 3x11
|
||||
11-11
|
||||
12 max partial rep 13 on right side, did 20 reps on left side
|
||||
|
||||
2025-03-14 workout
|
||||
dip 45 3x10
|
||||
10-10-10
|
||||
chinup 115 1x1
|
||||
0 missed by barely an inch
|
||||
chinup 90 2x3
|
||||
2 max partial 3
|
||||
2 max partial 3
|
||||
chinup 45 3x8
|
||||
9-9 max
|
||||
7 did not attempt rep 8
|
||||
hack squat 70 1x10
|
||||
10
|
||||
jefferson curl 110 1x10
|
||||
10
|
||||
pushdown 60 2x15
|
||||
16 max
|
||||
5 failure partial 6
|
||||
prayer pulldown 70 1x10
|
||||
9 max partial 10
|
||||
|
||||
2025-03-12 workout warmup stairmaster for 10 minutes at level 6
|
||||
hack squat 70 1x10
|
||||
10
|
||||
jefferson curl 130 1x10 (cable)
|
||||
10
|
||||
jefferson curl 95 1x5
|
||||
5
|
||||
hamstring curl 130 3x18
|
||||
18-18-10
|
||||
seated leg extension 130 3x15
|
||||
15-15-15
|
||||
wrist roller 15 2x1
|
||||
1-1
|
||||
|
||||
2025-03-10 workout
|
||||
chinup 25 3x9
|
||||
10-10 max
|
||||
8 failure partial 9 half way up
|
||||
jefferson curl 120 1x10 (cable)
|
||||
10
|
||||
prayer pulldown 70 3x10
|
||||
10-10-10
|
||||
dumbbell row 120 3x11
|
||||
11-11-11
|
||||
|
||||
2025-03-07 workout
|
||||
dip 45 3x10
|
||||
10-10-10
|
||||
chinup 110 1x1
|
||||
1 max
|
||||
chinup 90 2x2
|
||||
2 max
|
||||
2 close to a third rep
|
||||
chinup 45 3x8
|
||||
8-8-8 max
|
||||
jefferson curl 120 1x10 (cable)
|
||||
10
|
||||
hamstring curl 130 2x17
|
||||
19-17
|
||||
|
||||
2025-03-05 workout warmup stairmaster 10 minutes at level 5
|
||||
decline situp 0 2x10
|
||||
10-7 does not feel good on my low back
|
||||
prayer puldown 70 3x10
|
||||
10-10-10
|
||||
jefferson curl 110 1x10 (cable)
|
||||
10
|
||||
hamstring curl 130 3x18
|
||||
18 max
|
||||
17
|
||||
10 failure partial 11
|
||||
wrist roller 15 2x1
|
||||
1-1
|
||||
|
||||
2025-03-04 workout
|
||||
jefferson curl 70 1x5 (cable)
|
||||
5
|
||||
hack squat 70 1x10
|
||||
10 tibial tuberosity hurts
|
||||
prayer pulldown 60 1x15
|
||||
15
|
||||
|
||||
2025-02-28 workout
|
||||
dip 45 3x10
|
||||
10-10-10
|
||||
chinup 100 1x1
|
||||
1 max
|
||||
chinup 90 2x2
|
||||
2 max
|
||||
2 failure partial 3
|
||||
chinup 45 3x8
|
||||
8-8 max
|
||||
6 failure partial 7 after resetting my grip
|
||||
jefferson curl 100 1x10 (cable)
|
||||
10
|
||||
hack squat 70 2x10
|
||||
10
|
||||
10 left tibial tuberosity hurts a lot
|
||||
pushdown 60 3x15
|
||||
17 max
|
||||
15 failure partial 16
|
||||
13 failure partial 14
|
||||
decline situp 10 2x10
|
||||
9 failure partial 10
|
||||
5 failure partial 6 and did the rest of the set at bodyweight
|
||||
|
||||
2025-02-26 workout
|
||||
jefferson curl 90 1x10 (cable)
|
||||
10
|
||||
hack squat 50 3x10
|
||||
10-10-60x10
|
||||
reverse hyper 90 3x25
|
||||
25-25-25
|
||||
decline situp 0 3x15
|
||||
15
|
||||
15 not hard but feel my low back
|
||||
15 lots of low back pressure
|
||||
hamstring curl 130 3x17
|
||||
17-17
|
||||
15 partial reps 16 and 17
|
||||
|
||||
2025-02-24 workout warmup stairmaster 5 minutes at level 6
|
||||
deadlift 275 3x1
|
||||
1-1-1
|
||||
chinup 25 3x9
|
||||
9-9-9 max
|
||||
hack squat 50 2x5
|
||||
5-5
|
||||
dumbbell row 120 3x10
|
||||
10-10-10 max 12 reps on the left side
|
||||
wrist roller 15 2x1
|
||||
1
|
||||
0 failed 3/4 of the way up and finished with 10 pounds
|
||||
jefferson curl 40 1x10 (cable)
|
||||
10
|
||||
|
||||
2025-02-20 workout
|
||||
dip 100 1x3
|
||||
3 max
|
||||
dip 40 3x10
|
||||
10-10-10
|
||||
chinup 100 1x1
|
||||
0 failed almost all the way up
|
||||
chinup 90 2x2
|
||||
1 max failed partial second rep by 2 inches
|
||||
1 closer but not over the bar on second rep
|
||||
chinup 45 3x8
|
||||
8 max
|
||||
8-6
|
||||
seated leg extension 150 1x18
|
||||
18
|
||||
pushdown 60 3x15
|
||||
16 max
|
||||
14 failure partial 15
|
||||
6 failure partial 7
|
||||
|
||||
2025-02-14 workout
|
||||
dip 40 3x10
|
||||
10-10-10
|
||||
chinup 100 1x1
|
||||
1 max barely over the bar after a grind
|
||||
chinup 90 2x2
|
||||
2 max
|
||||
1
|
||||
chinup 45 3x8
|
||||
7-7-7 max
|
||||
seated leg extension 150 3x18
|
||||
18-18-18
|
||||
pushdown 60 3x15
|
||||
15 max
|
||||
13 failure partial 14
|
||||
11
|
||||
landmine deadlift 115 5x1 (grip)
|
||||
1-1-1-1-1
|
||||
landmine deadlift 90 5x1 (grip)
|
||||
1-1-1-1-1
|
||||
|
||||
2025-02-12 workout warmup stairmaster 10 minutes at level 5
|
||||
seated leg extension 150 3x15
|
||||
17-17-17
|
||||
hamstring curl 130 3x17
|
||||
17-17 max
|
||||
15 failure partial 16
|
||||
tibialis raise 100 3x20
|
||||
20-22-19
|
||||
|
||||
2025-02-10 workout
|
||||
chinup 25 3x9
|
||||
9-9-9 max
|
||||
hamstring curl 130 3x15
|
||||
15-15-15
|
||||
dumbbell row 120 3x9
|
||||
9-9-12 max got 15 on the left side
|
||||
single leg RDL 60 2x5
|
||||
5-5
|
||||
wrist roller 12.5 2x1
|
||||
1-1
|
||||
|
||||
2025-02-07 workout
|
||||
dip 40 3x10
|
||||
10-10-10
|
||||
chinup 90 3x1
|
||||
1-1-1 max
|
||||
chinup 45 3x8
|
||||
7 max
|
||||
7-6
|
||||
pinch grip 50 1x30 (seconds)
|
||||
30
|
||||
pushdown 55 1x19
|
||||
19 max partial rep 20
|
||||
60x9 partial rep 10
|
||||
5
|
||||
seated leg extension 150 3x15
|
||||
18 max
|
||||
18-15
|
||||
|
||||
2025-02-05 workout warmup stairmaster 10 minutes at level 5
|
||||
hamstring curl 130 3x15
|
||||
15-15 max
|
||||
14 partial rep 15
|
||||
supine leg extension 70 2x10
|
||||
10-10
|
||||
seated leg extension 150 3x15
|
||||
15-15-15
|
||||
tibialis raise 100 5x20
|
||||
20-22-105x15-105x4-20
|
||||
|
||||
2025-02-03 workout
|
||||
deadlift 225 3x1
|
||||
1-1-1
|
||||
chinup 25 3x10
|
||||
10 max
|
||||
9
|
||||
7 failure partial 8
|
||||
dumbbell row 120 3x8
|
||||
8-8-8
|
||||
hamstring curl 120 3x15
|
||||
15-15-15
|
||||
wrist roller 12.5 2x1
|
||||
1-1
|
||||
|
||||
2025-01-31 workout
|
||||
dip 35 3x10
|
||||
10-10-10
|
||||
chinup 90 1x1
|
||||
1 max
|
||||
chinup 45 3x6
|
||||
6 max
|
||||
6-7
|
||||
seated leg extension 140 3x20
|
||||
20-20-20
|
||||
pushdown 50 3x15
|
||||
15 max
|
||||
55x11 failure partial 12
|
||||
55x12 max failure partial 13
|
||||
|
||||
2025-01-29 workout
|
||||
RDL 225 3x10
|
||||
10-10-10
|
||||
barbell row 225 1x5
|
||||
5 partial reps, too heavy
|
||||
seated leg extension 140 3x20
|
||||
20-20-20
|
||||
pushdown 40 1x20
|
||||
20
|
||||
|
||||
2025-01-27 workout warmup stairmaster 10 minutes at level 5
|
||||
deadlift 275 3x5
|
||||
5-5-5
|
||||
deadlift 235 8x4 (EMOM)
|
||||
4-4-4-4-4-4-4-4
|
||||
wrist roller 12.5 2x1
|
||||
1-1
|
||||
|
||||
2025-01-24 workout
|
||||
seated leg extension 130 3x20
|
||||
20-20-140x20
|
||||
dip 30 3x10
|
||||
10-10-10
|
||||
chinup 30 3x8
|
||||
8-8-8 max
|
||||
pushdown 40 1x12
|
||||
12-17-45x12
|
||||
tibialis raise 95 4x20
|
||||
20-100x19-100x15-100x20
|
||||
|
||||
2025-01-22 workout warmup stairmaster 1 minutes at level 5
|
||||
seated leg extension 130 2x20
|
||||
20-20
|
||||
barbell row 185 3x8
|
||||
8-8-8
|
||||
dumbbell row 120 4x8
|
||||
8-8-8-8
|
||||
|
||||
2025-01-17 workout warmup stairmaster 10 miinutes at level 5
|
||||
seated leg extension 130 3x20
|
||||
20-20-20
|
||||
dip 30 3x10
|
||||
10-10-10
|
||||
chinup 30 3x8
|
||||
8-8-8
|
||||
|
||||
2025-01-15 workout
|
||||
seated leg extension 130 3x20
|
||||
20-20-140x20
|
||||
barbell row 175 3x8
|
||||
10-9-8
|
||||
dumbbell row 120 3x10
|
||||
12-10-10
|
||||
|
||||
2025-01-13 workout
|
||||
deadlift 275 3x4
|
||||
4-4-4
|
||||
deadlift 235 10x4 (EMOM)
|
||||
4-4-4-4-4-4-4-4-4-4
|
||||
RDL 225 3x8
|
||||
8-8-8
|
||||
triceps overhead 25 3x10
|
||||
10-10-10
|
||||
wrist roller 10 2x1
|
||||
1-12.5x1
|
||||
|
||||
2025-01-10 workout warmup stairmaster 10 minutes at level 5
|
||||
seated leg extension 120 3x20
|
||||
20-20-25
|
||||
dip 30 3x10
|
||||
10-10-10
|
||||
chinup 30 3x8
|
||||
8-8-8 max
|
||||
pushdown 45 3x10
|
||||
10-10
|
||||
9 failure partial 10
|
||||
triceps overhead 35 3x10
|
||||
10-10-10
|
||||
|
||||
2025-01-08 workout warmup stairmaster 10 minutes at level 5
|
||||
seated leg extension 120 3x20
|
||||
20-20-17
|
||||
barbell row 170 3x8
|
||||
8-8-8
|
||||
dumbbell row 105 4x12
|
||||
12-12-13-120x9
|
||||
|
||||
2025-01-06 workout
|
||||
deadlift 275 3x3
|
||||
3-3-3
|
||||
deadlift 235 10x3 (EMOM) deficit
|
||||
3-3-3-3-3-3-3-3-3-3
|
||||
RDL 235 3x8
|
||||
8-8-8
|
||||
triceps overhead 30 3x10
|
||||
10-10-10
|
||||
|
||||
2025-01-03 workout
|
||||
seated leg extension 110 3x20
|
||||
20-20-20
|
||||
dip 30 3x10
|
||||
10-10-10
|
||||
chinup 30 3x8
|
||||
8-8-8
|
||||
tibialis raise 100 4x20
|
||||
20-20-5-20
|
||||
pushdown 45 3x10
|
||||
10-10-10
|
||||
|
||||
2025-01-01 workout warmup stairmaster 10 minutes at level 5
|
||||
supine leg extension 65 4x20 (bilateral)
|
||||
20-20-20-20
|
||||
barebll row 165 3x8
|
||||
8-8-175x8
|
||||
dumbbell row 100 3x12
|
||||
12-12-12
|
||||
tibialis raise 100 4x20
|
||||
20-19-20-16
|
||||
|
||||
@@ -0,0 +1,403 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget"
|
||||
"gioui.org/widget/material"
|
||||
|
||||
bolt "github.com/etcd-io/bbolt"
|
||||
"git.wow.st/gmp/logbook"
|
||||
)
|
||||
|
||||
var (
|
||||
btnPrevWorkouts widget.Clickable
|
||||
btnPredictStrength widget.Clickable
|
||||
btnMeasurements widget.Clickable
|
||||
btnPlanWorkout widget.Clickable
|
||||
btnLeft widget.Clickable
|
||||
btnRight widget.Clickable
|
||||
list = new(layout.List) // pointer to layout.List
|
||||
)
|
||||
|
||||
type page int
|
||||
|
||||
const (
|
||||
pageLanding page = iota
|
||||
pagePlanWorkout
|
||||
)
|
||||
|
||||
func main() {
|
||||
go func() {
|
||||
window := new(app.Window)
|
||||
if err := run(window); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Exit(0)
|
||||
}()
|
||||
app.Main()
|
||||
}
|
||||
|
||||
func openStandardDB() (*bolt.DB, error) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dir := filepath.Join(usr.HomeDir, ".config", "logbook")
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbPath := filepath.Join(dir, "logbook.db")
|
||||
db, err := bolt.Open(dbPath, 0600, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func run(window *app.Window) error {
|
||||
theme := material.NewTheme()
|
||||
var ops op.Ops
|
||||
|
||||
db, err := openStandardDB()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open DB: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
workoutRepo, err := logbook.NewWorkoutRepository(db)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create workout repo: %w", err)
|
||||
}
|
||||
setRepo, err := logbook.NewSetRepository(db)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create set repo: %w", err)
|
||||
}
|
||||
|
||||
// Navigation state
|
||||
currentPage := pageLanding
|
||||
var planPage *planWorkoutPage
|
||||
|
||||
// For landing page state
|
||||
var planned []*logbook.Workout
|
||||
var workoutIdx int
|
||||
|
||||
// Preload planned workouts for landing page
|
||||
reloadPlanned := func() {
|
||||
now := time.Now()
|
||||
allWorkouts, err := workoutRepo.FindAll()
|
||||
if err != nil {
|
||||
planned = nil
|
||||
workoutIdx = 0
|
||||
return
|
||||
}
|
||||
planned = filterPlannedWorkoutsAfter(allWorkouts, now)
|
||||
sort.Slice(planned, func(i, j int) bool {
|
||||
return planned[i].Date.Before(planned[j].Date)
|
||||
})
|
||||
workoutIdx = 0
|
||||
}
|
||||
reloadPlanned()
|
||||
|
||||
for {
|
||||
e := window.Event()
|
||||
switch e := e.(type) {
|
||||
case app.DestroyEvent:
|
||||
return e.Err
|
||||
case app.FrameEvent:
|
||||
gtx := app.NewContext(&ops, e)
|
||||
|
||||
switch currentPage {
|
||||
case pageLanding:
|
||||
// Click handling flags
|
||||
planWorkoutClicked := false
|
||||
|
||||
layout.Flex{
|
||||
Axis: layout.Vertical,
|
||||
}.Layout(gtx,
|
||||
// Top navigation bar
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||
layout.Rigid(material.Button(theme, &btnPrevWorkouts, "Previous Workouts").Layout),
|
||||
layout.Rigid(material.Button(theme, &btnPredictStrength, "Predict Strength").Layout),
|
||||
layout.Rigid(material.Button(theme, &btnMeasurements, "Measurements").Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
dims := material.Button(theme, &btnPlanWorkout, "Plan Workout").Layout(gtx)
|
||||
if btnPlanWorkout.Clicked(gtx) {
|
||||
planWorkoutClicked = true
|
||||
}
|
||||
return dims
|
||||
}),
|
||||
)
|
||||
}),
|
||||
// Main content: Next planned workout
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
if len(planned) == 0 {
|
||||
return material.H5(theme, "No planned workouts.").Layout(gtx)
|
||||
}
|
||||
w := planned[workoutIdx]
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return material.H4(theme, "Next Workout: "+w.Date.Format("Mon Jan 2, 2006 3:04 PM")).Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return material.H5(theme, "Type: "+w.Type).Layout(gtx)
|
||||
}),
|
||||
// Planned sets, one per line
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
sets := getPlannedSets(setRepo, w.SetIDs)
|
||||
return list.Layout(gtx, len(sets), func(gtx layout.Context, i int) layout.Dimensions {
|
||||
set := sets[i]
|
||||
return material.Body1(theme, formatSet(set)).Layout(gtx)
|
||||
})
|
||||
}),
|
||||
)
|
||||
}),
|
||||
// Bottom navigation: left/right arrows
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
leftClicked := false
|
||||
rightClicked := false
|
||||
dims := layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
btn := material.Button(theme, &btnLeft, "←")
|
||||
if workoutIdx == 0 {
|
||||
btn.Background = color.NRGBA{A: 80}
|
||||
}
|
||||
d := btn.Layout(gtx)
|
||||
if btnLeft.Clicked(gtx) {
|
||||
leftClicked = true
|
||||
}
|
||||
return d
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
btn := material.Button(theme, &btnRight, "→")
|
||||
if workoutIdx == len(planned)-1 {
|
||||
btn.Background = color.NRGBA{A: 80}
|
||||
}
|
||||
d := btn.Layout(gtx)
|
||||
if btnRight.Clicked(gtx) {
|
||||
rightClicked = true
|
||||
}
|
||||
return d
|
||||
}),
|
||||
)
|
||||
// Handle navigation after layout
|
||||
if leftClicked && workoutIdx > 0 {
|
||||
workoutIdx--
|
||||
}
|
||||
if rightClicked && workoutIdx < len(planned)-1 {
|
||||
workoutIdx++
|
||||
}
|
||||
return dims
|
||||
}),
|
||||
)
|
||||
|
||||
// Handle navigation to Plan Workout page after layout
|
||||
if planWorkoutClicked {
|
||||
planPage = newPlanWorkoutPage()
|
||||
currentPage = pagePlanWorkout
|
||||
}
|
||||
|
||||
case pagePlanWorkout:
|
||||
planPage.Layout(gtx, theme, setRepo, workoutRepo, func() {
|
||||
reloadPlanned()
|
||||
currentPage = pageLanding
|
||||
})
|
||||
}
|
||||
|
||||
e.Frame(gtx.Ops)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func filterPlannedWorkoutsAfter(workouts []*logbook.Workout, after time.Time) []*logbook.Workout {
|
||||
var planned []*logbook.Workout
|
||||
for _, w := range workouts {
|
||||
if w.Date.After(after) {
|
||||
planned = append(planned, w)
|
||||
}
|
||||
}
|
||||
return planned
|
||||
}
|
||||
|
||||
// Use setRepo.GetByID for efficient lookup
|
||||
func getPlannedSets(setRepo *logbook.SetRepository, setIDs []string) []logbook.Set {
|
||||
var sets []logbook.Set
|
||||
for _, id := range setIDs {
|
||||
set, err := setRepo.GetByID(id)
|
||||
if err == nil && set != nil {
|
||||
sets = append(sets, *set)
|
||||
}
|
||||
}
|
||||
return sets
|
||||
}
|
||||
|
||||
func formatSet(set logbook.Set) string {
|
||||
if set.Weight > 0 {
|
||||
return fmt.Sprintf("%s: %d reps @ %.0f lb", set.Exercise, set.Reps, set.Weight)
|
||||
}
|
||||
return fmt.Sprintf("%s: %d reps (bodyweight)", set.Exercise, set.Reps)
|
||||
}
|
||||
|
||||
// --- Plan Workout Page Implementation ---
|
||||
|
||||
type planWorkoutPage struct {
|
||||
dateEditor widget.Editor
|
||||
typeEditor widget.Editor
|
||||
addSetBtn widget.Clickable
|
||||
saveBtn widget.Clickable
|
||||
sets []plannedSet
|
||||
setEditors []plannedSetEditors
|
||||
errorMsg string
|
||||
successMsg string
|
||||
backBtn widget.Clickable
|
||||
}
|
||||
|
||||
type plannedSet struct {
|
||||
Exercise string
|
||||
Reps int
|
||||
Weight float64
|
||||
}
|
||||
|
||||
type plannedSetEditors struct {
|
||||
exerciseEditor widget.Editor
|
||||
repsEditor widget.Editor
|
||||
weightEditor widget.Editor
|
||||
}
|
||||
|
||||
func newPlanWorkoutPage() *planWorkoutPage {
|
||||
p := &planWorkoutPage{}
|
||||
p.dateEditor.SingleLine = true
|
||||
p.dateEditor.SetText(time.Now().Format("2006-01-02"))
|
||||
p.typeEditor.SingleLine = true
|
||||
p.setEditors = []plannedSetEditors{newPlannedSetEditors()}
|
||||
return p
|
||||
}
|
||||
|
||||
func newPlannedSetEditors() plannedSetEditors {
|
||||
var e plannedSetEditors
|
||||
e.exerciseEditor.SingleLine = true
|
||||
e.repsEditor.SingleLine = true
|
||||
e.weightEditor.SingleLine = true
|
||||
return e
|
||||
}
|
||||
|
||||
func (p *planWorkoutPage) Layout(gtx layout.Context, th *material.Theme, setRepo *logbook.SetRepository, workoutRepo *logbook.WorkoutRepository, navBack func()) layout.Dimensions {
|
||||
var ls = new(layout.List)
|
||||
ls.Axis = layout.Vertical
|
||||
// Handle Add Set button
|
||||
if p.addSetBtn.Clicked(gtx) {
|
||||
p.setEditors = append(p.setEditors, newPlannedSetEditors())
|
||||
}
|
||||
|
||||
// Handle Save button
|
||||
if p.saveBtn.Clicked(gtx) {
|
||||
p.errorMsg = ""
|
||||
p.successMsg = ""
|
||||
// Parse date
|
||||
date, err := time.Parse("2006-01-02", p.dateEditor.Text())
|
||||
if err != nil {
|
||||
p.errorMsg = "Invalid date format (use YYYY-MM-DD)"
|
||||
} else {
|
||||
// Collect sets
|
||||
var setIDs []string
|
||||
for _, ed := range p.setEditors {
|
||||
exercise := ed.exerciseEditor.Text()
|
||||
reps, _ := parseInt(ed.repsEditor.Text())
|
||||
weight, _ := parseFloat(ed.weightEditor.Text())
|
||||
if exercise == "" || reps == 0 {
|
||||
continue // skip incomplete sets
|
||||
}
|
||||
set := &logbook.Set{
|
||||
Exercise: exercise,
|
||||
Reps: reps,
|
||||
Weight: weight,
|
||||
Date: date,
|
||||
Plan: true,
|
||||
}
|
||||
if err := setRepo.Save(set); err == nil {
|
||||
setIDs = append(setIDs, set.ID)
|
||||
}
|
||||
}
|
||||
if len(setIDs) == 0 {
|
||||
p.errorMsg = "No valid sets entered."
|
||||
} else {
|
||||
workout := &logbook.Workout{
|
||||
Date: date,
|
||||
Type: p.typeEditor.Text(),
|
||||
SetIDs: setIDs,
|
||||
}
|
||||
if err := workoutRepo.Save(workout); err != nil {
|
||||
p.errorMsg = "Failed to save workout: " + err.Error()
|
||||
} else {
|
||||
p.successMsg = "Workout planned!"
|
||||
navBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Back button
|
||||
if p.backBtn.Clicked(gtx) {
|
||||
navBack()
|
||||
}
|
||||
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||
layout.Rigid(material.H4(th, "Plan Workout").Layout),
|
||||
layout.Rigid(material.Body1(th, "Date (YYYY-MM-DD):").Layout),
|
||||
layout.Rigid(material.Editor(th, &p.dateEditor, "2025-05-05").Layout),
|
||||
layout.Rigid(material.Body1(th, "Type:").Layout),
|
||||
layout.Rigid(material.Editor(th, &p.typeEditor, "e.g. Strength, Hypertrophy").Layout),
|
||||
layout.Rigid(material.Body1(th, "Sets:").Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return ls.Layout(gtx, len(p.setEditors), func(gtx layout.Context, i int) layout.Dimensions {
|
||||
ed := &p.setEditors[i]
|
||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Inset{Right: unit.Dp(8)}.Layout(gtx, material.Editor(th, &ed.exerciseEditor, "Exercise").Layout)
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Inset{Right: unit.Dp(8)}.Layout(gtx, material.Editor(th, &ed.repsEditor, "Reps").Layout)
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return material.Editor(th, &ed.weightEditor, "Weight (lb)").Layout(gtx)
|
||||
}),
|
||||
)
|
||||
})
|
||||
}),
|
||||
layout.Rigid(material.Button(th, &p.addSetBtn, "Add Set").Layout),
|
||||
layout.Rigid(material.Button(th, &p.saveBtn, "Save Workout").Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
if p.errorMsg != "" {
|
||||
return material.Body1(th, "[Error] "+p.errorMsg).Layout(gtx)
|
||||
}
|
||||
if p.successMsg != "" {
|
||||
return material.Body1(th, p.successMsg).Layout(gtx)
|
||||
}
|
||||
return layout.Dimensions{}
|
||||
}),
|
||||
layout.Rigid(material.Button(th, &p.backBtn, "Back").Layout),
|
||||
)
|
||||
}
|
||||
|
||||
func parseInt(s string) (int, error) {
|
||||
var i int
|
||||
_, err := fmt.Sscanf(s, "%d", &i)
|
||||
return i, err
|
||||
}
|
||||
func parseFloat(s string) (float64, error) {
|
||||
var f float64
|
||||
_, err := fmt.Sscanf(s, "%f", &f)
|
||||
return f, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/widget"
|
||||
"gioui.org/widget/material"
|
||||
|
||||
bolt "github.com/etcd-io/bbolt"
|
||||
"git.wow.st/gmp/logbook"
|
||||
)
|
||||
|
||||
var (
|
||||
btnPrevWorkouts widget.Clickable
|
||||
btnPredictStrength widget.Clickable
|
||||
btnMeasurements widget.Clickable
|
||||
btnPlanWorkout widget.Clickable
|
||||
btnLeft widget.Clickable
|
||||
btnRight widget.Clickable
|
||||
list widget.List
|
||||
)
|
||||
|
||||
func main() {
|
||||
go func() {
|
||||
window := new(app.Window)
|
||||
if err := run(window); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Exit(0)
|
||||
}()
|
||||
app.Main()
|
||||
}
|
||||
|
||||
func openStandardDB() (*bolt.DB, error) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dir := filepath.Join(usr.HomeDir, ".config", "logbook")
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbPath := filepath.Join(dir, "logbook.db")
|
||||
db, err := bolt.Open(dbPath, 0600, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func run(window *app.Window) error {
|
||||
theme := material.NewTheme()
|
||||
var ops op.Ops
|
||||
|
||||
// --- Open database and repositories ---
|
||||
db, err := openStandardDB()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open DB: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
workoutRepo, err := logbook.NewWorkoutRepository(db)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create workout repo: %w", err)
|
||||
}
|
||||
setRepo, err := logbook.NewSetRepository(db)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create set repo: %w", err)
|
||||
}
|
||||
|
||||
// --- Load all planned workouts after now ---
|
||||
now := time.Now()
|
||||
allWorkouts, err := workoutRepo.FindAll()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load workouts: %w", err)
|
||||
}
|
||||
planned := filterPlannedWorkoutsAfter(allWorkouts, now)
|
||||
sort.Slice(planned, func(i, j int) bool {
|
||||
return planned[i].Date.Before(planned[j].Date)
|
||||
})
|
||||
workoutIdx := 0
|
||||
|
||||
for {
|
||||
e := window.Event()
|
||||
switch e := e.(type) {
|
||||
case app.DestroyEvent:
|
||||
return e.Err
|
||||
case app.FrameEvent:
|
||||
gtx := app.NewContext(&ops, e)
|
||||
|
||||
// Handle left/right navigation
|
||||
if btnLeft.Clicked(gtx) && workoutIdx > 0 {
|
||||
workoutIdx--
|
||||
}
|
||||
if btnRight.Clicked(gtx) && workoutIdx < len(planned)-1 {
|
||||
workoutIdx++
|
||||
}
|
||||
|
||||
layout.Flex{
|
||||
Axis: layout.Vertical,
|
||||
}.Layout(gtx,
|
||||
// Top navigation bar
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||
layout.Rigid(material.Button(theme, &btnPrevWorkouts, "Previous Workouts").Layout),
|
||||
layout.Rigid(material.Button(theme, &btnPredictStrength, "Predict Strength").Layout),
|
||||
layout.Rigid(material.Button(theme, &btnMeasurements, "Measurements").Layout),
|
||||
layout.Rigid(material.Button(theme, &btnPlanWorkout, "Plan Workout").Layout),
|
||||
)
|
||||
}),
|
||||
// Main content: Next planned workout
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
if len(planned) == 0 {
|
||||
return material.H5(theme, "No planned workouts.").Layout(gtx)
|
||||
}
|
||||
w := planned[workoutIdx]
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return material.H4(theme, "Next Workout: "+w.Date.Format("Mon Jan 2, 2006 3:04 PM")).Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return material.H5(theme, "Type: "+w.Type).Layout(gtx)
|
||||
}),
|
||||
// Planned sets, one per line
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
sets := getPlannedSets(setRepo, w.SetIDs)
|
||||
return list.Layout(gtx, len(sets), func(gtx layout.Context, i int) layout.Dimensions {
|
||||
set := sets[i]
|
||||
return material.Body1(theme, formatSet(set)).Layout(gtx)
|
||||
})
|
||||
}),
|
||||
)
|
||||
}),
|
||||
// Bottom navigation: left/right arrows
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
btn := material.Button(theme, &btnLeft, "←")
|
||||
if workoutIdx == 0 {
|
||||
btn.Background = color.NRGBA{A: 80}
|
||||
}
|
||||
return btn.Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
btn := material.Button(theme, &btnRight, "→")
|
||||
if workoutIdx == len(planned)-1 {
|
||||
btn.Background = color.NRGBA{A: 80}
|
||||
}
|
||||
return btn.Layout(gtx)
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
e.Frame(gtx.Ops)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter for planned workouts after the current date
|
||||
func filterPlannedWorkoutsAfter(workouts []*logbook.Workout, after time.Time) []*logbook.Workout {
|
||||
var planned []*logbook.Workout
|
||||
for _, w := range workouts {
|
||||
if w.Date.After(after) {
|
||||
planned = append(planned, w)
|
||||
}
|
||||
}
|
||||
return planned
|
||||
}
|
||||
|
||||
// Load planned sets for a workout from the SetRepository
|
||||
func getPlannedSets(setRepo *logbook.SetRepository, setIDs []string) []logbook.Set {
|
||||
var sets []logbook.Set
|
||||
for _, id := range setIDs {
|
||||
set, err := setRepo.GetByID(id)
|
||||
if err == nil && set != nil {
|
||||
sets = append(sets, *set)
|
||||
}
|
||||
}
|
||||
return sets
|
||||
}
|
||||
|
||||
// Format a set as a string for display
|
||||
func formatSet(set logbook.Set) string {
|
||||
if set.Weight > 0 {
|
||||
return fmt.Sprintf("%s: %d reps @ %.0f lb", set.Exercise, set.Reps, set.Weight)
|
||||
}
|
||||
return fmt.Sprintf("%s: %d reps (bodyweight)", set.Exercise, set.Reps)
|
||||
}
|
||||
Reference in New Issue
Block a user