Crates.io | my-gym-data-rust-parser |
lib.rs | my-gym-data-rust-parser |
version | 0.3.0 |
source | src |
created_at | 2024-11-12 03:55:27.079664 |
updated_at | 2024-11-13 22:00:19.60205 |
description | A Rust parser for my gym data log |
homepage | |
repository | |
max_upload_size | |
id | 1444523 |
size | 73,785 |
This is an implementation for a simple parser designed to process weight training gym workout logs, manually recorded for each exercise session. It is written using Pest library. The parser takes a txt
file as an input, where each line represents an exercise performed, and produces a structured record for each line. Each record includes details such as the date, exercise type, target number of sets and repetitions, and the real number of sets and repetitions performed, divided into separate attempts (including any variations in weight or repetitions within sets).
Each line in the log file represents a group of sets performed in one go for a single exercise and is divided into four sections, separated by the /
symbol:
DD.MM.YYYY
format.3 x 10-15
).35-15
, 25-15
). The weight is specified in kilograms.
The program will parse every line in the file into a Record
Data Structure contains information as follows:
ExerciseRecord
: Contains the date, exercise name, target reps, and a list of sets.
TargetReps
: Describes the number of sets and min-max range of reps per set.
Set
: Represents one set, which may contain multiple attempts (e.g., if the weight or reps changed during the set).
Attempt
: Specifies the weight and reps for a single attempt within a set.
Given an input file (input.txt
) with the following line:
05.08.2024 / reverse grip lat pulldown / (3 x 10-15) / 35-15,30-15;25-15;25-15
The parser generates an ExerciseRecord
with the following components:
Date: "05.08.2024"
Represents the date on which the exercise was performed, allowing the parser to associate each session with a specific day.
Exercise Name: "reverse grip lat pulldown"
Identifies the name of the exercise performed, enabling tracking of specific exercises over time.
Target Reps:
Indicates the initial goal for this exercise in terms of sets and repetitions:
3
10-15
Sets Completed:
Contains details about each set performed, which may include one or multiple attempts (if weights or reps were adjusted within the set). In this example, the parser interprets the sets as follows:
Set 1:
35kg
for 15
reps30kg
for 15
repsSet 2:
25kg
for 15
reps, meeting the target without any weight changes.Set 3:
Another single attempt with 25kg
for 15
reps, again completed without adjustments.
The full Pest grammar for the parser is defined as follows:
file = { SOI ~ (record ~ ("\r\n" | "\n")?)+ ~ EOI }
record = { date ~ "/" ~ exercise_name ~ "/" ~ target ~ "/" ~ set_group }
date = { day ~ "." ~ month ~ "." ~ year }
day = { ASCII_DIGIT{2} }
month = { ASCII_DIGIT{2} }
year = { ASCII_DIGIT{4} }
exercise_name = { (!"/" ~ ANY)+ }
target = { "(" ~ target_sets ~ "x" ~ target_min_reps ~ "-" ~ target_max_reps ~ ")" }
target_sets = { ASCII_DIGIT+ }
target_min_reps = { ASCII_DIGIT+ }
target_max_reps = { ASCII_DIGIT+ }
set_group = { set ~ (";" ~ set)* }
set = { attempt ~ ("," ~ attempt)* }
attempt = { weight ~ "-" ~ reps }
weight = { ASCII_DIGIT+ }
reps = { ASCII_DIGIT+ }
WHITESPACE = _{ " " }
Either clone this repository:
git clone <link>
cd <local-repo>
cargo build
Or add this crate to your Cargo.toml
:
[dependencies]
exercise_log_parser = "0.1.0"
You can then launch this parser with the command:
cargo run -- parse --file input.txt
This project is licensed under the MIT License.