Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for power trainings and various improvements #20

Merged
merged 12 commits into from
Sep 29, 2022
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.gem
*.rbc
/.config
/coverage/
Expand Down Expand Up @@ -54,3 +53,7 @@ build-iPhoneSimulator/

# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*


/feature_diagram
*.gem
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ source 'https://rubygems.org'
gemspec

gem 'rake', '~> 13.0'
gem 'ruby-enum'
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ PATH
GEM
remote: https://rubygems.org/
specs:
concurrent-ruby (1.1.10)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
rake (13.0.6)
ruby-enum (0.9.0)
i18n

PLATFORMS
x64-mingw-ucrt
Expand All @@ -15,6 +20,7 @@ PLATFORMS
DEPENDENCIES
ast-tdl!
rake (~> 13.0)
ruby-enum

BUNDLED WITH
2.3.7
96 changes: 54 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,77 @@
## Motivation
ast-dsl is intended to be a small DSL for practical definition and description of sports training that can be automatically or manually defined and used in conjunction with Artificial Sport Trainer.

According to sports theory, three major types of sports trainings exist:
- speed trainings,
- interval trainings and
- power trainings.

Speed trainings are intended for supplying an athlete with energy, coordination and power adaptation. This type of sports training is often used by middle-distance athletes, as they can be very useful for enhancing their performance.

Interval training has been described for the first time by Reindell and Roskamm, however, it was popularized by the famous Chech athlete Emil Zatopek. This type of training consists of a speed phase that is followed by a recovery phase. This sequence is repeated for several times where the number of repetitions depends on interval training plan.

Power trainings have been proven to be an effective method for increasing muscle mass. Consequently, in most cases they are used at extreme sports, such as weight lifting, where the lactate amount in blood is significant.

## Feature diagram
![scheme](https://raw.githubusercontent.com/firefly-cpp/ast-tdl/main/.github/img/ast-tdl-feature.png)
![ast-tdl](https://user-images.githubusercontent.com/73126820/193033601-6c94b328-30a4-4b25-86a3-0fb81cebca3d.png)

## Installation
$ gem install ast-tdl
```sh
$ gem install ast-tdl
```

## Language description
Training Description Language (TDL) is implemented in Ruby. Currently, the description of sports training sessions and intervals is now supported. Those contain various data, such as duration, average heart rate, sport type, and many more.
Training Description Language (TDL) is implemented in Ruby. All three major training types (speed, interval and power) can be described in TDL.

Speed training sessions are described with their name, sport type, proposed average heart rate and total duration, while the additional information is optional.

Interval training sessions, as well as their speed counterparts, are described with their name, type of sport and optional information. However, heart rate and duration of intervals are described separately for both speed and recovery phase. Additionally, number of repetitions and interval training type are also described along with forementioned features.

Power training sessions are described with their names and sport types, but opposed to speed and interval they are described with series, which are furtherly described with their name, intensity level from 1 to 10 and number of repetitions.

## Examples
### Example of a sports training
```ruby
Ast.build('My first training') do
session('Short swimming session') do
sport :swim
info :"Very easy training"
average_heart_rate :"130"
total_duration :"30"
Ast.build do
speed('Swimming with the dolphins') do
sport Sport::SWIMMING
info :"Very easy training"
average_heart_rate :"130"
total_duration :"30"
end

session('Bike ride') do
sport :cycling
info :"Endurance ride with intervals"
average_heart_rate :"140"
total_duration :"120"
speed('Cross the country') do
sport Sport::CYCLING
info :"Endurance ride"
average_heart_rate :"140"
total_duration :"120"
end

interval('Sample interval') do
sport :cycling
info :Moderate
speed_duration :"5"
recovery_duration :"5"
interval('Following Emil Zatopek') do
sport Sport::RUNNING
info :Hard
speed_duration :"1"
recovery_duration :"1"
speed_heart_rate :"180"
recovery_heart_rate :"90"
repetitions :"10"
type :fixed
end
end
```

### Session
```ruby
session('Bike ride') do
sport :cycling
info :"Endurance ride with intervals"
average_heart_rate :"140"
total_duration :"120"
end
```

### Interval
```ruby
interval('Sample interval') do
sport :cycling
info :Moderate
speed_duration :"5"
recovery_duration :"5"
speed_heart_rate :"180"
recovery_heart_rate :"90"
repetitions :"10"
power('As strong as an ox') do
sport Sport::WEIGHT_LIFTING
series('Little ox') do
intensity: :"5"
repetitions :"20"
end
series('Big ox') do
intensity :"10"
repetitions :"80"
end
end
end
```
The description of the sports training consists of four sessions: two speed sessions, one interval sesssion and one power session. The first, swimming speed session is relatively easy, as the planned heart rate throughout the whole session is prescribed to be 130 bpm, and it lasts for half an hour. The next, cycling speed session is described as a 2-hour endurance ride with the prescribed average heart rate of 140 bpm. The third session is a hard, running interval training. It consists of 10 fixed intervals, where speed phase and recovery duration are 1 minute each. The proposed heart rate during speed phases is set at 180 bpm, while in recovery phases it is set to half the speed heart rate: 90 bpm. The final, weight lifting power session consists of two series, the first being of middle intensity with 20 repetitions and the second being of extreme intensity with 80 repetitions.

## License
This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
Expand All @@ -75,5 +86,6 @@ This package is distributed under the MIT License. This license can be found onl
This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!

## References

Fister Jr, I., Fister, I., Iglesias, A., Galvez, A., Deb, S., & Fister, D. (2021). On deploying the Artificial Sport Trainer into practice. arXiv preprint [arXiv:2109.13334](https://arxiv.org/abs/2109.13334).

Lukač, L. (2022). Aplikacija koncepta digitalnega dvojčka v športu [online]. University of Maribor, Faculty of Electrical Engineering and Computer Science. [Access: 29th September, 2022].
46 changes: 29 additions & 17 deletions examples/run_example.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
# frozen_string_literal: true

require 'ast-tdl'
require_relative '../lib/ast-tdl'

# Training description in AST-TDL domain specific language.
training = Ast.build('My first training') do
session('Short swimming session') do
sport :swim
info :"Very easy training"
average_heart_rate :"130"
total_duration :"30"
training = Ast.build do
speed('Swimming with the dolphins') do
sport Sport::SWIMMING
info :"Very easy training"
average_heart_rate :"130"
total_duration :"30"
end

session('Bike ride') do
sport :cycling
info :"Endurance ride with intervals"
average_heart_rate :"140"
total_duration :"120"
speed('Cross the country') do
sport Sport::CYCLING
info :"Endurance ride"
average_heart_rate :"140"
total_duration :"120"
end

interval('Sample interval') do
sport :cycling
info :Moderate
speed_duration :"5"
recovery_duration :"5"
interval('Following Emil Zatopek') do
sport Sport::RUNNING
info :Hard
speed_duration :"1"
recovery_duration :"1"
speed_heart_rate :"180"
recovery_heart_rate :"90"
repetitions :"10"
type :fixed
end

power('As strong as an ox') do
sport Sport::WEIGHT_LIFTING
series('Little ox') do
intensity :"5"
repetitions :"20"
end
series('Big ox') do
intensity :"10"
repetitions :"80"
end
end
end

# Printing JSON-ized training to the console.
Expand Down
46 changes: 29 additions & 17 deletions examples/save_training_to_file.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
# frozen_string_literal: true

require 'ast-tdl'
require_relative '../lib/ast-tdl'

# Training description in AST-TDL domain specific language.
training = Ast.build('My first training') do
session('Short swimming session') do
sport :swim
info :"Very easy training"
average_heart_rate :"130"
total_duration :"30"
training = Ast.build do
speed('Swimming with the dolphins') do
sport Sport::SWIMMING
info :"Very easy training"
average_heart_rate :"130"
total_duration :"30"
end

session('Bike ride') do
sport :cycling
info :"Endurance ride with intervals"
average_heart_rate :"140"
total_duration :"120"
speed('Cross the country') do
sport Sport::CYCLING
info :"Endurance ride"
average_heart_rate :"140"
total_duration :"120"
end

interval('Sample interval') do
sport :cycling
info :Moderate
speed_duration :"5"
recovery_duration :"5"
interval('Following Emil Zatopek') do
sport Sport::RUNNING
info :Hard
speed_duration :"1"
recovery_duration :"1"
speed_heart_rate :"180"
recovery_heart_rate :"90"
repetitions :"10"
type :fixed
end

power('As strong as an ox') do
sport Sport::WEIGHT_LIFTING
series('Little ox') do
intensity :"5"
repetitions :"20"
end
series('Big ox') do
intensity :"10"
repetitions :"80"
end
end
end

# Saving JSON-ized training to a file.
Expand Down
55 changes: 37 additions & 18 deletions lib/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require 'json'
require_relative 'interval'
require_relative 'session'
require_relative 'power'
require_relative 'speed'
require_relative 'sport'

##
# This module is intended to be used for building trainings
Expand All @@ -11,10 +13,9 @@ module Ast
##
# Building a new training from the domain specific language.
# Params:
# +name+:: the name of the training
# +block+:: training data
def self.build(name, &block)
training = Training.new(name)
def self.build(&block)
training = Training.new()
training.instance_eval(&block)
training
end
Expand All @@ -26,21 +27,21 @@ class Training
# Initialization method for the +Training+ class.
# Params:
# +name+:: the name of the training
def initialize(name)
@name = name
@session = []
def initialize
@speed = []
@interval = []
@power = []
end

##
# Building a new session from the domain specific language.
# Building a new speed session from the domain specific language.
# Params:
# +name+:: the name of the session
# +block+:: session data
def session(name, &block)
training_type = Session.new(name)
# +name+:: the name of the speed session
# +block+:: speed session data
def speed(name, &block)
training_type = Speed.new(name)
training_type.instance_eval(&block)
@session << training_type
@speed << training_type
end

##
Expand All @@ -54,19 +55,37 @@ def interval(name, &block)
@interval << interval_data
end

##
# Building a new power session from the domain specific language.
# Params:
# +name+:: the name of the power session
# +block+:: power session data
def power(name, &block)
power_data = Power.new(name)
power_data.instance_eval(&block)
@power << power_data
end

##
# Converting a training to a string.
def to_s
"#{@name} #{@session[0]}"
speed_number = @speed.length
interval_number = @interval.length
power_number = @power.length

"TRAINING DATA:\n"\
"Speed sessions: #{speed_number}\n"\
"Interval sessions: #{interval_number}\n"\
"Power sessions: #{power_number}\n\n"
end

##
# Converting a training to a JSON-ized string.
def json
training_json = {
name: @name,
session: @session.collect(&:to_hash),
interval: @interval.collect(&:to_hash)
speed: @speed.collect(&:to_hash),
interval: @interval.collect(&:to_hash),
power: @power.collect(&:to_hash)
}
JSON.pretty_generate(training_json)
end
Expand All @@ -76,7 +95,7 @@ def json
# Params:
# +filename+:: the desired name of the file
def save_to_file(filename)
f = File.open(filename, 'w')
f = File.open("../trainings/#{filename}", 'w')
f.puts(json)
f.close
end
Expand Down
Loading