### Install Openweight SDK Source: https://github.com/radupana/openweight/blob/main/docs/guide/getting-started.md Installs the openweight SDK package for use in JavaScript/TypeScript projects. Supports npm, pnpm, and yarn package managers. ```bash npm install @openweight/sdk ``` ```bash pnpm add @openweight/sdk ``` ```bash yarn add @openweight/sdk ``` -------------------------------- ### Validate OpenWeight Examples Locally (Bash) Source: https://github.com/radupana/openweight/blob/main/docs/examples/index.md This snippet shows how to clone the openweight repository, navigate into the directory, install dependencies, and run the validation script for the examples. It's a prerequisite for local development and testing. ```bash git clone https://github.com/radupana/openweight.git cd openweight npm install npm run validate-examples ``` -------------------------------- ### Install and Use openweight SDK (TypeScript/JavaScript) Source: https://github.com/radupana/openweight/blob/main/README.md Instructions for installing the openweight SDK using npm and a code example demonstrating how to parse and access data from a workout log in TypeScript. This SDK facilitates programmatic interaction with openweight data. ```bash npm install @openweight/sdk ``` ```typescript import {parseWorkoutLog, isValidWorkoutLog} from '@openweight/sdk'; const log = parseWorkoutLog(jsonString); console.log(log.exercises[0].exercise.name); // "Squat" ``` -------------------------------- ### Minimal Workout Template Example (JSON) Source: https://github.com/radupana/openweight/blob/main/docs/examples/workout-templates.md Demonstrates the most basic valid workout template structure, requiring only a name and a single exercise with its sets. This serves as a starting point for creating new templates. ```json { "name": "Push Day", "exercises": [ { "exercise": { "name": "Bench Press" }, "sets": [ { "targetReps": 5 }, { "targetReps": 5 }, { "targetReps": 5 } ] } ] } ``` -------------------------------- ### Install @openweight/sdk Source: https://github.com/radupana/openweight/blob/main/packages/ts-sdk/README.md Installs the @openweight/sdk package using npm. This is the first step to using the SDK in your project. ```bash npm install @openweight/sdk ``` -------------------------------- ### Install and Use openweight SDK (Kotlin/JVM) Source: https://github.com/radupana/openweight/blob/main/README.md Instructions for adding the openweight SDK dependency for Kotlin/JVM projects and a code example showing how to parse workout log data. This enables developers to work with openweight data in their JVM applications. ```kotlin implementation("io.github.radupana:openweight-sdk:0.4.0") ``` ```kotlin val log = parseWorkoutLog(jsonString) println(log.exercises[0].exercise.name) // "Squat" ``` -------------------------------- ### Example: Simple Strength Program (JSON) Source: https://github.com/radupana/openweight/blob/main/docs/schema/program.md An example of a basic 3-day strength training program structured according to the Program schema. It includes program metadata and a single week with two workout days. ```json { "name": "Simple Strength", "description": "A basic 3-day strength program", "author": "Coach Smith", "tags": ["strength", "beginner", "3-day"], "weeks": [ { "name": "Week 1", "workouts": [ { "name": "Day A - Squat", "day": 1, "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "targetReps": 5, "targetWeight": 100, "unit": "kg" } ] } ] }, { "name": "Day B - Bench", "day": 3, "exercises": [ { "exercise": { "name": "Bench Press" }, "sets": [ { "targetReps": 5, "targetWeight": 80, "unit": "kg" } ] } ] } ] } ] } ``` -------------------------------- ### Workout Template with Rep Ranges Example (JSON) Source: https://github.com/radupana/openweight/blob/main/docs/examples/workout-templates.md Demonstrates how to use rep ranges for flexible programming, particularly useful for hypertrophy-focused training. This example includes target reps, minimum and maximum reps, and RPE. ```json { "name": "Hypertrophy Day", "exercises": [ { "exercise": { "name": "Lat Pulldown" }, "sets": [ { "targetRepsMin": 8, "targetRepsMax": 12, "targetRPE": 8 }, { "targetRepsMin": 8, "targetRepsMax": 12, "targetRPE": 8 }, { "targetRepsMin": 8, "targetRepsMax": 12, "targetRPE": 9 } ] } ] } ``` -------------------------------- ### Example: 5/3/1 BBB Program (JSON) Source: https://github.com/radupana/openweight/blob/main/docs/schema/program.md A comprehensive example of Jim Wendler's 5/3/1 Boring But Big program, structured over 4 weeks. This demonstrates percentage-based loading and AMRAP sets within the Program schema. ```json { "name": "5/3/1 Boring But Big", "description": "Jim Wendler's 5/3/1 with BBB assistance", "author": "Jim Wendler", "tags": ["strength", "intermediate", "4-day", "531"], "weeks": [ { "name": "Week 1 - 5s", "workouts": [ { "name": "Squat Day", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "percentage": 65, "percentageOf": "TM", "targetReps": 5 }, { "percentage": 75, "percentageOf": "TM", "targetReps": 5 }, { "percentage": 85, "percentageOf": "TM", "targetReps": 5, "type": "amrap" } ] } ] } ] }, { "name": "Week 2 - 3s", "workouts": [ { "name": "Squat Day", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "percentage": 70, "percentageOf": "TM", "targetReps": 3 }, { "percentage": 80, "percentageOf": "TM", "targetReps": 3 }, { "percentage": 90, "percentageOf": "TM", "targetReps": 3, "type": "amrap" } ] } ] } ] }, { "name": "Week 3 - 5/3/1", "workouts": [ { "name": "Squat Day", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "percentage": 75, "percentageOf": "TM", "targetReps": 5 }, { "percentage": 85, "percentageOf": "TM", "targetReps": 3 }, { "percentage": 95, "percentageOf": "TM", "targetReps": 1, "type": "amrap" } ] } ] } ] }, { "name": "Week 4 - Deload", "notes": "Reduce volume, focus on recovery", "workouts": [ { "name": "Squat Day", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "percentage": 40, "percentageOf": "TM", "targetReps": 5 }, { "percentage": 50, "percentageOf": "TM", "targetReps": 5 }, { "percentage": 60, "percentageOf": "TM", "targetReps": 5 } ] } ] } ] } ] } ``` -------------------------------- ### 5/3/1 Boring But Big JSON Program Example Source: https://github.com/radupana/openweight/blob/main/docs/examples/programs.md An excerpt from the 5/3/1 Boring But Big program, showcasing percentage-based loading, AMRAP sets, and supplemental BBB accessory work. This example focuses on the squat day of Week 1. ```json { "name": "5/3/1 Boring But Big", "description": "Jim Wendler's 5/3/1 program with Boring But Big supplemental work. A 4-week cycle focusing on the four main lifts with 5x10 volume work.", "author": "Jim Wendler", "tags": ["strength", "powerlifting", "intermediate"], "weeks": [ { "name": "Week 1 - 3x5", "notes": "Working sets at 65%, 75%, 85% of training max", "workouts": [ { "name": "Squat Day", "day": 1, "exercises": [ { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell", "category": "legs" }, "order": 1, "sets": [ { "type": "working", "targetReps": 5, "percentage": 65, "percentageOf": "1RM", "restSeconds": 180 }, { "type": "working", "targetReps": 5, "percentage": 75, "percentageOf": "1RM", "restSeconds": 180 }, { "type": "working", "targetReps": 5, "percentage": 85, "percentageOf": "1RM", "notes": "AMRAP", "restSeconds": 180 } ] }, { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell", "category": "legs" }, "order": 2, "notes": "BBB sets", "sets": [ { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 } ] }, { "exercise": { "name": "Leg Curl", "equipment": "machine", "category": "legs" }, "order": 3, "sets": [ { "targetRepsMin": 10, "targetRepsMax": 15 }, { "targetRepsMin": 10, "targetRepsMax": 15 }, { "targetRepsMin": 10, "targetRepsMax": 15 } ] } ] } ] } ] } ``` -------------------------------- ### Percentage-Based Workout Template Example (JSON) Source: https://github.com/radupana/openweight/blob/main/docs/examples/workout-templates.md Illustrates a 5/3/1 style workout template using percentage-based loading relative to a 1RM. It showcases features like warmup and working sets, rep ranges, rest periods, and exercise ordering. ```json { "name": "531 Week 1 Squat Day", "notes": "Wendler 5/3/1 week 1 - 3x5 at 65/75/85%", "exercises": [ { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell", "category": "legs" }, "order": 1, "sets": [ { "type": "warmup", "targetReps": 5, "percentage": 40, "percentageOf": "1RM" }, { "type": "warmup", "targetReps": 5, "percentage": 50, "percentageOf": "1RM" }, { "type": "warmup", "targetReps": 3, "percentage": 60, "percentageOf": "1RM" }, { "type": "working", "targetReps": 5, "percentage": 65, "percentageOf": "1RM", "restSeconds": 180 }, { "type": "working", "targetReps": 5, "percentage": 75, "percentageOf": "1RM", "restSeconds": 180 }, { "type": "working", "targetReps": 5, "percentage": 85, "percentageOf": "1RM", "notes": "AMRAP on last set", "restSeconds": 180 } ] }, { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell", "category": "legs" }, "order": 2, "notes": "BBB supplemental - 5x10 at 50%", "sets": [ { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 }, { "targetReps": 10, "percentage": 50, "percentageOf": "1RM", "restSeconds": 90 } ] }, { "exercise": { "name": "Leg Curl", "equipment": "machine", "category": "legs" }, "order": 3, "sets": [ { "targetRepsMin": 10, "targetRepsMax": 15 }, { "targetRepsMin": 10, "targetRepsMax": 15 }, { "targetRepsMin": 10, "targetRepsMax": 15 } ] }, { "exercise": { "name": "Ab Wheel Rollout", "equipment": "bodyweight", "category": "core" }, "order": 4, "sets": [ { "targetRepsMin": 10, "targetRepsMax": 20 }, { "targetRepsMin": 10, "targetRepsMax": 20 }, { "targetRepsMin": 10, "targetRepsMax": 20 } ] } ] } ``` -------------------------------- ### Workout Template with Absolute Weights Example (JSON) Source: https://github.com/radupana/openweight/blob/main/docs/examples/workout-templates.md Shows how to define workout templates with fixed weights for each set. This is suitable for programs where specific absolute loads are prescribed, including the unit of measurement. ```json { "name": "Fixed Weight Day", "exercises": [ { "exercise": { "name": "Bench Press" }, "sets": [ { "targetReps": 5, "targetWeight": 100, "unit": "kg" }, { "targetReps": 5, "targetWeight": 100, "unit": "kg" }, { "targetReps": 5, "targetWeight": 100, "unit": "kg" } ] } ] } ``` -------------------------------- ### WorkoutTemplate JSON Example Source: https://github.com/radupana/openweight/blob/main/docs/schema/workout-template.md An example JSON object representing a complete workout template, including multiple exercises and sets with percentage-based loading and warm-up sets. ```json { "name": "Squat Day", "day": 1, "exercises": [ { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell", "category": "legs" }, "sets": [ { "percentage": 65, "percentageOf": "1RM", "targetReps": 5, "type": "warmup", "restSeconds": 180 }, { "percentage": 75, "percentageOf": "1RM", "targetReps": 5, "restSeconds": 180 }, { "percentage": 85, "percentageOf": "1RM", "targetReps": 5, "restSeconds": 180 }, { "percentage": 85, "percentageOf": "1RM", "targetReps": 5, "type": "amrap", "restSeconds": 180 } ] }, { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell" }, "notes": "BBB sets", "sets": [ { "percentage": 50, "percentageOf": "1RM", "targetReps": 10 }, { "percentage": 50, "percentageOf": "1RM", "targetReps": 10 }, { "percentage": 50, "percentageOf": "1RM", "targetReps": 10 }, { "percentage": 50, "percentageOf": "1RM", "targetReps": 10 }, { "percentage": 50, "percentageOf": "1RM", "targetReps": 10 } ] } ] } ``` -------------------------------- ### JSON Program Metadata Structure Source: https://github.com/radupana/openweight/blob/main/docs/examples/programs.md Demonstrates the structure for including rich metadata within a program definition. This includes fields for name, description, author, and tags, allowing for better organization and discoverability of training programs. ```json { "name": "My Custom Program", "description": "A 6-week hypertrophy block", "author": "Coach Smith", "tags": ["hypertrophy", "intermediate", "6-week", "upper-lower"], "weeks": [...] } ``` -------------------------------- ### Workout Log Example (JSON) Source: https://github.com/radupana/openweight/blob/main/README.md A sample JSON object representing a completed workout log, including date, exercises, sets, reps, weight, unit, and RPE. This serves as a basic example of the openweight format. ```json { "$schema": "https://openweight.dev/schemas/workout-log.schema.json", "date": "2024-01-15T09:00:00Z", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "reps": 5, "weight": 140, "unit": "kg", "rpe": 7 }, { "reps": 5, "weight": 140, "unit": "kg", "rpe": 8 }, { "reps": 5, "weight": 140, "unit": "kg", "rpe": 8.5 } ] } ] } ``` -------------------------------- ### Add Kotlin SDK Dependency Source: https://github.com/radupana/openweight/blob/main/docs/guide/getting-started.md Adds the openweight SDK as a dependency for Android/JVM projects using Maven Central. This allows integration of workout log processing into Kotlin applications. ```kotlin dependencies { implementation("io.github.radupana:openweight-sdk:0.4.0") } ``` -------------------------------- ### WorkoutTemplate Schema Example (JSON) Source: https://context7.com/radupana/openweight/llms.txt An example of a planned workout template, specifying target sets, rep ranges, percentage-based loading, and intensity prescriptions. This schema is used for programming future training sessions. ```json { "$schema": "https://openweight.dev/schemas/workout-template.schema.json", "name": "Upper Body A", "day": 1, "exercises": [ { "exercise": { "name": "Barbell Bench Press", "equipment": "barbell", "category": "chest" }, "sets": [ { "type": "working", "targetReps": 5, "percentage": 65, "percentageOf": "1RM", "restSeconds": 180 }, { "type": "working", "targetReps": 5, "percentage": 75, "percentageOf": "1RM", "restSeconds": 180 }, { "type": "working", "targetReps": 5, "percentage": 85, "percentageOf": "1RM", "notes": "AMRAP" } ] }, { "exercise": { "name": "Dumbbell Row", "equipment": "dumbbell", "category": "back" }, "supersetId": 1, "sets": [ { "targetRepsMin": 8, "targetRepsMax": 12, "targetRPE": 8 }, { "targetRepsMin": 8, "targetRepsMax": 12, "targetRPE": 8 }, { "targetRepsMin": 8, "targetRepsMax": 12, "targetRPE": 8 } ] }, { "exercise": { "name": "Face Pull", "equipment": "cable", "category": "shoulders" }, "supersetId": 1, "sets": [ { "targetRepsMin": 15, "targetRepsMax": 20 }, { "targetRepsMin": 15, "targetRepsMax": 20 } ] } ] } ``` -------------------------------- ### Example Workout Log JSON Source: https://github.com/radupana/openweight/blob/main/docs/schema/workout-log.md This JSON object represents a single workout session, detailing the date, name, duration, exercises performed, and any relevant notes. It serves as a practical example of the data structure. ```json { "date": "2024-01-15T09:30:00Z", "name": "Push Day", "durationSeconds": 3600, "exercises": [ { "exercise": { "name": "Barbell Bench Press", "equipment": "barbell", "category": "chest" }, "sets": [ { "reps": 5, "weight": 100, "unit": "kg", "rpe": 7 }, { "reps": 5, "weight": 100, "unit": "kg", "rpe": 7.5 }, { "reps": 5, "weight": 100, "unit": "kg", "rpe": 8 } ] }, { "exercise": { "name": "Incline Dumbbell Press", "equipment": "dumbbell", "category": "chest" }, "sets": [ { "reps": 10, "weight": 30, "unit": "kg" }, { "reps": 10, "weight": 30, "unit": "kg" }, { "reps": 8, "weight": 30, "unit": "kg" } ] } ], "notes": "Felt strong today. Bench press moving well." } ``` -------------------------------- ### Minimal JSON Program Structure Source: https://github.com/radupana/openweight/blob/main/docs/examples/programs.md The smallest valid program configuration, demonstrating a single week with two distinct workouts. This serves as a basic template for defining training sessions. ```json { "name": "Simple 2-Day Split", "weeks": [ { "workouts": [ { "name": "Workout A", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "targetReps": 5 }, { "targetReps": 5 }, { "targetReps": 5 } ] }, { "exercise": { "name": "Bench Press" }, "sets": [ { "targetReps": 5 }, { "targetReps": 5 }, { "targetReps": 5 } ] } ] }, { "name": "Workout B", "exercises": [ { "exercise": { "name": "Deadlift" }, "sets": [ { "targetReps": 5 }, { "targetReps": 5 }, { "targetReps": 5 } ] }, { "exercise": { "name": "Overhead Press" }, "sets": [ { "targetReps": 5 }, { "targetReps": 5 }, { "targetReps": 5 } ] } ] } ] } ] } ``` -------------------------------- ### Create Workout with Custom Metadata (TypeScript) Source: https://github.com/radupana/openweight/blob/main/docs/guide/concepts.md This TypeScript example demonstrates creating a `WorkoutLog` object with custom, app-specific metadata. It shows how to add custom fields to both the main workout object and individual exercises, utilizing namespaced keys like `myapp:sessionId`. ```typescript import { serializeWorkoutLogPretty, type WorkoutLog } from '@openweight/sdk' // Create a workout with custom app-specific metadata const workout: WorkoutLog = { date: new Date().toISOString(), name: 'Morning Workout', exercises: [ { exercise: { name: 'Squat' }, sets: [{ reps: 5, weight: 100, unit: 'kg' }], // Custom field on exercise 'myapp:restTimerUsed': true, }, ], // Custom fields on workout 'myapp:sessionId': 'abc123', 'myapp:gymLocation': 'Downtown Gym', 'myapp:mood': 'energetic', 'myapp:heartRateData': { avg: 142, max: 165, zones: [10, 25, 40, 20, 5], }, } const json = serializeWorkoutLogPretty(workout) // Custom fields are preserved in the JSON output ``` -------------------------------- ### WorkoutLog Schema Example (JSON) Source: https://context7.com/radupana/openweight/llms.txt An example of a completed strength training session log, including exercises, sets, reps, weight, RPE, and optional metadata like tempo and rest periods. This schema is used to record the details of a finished workout. ```json { "$schema": "https://openweight.dev/schemas/workout-log.schema.json", "date": "2024-01-23T10:00:00+01:00", "name": "Complete Feature Demo", "notes": "This workout uses all optional fields", "durationSeconds": 5400, "exercises": [ { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell", "category": "legs", "musclesWorked": ["quadriceps", "glutes", "hamstrings", "core"] }, "order": 1, "notes": "Focus on depth and control", "sets": [ { "reps": 5, "weight": 60, "unit": "kg", "type": "warmup", "restSeconds": 60 }, { "reps": 5, "weight": 80, "unit": "kg", "type": "warmup", "restSeconds": 90 }, { "reps": 5, "weight": 100, "unit": "kg", "rpe": 7, "restSeconds": 180 }, { "reps": 5, "weight": 105, "unit": "kg", "rpe": 8, "tempo": "2-0-1-0", "restSeconds": 180 }, { "reps": 5, "weight": 105, "unit": "kg", "rpe": 8.5, "rir": 2 } ] }, { "exercise": { "name": "Plank", "equipment": "bodyweight", "category": "core" }, "sets": [ { "durationSeconds": 60, "rpe": 6 }, { "durationSeconds": 45, "rpe": 7 } ] }, { "exercise": { "name": "Farmer Walk", "equipment": "dumbbell", "category": "full-body" }, "sets": [ { "weight": 40, "unit": "kg", "distance": 40, "distanceUnit": "m", "durationSeconds": 35 } ] }, { "exercise": { "name": "Leg Press", "equipment": "machine", "category": "legs" }, "sets": [ { "reps": 20, "weight": 150, "unit": "kg", "type": "amrap", "toFailure": true } ] } ] } ``` -------------------------------- ### LifterProfile JSON Example Source: https://github.com/radupana/openweight/blob/main/docs/schema/lifter-profile.md An example JSON object representing a lifter's profile. It includes personal details, bodyweight history, exercise records, and normalized scores. ```json { "exportedAt": "2024-01-15T10:00:00Z", "name": "John", "sex": "male", "birthDate": "1990-05-15", "height": { "value": 180, "unit": "cm" }, "bodyweight": { "value": 82.5, "unit": "kg", "date": "2024-01-15" }, "bodyweightHistory": [ { "value": 82.5, "unit": "kg", "date": "2024-01-15", "notes": "Morning weigh-in" }, { "value": 83.0, "unit": "kg", "date": "2024-01-08" }, { "value": 81.5, "unit": "kg", "date": "2024-01-01" } ], "records": [ { "exercise": { "name": "Barbell Back Squat", "equipment": "barbell" }, "repMaxes": [ { "reps": 1, "weight": 180, "unit": "kg", "date": "2024-01-10", "type": "actual", "notes": "Competition PR" }, { "reps": 5, "weight": 155, "unit": "kg", "date": "2023-12-20", "type": "actual" } ], "estimated1RM": { "value": 185, "unit": "kg", "formula": "brzycki", "basedOnReps": 5, "basedOnWeight": 155 } }, { "exercise": { "name": "Plank", "equipment": "bodyweight" }, "durationPR": { "seconds": 180, "date": "2024-01-08" } } ], "normalizedScores": { "squat": { "wilks": 145.2, "dots": 148.5 }, "total": { "wilks": 406.2, "dots": 414.6 } } } ``` -------------------------------- ### Parse Workout Log with OpenWeight SDK (TypeScript) Source: https://github.com/radupana/openweight/blob/main/docs/examples/index.md This TypeScript code demonstrates how to use the @openweight/sdk to parse a workout log file. It reads a JSON file from the 'examples/workout-logs/minimal.json' path and then parses it into a workout object using the `parseWorkoutLog` function. This requires the 'fs' module for file system operations. ```typescript import {parseWorkoutLog} from '@openweight/sdk' import fs from 'fs' const json = fs.readFileSync('examples/workout-logs/minimal.json', 'utf-8') const workout = parseWorkoutLog(json) ``` -------------------------------- ### Example JSON with Version Metadata Source: https://github.com/radupana/openweight/blob/main/docs/guide/versioning.md An example of a JSON object representing workout data that includes optional version metadata. Including a 'openweight:version' field can help identify the schema version used when the data was created, aiding in compatibility checks. ```json { "date": "2024-01-15T09:30:00Z", "exercises": [...], "openweight:version": "0.2.0" } ``` -------------------------------- ### Example openweight JSON output for a workout Source: https://github.com/radupana/openweight/blob/main/docs/migrate/strong.md This JSON object represents a single workout converted from Strong format to openweight format. It includes workout details like date, name, duration, and a list of exercises, each with its sets, reps, weight, and other relevant information. ```json { "date": "2024-03-15T07:30:00.000Z", "name": "Push Day", "durationSeconds": 4380, "exercises": [ { "exercise": { "name": "Bench Press" }, "sets": [ { "reps": 5, "weight": 100, "unit": "kg", "rpe": 7 }, { "reps": 5, "weight": 100, "unit": "kg", "rpe": 8 }, { "reps": 5, "weight": 100, "unit": "kg", "rpe": 8.5 } ] }, { "exercise": { "name": "Overhead Press" }, "sets": [ { "reps": 8, "weight": 50, "unit": "kg" }, { "reps": 8, "weight": 50, "unit": "kg" }, { "reps": 7, "weight": 50, "unit": "kg" } ] } ] } ``` -------------------------------- ### Extensible JSON Schema Example Source: https://github.com/radupana/openweight/blob/main/docs/schema/index.md Demonstrates how to include custom, namespaced fields within an OpenWeight JSON Schema. This allows applications to store additional data without conflicting with future schema updates. ```json { "date": "2024-01-15T09:30:00Z", "exercises": [ ... ], "myapp:notes": "Felt strong today" } ``` -------------------------------- ### AI-Assisted CSV Conversion with OpenWeight Library (TypeScript) Source: https://github.com/radupana/openweight/blob/main/docs/cli/index.md This snippet shows how to perform AI-assisted conversion using the OpenWeight library. It initializes an AI provider (which uses OPENAI_API_KEY or OPENWEIGHT_AI_URL), detects the CSV format, and converts the data. AI suggestions are available in the report for review. It requires the '@openweight/converters' package and an AI provider setup. ```typescript import { convert, detectFormat, createAIProvider } from '@openweight/converters' import * as fs from 'fs' const csv = fs.readFileSync('export.csv', 'utf-8') const ai = await createAIProvider() // uses OPENAI_API_KEY or OPENWEIGHT_AI_URL const result = await convert({ format: detectFormat(csv), csv, weightUnit: 'kg', ai, }) // AI suggestions are in the report (not auto-applied) if (result.report.aiExerciseSuggestions?.length) { console.log('AI exercise suggestions:', result.report.aiExerciseSuggestions) } ``` -------------------------------- ### Validate OpenWeight Data with TypeScript Source: https://github.com/radupana/openweight/blob/main/packages/ts-sdk/README.md Shows how to validate OpenWeight data using the SDK. It includes getting detailed validation results with errors and using type guards for runtime data validation. Assumes data is available. ```typescript import { validateWorkoutLog, isValidWorkoutLog, validatePersonalRecords } from '@openweight/sdk' // Get detailed validation result const result = validateWorkoutLog(data) if (!result.valid) { console.log(result.errors) } // Type guard for unknown data if (isValidWorkoutLog(data)) { // data is now typed as WorkoutLog } // Validate personal records const prResult = validatePersonalRecords(data) ``` -------------------------------- ### Serialize Workout Log to JSON with TypeScript SDK Source: https://github.com/radupana/openweight/blob/main/docs/guide/getting-started.md Serializes a workout object into JSON format using the openweight SDK. Offers both a compact format for efficient storage and a pretty-printed format for readability and debugging. ```typescript import { serializeWorkoutLog, serializeWorkoutLogPretty } from '@openweight/sdk' const workout = { date: '2024-01-15T09:30:00Z', exercises: [ { exercise: { name: 'Deadlift' }, sets: [{ reps: 5, weight: 140, unit: 'kg' }] } ] } // Compact JSON (for storage/transmission) const compact = serializeWorkoutLog(workout) // Pretty JSON (for display/debugging) const pretty = serializeWorkoutLogPretty(workout) ``` -------------------------------- ### Validate Workout Data with TypeScript SDK Source: https://github.com/radupana/openweight/blob/main/docs/guide/getting-started.md Validates a workout data object against the openweight schema using the SDK. Provides both a type guard for simple validation and a detailed validation function that returns errors. ```typescript import { validateWorkoutLog, isValidWorkoutLog } from '@openweight/sdk' const data = { date: '2024-01-15T09:30:00Z', exercises: [ { exercise: { name: 'Bench Press' }, sets: [{ reps: 8, weight: 60, unit: 'kg' }] } ] } // Type guard if (isValidWorkoutLog(data)) { console.log('Valid workout!') } // Detailed validation const result = validateWorkoutLog(data) if (!result.valid) { console.log(result.errors) } ``` -------------------------------- ### Parse Workout Log with TypeScript SDK Source: https://github.com/radupana/openweight/blob/main/docs/guide/getting-started.md Parses a JSON string representing a workout log into a structured workout object using the openweight SDK. This function is essential for processing workout data within your application. ```typescript import { parseWorkoutLog } from '@openweight/sdk' const json = `{ "date": "2024-01-15T09:30:00Z", "exercises": [ { "exercise": { "name": "Squat" }, "sets": [ { "reps": 5, "weight": 100, "unit": "kg" } ] } ] }` const workout = parseWorkoutLog(json) console.log(workout.exercises[0].exercise.name) // "Squat" ``` -------------------------------- ### Convert Workout Data via CLI Source: https://github.com/radupana/openweight/blob/main/docs/guide/getting-started.md Converts workout data from a CSV export to a JSON format using the openweight CLI. This is useful for migrating data from other platforms like Strong or Hevy. No coding is required for this operation. ```bash npx @openweight/cli convert your-export.csv -o workouts.json --pretty ``` -------------------------------- ### CLI Convert Command Usage (Bash) Source: https://github.com/radupana/openweight/blob/main/docs/cli/index.md Demonstrates the basic usage of the `convert` command in the openweight CLI, specifying the input file and output file with pretty-printing enabled. Auto-detects the source format. ```bash npx @openweight/cli convert export.csv -o workouts.json --pretty ``` -------------------------------- ### openweight CLI convert command reference Source: https://github.com/radupana/openweight/blob/main/docs/migrate/strong.md This provides a reference for the 'convert' command in the openweight CLI, detailing its arguments and options. Key options include specifying the source file, weight unit, output file, pretty-printing, and generating a report. ```bash npx @openweight/cli convert [options] Options: -f, --format Source format (auto-detected from headers) -u, --weight-unit Weight unit: kg or lb (required for Strong) -o, --output Output file (default: stdout) --pretty Pretty-print JSON output --report Print conversion report to stderr ``` -------------------------------- ### Bodyweight Workout JSON Log Source: https://github.com/radupana/openweight/blob/main/docs/examples/workout-logs.md A workout log featuring bodyweight exercises, including weighted variations and failure sets. This example demonstrates how to log exercises performed without equipment and those that push to the limit. ```json { "date": "2024-01-19T07:00:00Z", "name": "Bodyweight Session", "durationSeconds": 2700, "exercises": [ { "exercise": { "name": "Pull-up", "equipment": "bodyweight", "category": "back" }, "sets": [ { "reps": 10 }, { "reps": 8 }, { "reps": 7 }, { "toFailure": true } ] }, { "exercise": { "name": "Weighted Pull-up", "equipment": "bodyweight", "category": "back" }, "sets": [ { "reps": 5, "weight": 10, "unit": "kg" }, { "reps": 5, "weight": 10, "unit": "kg" }, { "reps": 4, "weight": 10, "unit": "kg" } ] }, { "exercise": { "name": "Push-up", "equipment": "bodyweight", "category": "chest" }, "sets": [ { "reps": 20 }, { "reps": 18 }, { "reps": 15, "toFailure": true } ] } ] } ``` -------------------------------- ### AI-Assisted Data Conversion (CLI) Source: https://github.com/radupana/openweight/blob/main/README.md Command-line usage for leveraging AI to assist in converting workout data when unknown CSV columns or exercise names are encountered. It highlights the need for an OpenAI API key or a local Ollama model. ```bash # Requires OPENAI_API_KEY environment variable npx @openweight/cli convert export.csv --ai-assist --pretty # Or use a local model via Ollama OPENWEIGHT_AI_URL=http://localhost:11434/v1 npx @openweight/cli convert export.csv --ai-assist ``` -------------------------------- ### Imperial Units Lifter Profile JSON Source: https://github.com/radupana/openweight/blob/main/docs/examples/lifter-profiles.md A lifter profile example utilizing imperial units for measurements, specifically pounds (lb) for weight and inches (in) for height. This demonstrates the flexibility in unit representation within the profile structure. ```json { "exportedAt": "2024-01-15T10:00:00Z", "name": "Mike", "sex": "male", "height": { "value": 71, "unit": "in" }, "bodyweight": { "value": 200, "unit": "lb", "date": "2024-01-15" }, "records": [ { "exercise": { "name": "Squat", "equipment": "barbell" }, "repMaxes": [ { "reps": 1, "weight": 405, "unit": "lb", "date": "2024-01-10" }, { "reps": 5, "weight": 345, "unit": "lb", "date": "2024-01-05" } ] }, { "exercise": { "name": "Bench Press", "equipment": "barbell" }, "repMaxes": [ { "reps": 1, "weight": 275, "unit": "lb", "date": "2024-01-08" } ] } ] } ``` -------------------------------- ### SetTemplate JSON for Percentage Loading Source: https://github.com/radupana/openweight/blob/main/docs/schema/workout-template.md Shows how to configure a set for percentage-based training, specifying the percentage, the reference value (e.g., '1RM'), and the target repetitions. ```json { "percentage": 85, "percentageOf": "1RM", "targetReps": 5 } ``` -------------------------------- ### Piping CLI Convert Output to jq (Bash) Source: https://github.com/radupana/openweight/blob/main/docs/cli/index.md Illustrates piping the JSON output of the `convert` command to `jq` for further processing, specifically to count the number of exercises in the converted workout data. ```bash npx @openweight/cli convert export.csv | jq '.[] | .exercises | length' ``` -------------------------------- ### Create Workout Logs Programmatically with Kotlin Source: https://context7.com/radupana/openweight/llms.txt Build WorkoutLog objects directly in Kotlin for recording training sessions. This SDK allows for the programmatic creation of exercises and sets, with options to serialize the resulting object into both compact and pretty-printed JSON formats. ```kotlin import com.openweight.* import com.openweight.model.* val workout = WorkoutLog( date = "2024-01-15T09:30:00Z", name = "Push Day", durationSeconds = 3600, exercises = listOf( ExerciseLog( exercise = Exercise( name = "Barbell Bench Press", equipment = "barbell", category = "chest" ), sets = listOf( SetLog(reps = 5, weight = 80.0, unit = WeightUnit.KG, rpe = 7.0), SetLog(reps = 5, weight = 80.0, unit = WeightUnit.KG, rpe = 8.0), SetLog(reps = 5, weight = 80.0, unit = WeightUnit.KG, rpe = 8.5) ) ), ExerciseLog( exercise = Exercise(name = "Dumbbell Shoulder Press", equipment = "dumbbell"), sets = listOf( SetLog(reps = 10, weight = 20.0, unit = WeightUnit.KG), SetLog(reps = 10, weight = 20.0, unit = WeightUnit.KG), SetLog(reps = 8, weight = 20.0, unit = WeightUnit.KG, toFailure = true) ) ) ) ) // Compact JSON for API/storage val compact = serializeWorkoutLog(workout) // Pretty JSON for display val pretty = serializeWorkoutLogPretty(workout) ```