ast-tdl 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (11) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +124 -91
  4. data/lib/ast-tdl.rb +3 -3
  5. data/lib/ast.rb +103 -103
  6. data/lib/interval.rb +139 -139
  7. data/lib/power.rb +55 -55
  8. data/lib/series.rb +57 -57
  9. data/lib/speed.rb +83 -83
  10. data/lib/sport.rb +15 -15
  11. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c8570f5e5872a125474d6136f9aaadf1f8b2e66e8fab322195809d138c726f9
4
- data.tar.gz: 7bbb277292d148b02004394b424fa10d7edd05bb72f408932124f2934b8e1100
3
+ metadata.gz: c48bcca740ece68b00917b86f939a85316347e9e3e661d76aa0531b67e6aec55
4
+ data.tar.gz: 27f8a21215981993e870a81e1f9eecf65d9ba6adfac388fc307acb95e3089240
5
5
  SHA512:
6
- metadata.gz: 8c7792b0ed3c40eb833a303ac9f7fdd791d1c810f981ef122ab4b4d53feb356ea1fc26d4cf2e41d22bb93c74c23e63ec84608f5da14d20d1d94591f3036cf90a
7
- data.tar.gz: 1611041a04c44bdf8d7d01ff1ec98ab2c84d737586454211841a5a5794ba21e76bb3efec554195654a5ba1f5bee524602bcb279057b20cc1d8dcc99c27f29d14
6
+ metadata.gz: 7b816baa2b094710c6b58281ce2ca0ab24214ccabd59b8ed75332ad9487b9ea6451b27d83c75e5a85bfc521dbdd35c5044e44f1c9d932334dd4a6b80bc86baac
7
+ data.tar.gz: 283ed4403d1f6e6d2961e68850763785bc5119a665d013db1867b1d115fa52f1e84cc2222e352df0c00d2f1e5308a0d8b6b804f04e0e96f3e1540ade5077cfbb
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Iztok Fister Jr.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022-2024 Iztok Fister Jr.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,91 +1,124 @@
1
- # Training Description Language (TDL) for Artificial Sport Trainer (AST)
2
-
3
- ---
4
-
5
- [![DOI](https://img.shields.io/badge/DOI-10.1109/ISCMI53840.2021.9654817-blue)](https://doi.org/10.1109/ISCMI53840.2021.9654817)
6
-
7
- ## Motivation
8
- 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.
9
-
10
- According to sports theory, three major types of sports trainings exist:
11
- - speed trainings,
12
- - interval trainings and
13
- - power trainings.
14
-
15
- 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.
16
-
17
- 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.
18
-
19
- 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.
20
-
21
- ## Feature diagram
22
- ![ast-tdl](https://user-images.githubusercontent.com/73126820/193033601-6c94b328-30a4-4b25-86a3-0fb81cebca3d.png)
23
-
24
- ## Installation
25
- ```sh
26
- $ gem install ast-tdl
27
- ```
28
-
29
- ## Language description
30
- Training Description Language (TDL) is implemented in Ruby. All three major training types (speed, interval and power) can be described in TDL.
31
-
32
- Speed training sessions are described with their name, sport type, proposed average heart rate and total duration, while the additional information is optional.
33
-
34
- 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.
35
-
36
- 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.
37
-
38
- ## Examples
39
- ### Example of a sports training
40
- ```ruby
41
- Ast.build do
42
- speed('Swimming with the dolphins') do
43
- sport Sport::SWIMMING
44
- info :"Very easy training"
45
- average_heart_rate :"130"
46
- total_duration :"30"
47
- end
48
-
49
- speed('Cross the country') do
50
- sport Sport::CYCLING
51
- info :"Endurance ride"
52
- average_heart_rate :"140"
53
- total_duration :"120"
54
- end
55
-
56
- interval('Following Emil Zatopek') do
57
- sport Sport::RUNNING
58
- info :Hard
59
- speed_duration :"1"
60
- recovery_duration :"1"
61
- speed_heart_rate :"180"
62
- recovery_heart_rate :"90"
63
- repetitions :"10"
64
- type :fixed
65
- end
66
-
67
- power('As strong as an ox') do
68
- sport Sport::WEIGHT_LIFTING
69
- series('Little ox') do
70
- intensity: :"5"
71
- repetitions :"20"
72
- end
73
- series('Big ox') do
74
- intensity :"10"
75
- repetitions :"80"
76
- end
77
- end
78
- end
79
- ```
80
- 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.
81
-
82
- ## License
83
- This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
84
-
85
- ## Disclaimer
86
- 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!
87
-
88
- ## References
89
- 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).
90
-
91
- 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].
1
+ <h1 align="center">
2
+ Training Description Language (TDL) for Artificial Sport Trainer (AST)
3
+ </h1>
4
+
5
+ <p align="center">
6
+ <img alt="Gem package" src="https://img.shields.io/gem/v/ast-tdl?color=blue" href="https://rubygems.org/gems/ast-tdl">
7
+ <img alt="AUR package" src="https://img.shields.io/aur/version/ruby-ast-tdl?color=blue&label=Arch%20Linux&logo=arch-linux" href="https://aur.archlinux.org/packages/ruby-ast-tdl">
8
+ </p>
9
+
10
+ <p align="center">
11
+ <img alt="DOI" src="https://img.shields.io/badge/DOI-10.3390/app122412741-blue" href="https://doi.org/10.3390/app122412741">
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="#-motivation">💡 Motivation</a>
16
+ <a href="#-feature-diagram">✨ Feature diagram</a> •
17
+ <a href="#-installation">📦 Installation</a>
18
+ <a href="#️-language-description">🗣️ Language description</a> •
19
+ <a href="#-examples">🚀 Examples</a>
20
+ <a href="#-license">🔑 License</a> •
21
+ <a href="#-references">📝 References</a>
22
+ </p>
23
+
24
+ ## 💡 Motivation
25
+ 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.
26
+
27
+ According to sports theory, three major types of sports training exist:
28
+ - speed training ⚡
29
+ - interval training ⏱️
30
+ - power training 💪
31
+
32
+ Speed training is intended to supply an athlete with energy, coordination and power adaptation. This type of sports training is often used by middle-distance athletes, as it can enhance their performance.
33
+
34
+ Interval training was first described by Reindell and Roskamm, however, it was popularized by the famous Chech athlete Emil Zatopek. This type of training consists of a speed phase followed by a recovery phase. This sequence is repeated several times, and the number of repetitions depends on the interval training plan.
35
+
36
+ Power training has been proven to be an effective method for increasing muscle mass. Consequently, in most cases, they are used in extreme sports, such as weight lifting, where the lactate amount in blood is significant.
37
+
38
+ ## ✨ Feature diagram
39
+ ![ast-tdl](https://user-images.githubusercontent.com/73126820/193033601-6c94b328-30a4-4b25-86a3-0fb81cebca3d.png)
40
+
41
+ ## 📦 Installation
42
+ To install `ast-dsl` with gem, use:
43
+
44
+ ```sh
45
+ $ gem install ast-tdl
46
+ ```
47
+ To install `ast-tdl` on Alpine, use:
48
+
49
+ ```sh
50
+ $ apk add ruby-ast-tdl
51
+ ```
52
+
53
+ To install `ast-dsl` on Arch Linux, use an [AUR helper](https://wiki.archlinux.org/title/AUR_helpers):
54
+
55
+ ```sh
56
+ $ yay -Syyu ruby-ast-tdl
57
+ ```
58
+
59
+ ## 🗣️ Language description
60
+ Training Description Language (TDL) is implemented in Ruby. All three major training types (speed, interval and power) can be described in TDL.
61
+
62
+ Speed training sessions are described with their name, sport type, proposed average heart rate and total duration, while additional information is optional.
63
+
64
+ Interval training sessions and 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 the speed and recovery phases. Additionally, the number of repetitions and interval training types are also described along with the features mentioned earlier.
65
+
66
+ Power training sessions are described with their names and sports types. However, as opposed to speed and interval they are described with series, which are further described with their name, intensity level from 1 to 10 and number of repetitions.
67
+
68
+ ## 🚀 Examples
69
+ ### Example of a sports training
70
+ ```ruby
71
+ Ast.build do
72
+ speed('Swimming with the dolphins') do
73
+ sport Sport::SWIMMING
74
+ info :"Very easy training"
75
+ average_heart_rate :"130"
76
+ total_duration :"30"
77
+ end
78
+
79
+ speed('Cross the country') do
80
+ sport Sport::CYCLING
81
+ info :"Endurance ride"
82
+ average_heart_rate :"140"
83
+ total_duration :"120"
84
+ end
85
+
86
+ interval('Following Emil Zatopek') do
87
+ sport Sport::RUNNING
88
+ info :Hard
89
+ speed_duration :"1"
90
+ recovery_duration :"1"
91
+ speed_heart_rate :"180"
92
+ recovery_heart_rate :"90"
93
+ repetitions :"10"
94
+ type :fixed
95
+ end
96
+
97
+ power('As strong as an ox') do
98
+ sport Sport::WEIGHT_LIFTING
99
+ series('Little ox') do
100
+ intensity: :"5"
101
+ repetitions :"20"
102
+ end
103
+ series('Big ox') do
104
+ intensity :"10"
105
+ repetitions :"80"
106
+ end
107
+ end
108
+ end
109
+ ```
110
+
111
+ The description of the sports training consists of four sessions: two speed sessions, one interval session and one power session. The first (swimming speed) session is relatively easy, as the planned heart rate during the 30-minute session is prescribed to be 130 BPM. The second (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 the speed phase and recovery duration are 1 minute each. The proposed heart rate during speed phases is set at 180 BPM, while it is set to half the heart rate (90 BPM) in recovery phases. The final (weight-lifting) power session consists of two series: the first is moderate intensity with 20 repetitions, and the second is high intensity with 80 repetitions.
112
+
113
+ ## 🔑 License
114
+ This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
115
+
116
+ ## Disclaimer
117
+ 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!
118
+
119
+ ## 📝 References
120
+ Lukač, L., Fister Jr., I., Fister, I. "[Digital Twin in Sport: From an Idea to Realization](https://www.mdpi.com/2076-3417/12/24/12741)." Applied Sciences 12.24 (2022): 12741.
121
+
122
+ 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).
123
+
124
+ Lukač, L. (2022). [Aplikacija koncepta digitalnega dvojčka v športu](https://dk.um.si/IzpisGradiva.php?id=82612). University of Maribor, Faculty of Electrical Engineering and Computer Science. [Access: 29th September, 2022].
data/lib/ast-tdl.rb CHANGED
@@ -1,3 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './ast'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './ast'
data/lib/ast.rb CHANGED
@@ -1,103 +1,103 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require_relative 'interval'
5
- require_relative 'power'
6
- require_relative 'speed'
7
- require_relative 'sport'
8
-
9
- ##
10
- # This module is intended to be used for building trainings
11
- # from the domain specific language AST-TDL.
12
- module Ast
13
- ##
14
- # Building a new training from the domain specific language.
15
- # Params:
16
- # +block+:: training data
17
- def self.build(&block)
18
- training = Training.new()
19
- training.instance_eval(&block)
20
- training
21
- end
22
-
23
- ##
24
- # This class represents a training with a name, sessions and intervals.
25
- class Training
26
- ##
27
- # Initialization method for the +Training+ class.
28
- # Params:
29
- # +name+:: the name of the training
30
- def initialize
31
- @speed = []
32
- @interval = []
33
- @power = []
34
- end
35
-
36
- ##
37
- # Building a new speed session from the domain specific language.
38
- # Params:
39
- # +name+:: the name of the speed session
40
- # +block+:: speed session data
41
- def speed(name, &block)
42
- training_type = Speed.new(name)
43
- training_type.instance_eval(&block)
44
- @speed << training_type
45
- end
46
-
47
- ##
48
- # Building a new interval from the domain specific language.
49
- # Params:
50
- # +name+:: the name of the interval
51
- # +block+:: interval data
52
- def interval(name, &block)
53
- interval_data = Interval.new(name)
54
- interval_data.instance_eval(&block)
55
- @interval << interval_data
56
- end
57
-
58
- ##
59
- # Building a new power session from the domain specific language.
60
- # Params:
61
- # +name+:: the name of the power session
62
- # +block+:: power session data
63
- def power(name, &block)
64
- power_data = Power.new(name)
65
- power_data.instance_eval(&block)
66
- @power << power_data
67
- end
68
-
69
- ##
70
- # Converting a training to a string.
71
- def to_s
72
- speed_number = @speed.length
73
- interval_number = @interval.length
74
- power_number = @power.length
75
-
76
- "TRAINING DATA:\n"\
77
- "Speed sessions: #{speed_number}\n"\
78
- "Interval sessions: #{interval_number}\n"\
79
- "Power sessions: #{power_number}\n\n"
80
- end
81
-
82
- ##
83
- # Converting a training to a JSON-ized string.
84
- def json
85
- training_json = {
86
- speed: @speed.collect(&:to_hash),
87
- interval: @interval.collect(&:to_hash),
88
- power: @power.collect(&:to_hash)
89
- }
90
- JSON.pretty_generate(training_json)
91
- end
92
-
93
- ##
94
- # Saving a training to a JSON file.
95
- # Params:
96
- # +filename+:: the desired name of the file
97
- def save_to_file(filename)
98
- f = File.open("../trainings/#{filename}", 'w')
99
- f.puts(json)
100
- f.close
101
- end
102
- end
103
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'interval'
5
+ require_relative 'power'
6
+ require_relative 'speed'
7
+ require_relative 'sport'
8
+
9
+ ##
10
+ # This module is intended to be used for building trainings
11
+ # from the domain specific language AST-TDL.
12
+ module Ast
13
+ ##
14
+ # Building a new training from the domain specific language.
15
+ # Params:
16
+ # +block+:: training data
17
+ def self.build(&block)
18
+ training = Training.new()
19
+ training.instance_eval(&block)
20
+ training
21
+ end
22
+
23
+ ##
24
+ # This class represents a training with a name, sessions and intervals.
25
+ class Training
26
+ ##
27
+ # Initialization method for the +Training+ class.
28
+ # Params:
29
+ # +name+:: the name of the training
30
+ def initialize
31
+ @speed = []
32
+ @interval = []
33
+ @power = []
34
+ end
35
+
36
+ ##
37
+ # Building a new speed session from the domain specific language.
38
+ # Params:
39
+ # +name+:: the name of the speed session
40
+ # +block+:: speed session data
41
+ def speed(name, &block)
42
+ training_type = Speed.new(name)
43
+ training_type.instance_eval(&block)
44
+ @speed << training_type
45
+ end
46
+
47
+ ##
48
+ # Building a new interval from the domain specific language.
49
+ # Params:
50
+ # +name+:: the name of the interval
51
+ # +block+:: interval data
52
+ def interval(name, &block)
53
+ interval_data = Interval.new(name)
54
+ interval_data.instance_eval(&block)
55
+ @interval << interval_data
56
+ end
57
+
58
+ ##
59
+ # Building a new power session from the domain specific language.
60
+ # Params:
61
+ # +name+:: the name of the power session
62
+ # +block+:: power session data
63
+ def power(name, &block)
64
+ power_data = Power.new(name)
65
+ power_data.instance_eval(&block)
66
+ @power << power_data
67
+ end
68
+
69
+ ##
70
+ # Converting a training to a string.
71
+ def to_s
72
+ speed_number = @speed.length
73
+ interval_number = @interval.length
74
+ power_number = @power.length
75
+
76
+ "TRAINING DATA:\n"\
77
+ "Speed sessions: #{speed_number}\n"\
78
+ "Interval sessions: #{interval_number}\n"\
79
+ "Power sessions: #{power_number}\n\n"
80
+ end
81
+
82
+ ##
83
+ # Converting a training to a JSON-ized string.
84
+ def json
85
+ training_json = {
86
+ speed: @speed.collect(&:to_hash),
87
+ interval: @interval.collect(&:to_hash),
88
+ power: @power.collect(&:to_hash)
89
+ }
90
+ JSON.pretty_generate(training_json)
91
+ end
92
+
93
+ ##
94
+ # Saving a training to a JSON file.
95
+ # Params:
96
+ # +filename+:: the desired name of the file
97
+ def save_to_file(filename)
98
+ f = File.open("../trainings/#{filename}", 'w')
99
+ f.puts(json)
100
+ f.close
101
+ end
102
+ end
103
+ end
data/lib/interval.rb CHANGED
@@ -1,139 +1,139 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'sport'
4
-
5
- ##
6
- # This class represents an interval.
7
- class Interval
8
- ##
9
- # Initialization method for the +Interval+ class.
10
- # Params:
11
- # +name+:: the name of the interval
12
- def initialize(name)
13
- @name = name
14
- @sport = ''
15
- @info = ''
16
- @speed_duration = 0
17
- @recovery_duration = 0
18
- @speed_heart_rate = 0
19
- @recovery_heart_rate = 0
20
- @repetitions = 0
21
- @type = ''
22
- end
23
-
24
- ##
25
- # Adding a sport to the object.
26
- # Params:
27
- # +type+:: the type of the sport
28
- def sport(type)
29
- raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
30
-
31
- @sport = type
32
- end
33
-
34
- ##
35
- # Adding an info message to the object.
36
- # Params:
37
- # +message+:: the info message
38
- def info(message)
39
- @info = message
40
- end
41
-
42
- ##
43
- # Adding a speed duration of an interval to the object.
44
- # Params:
45
- # +speed_duration+:: the duration of the speed segment in minutes
46
- def speed_duration(speed_duration)
47
- speed_duration_str = speed_duration.to_s
48
- speed_duration_int = speed_duration.to_s.to_i
49
- raise 'The given speed duration is not an integer.' if speed_duration_str != speed_duration_str.to_i.to_s
50
- raise 'The speed duration has to be 1 minute at least.' if speed_duration_int < 1
51
-
52
- @speed_duration = speed_duration_int
53
- end
54
-
55
- ##
56
- # Adding a recovery duration of an interval to the object.
57
- # Params:
58
- # +recovery_duration+:: the duration of the recovery segment in minutes
59
- def recovery_duration(recovery_duration)
60
- recovery_duration_str = recovery_duration.to_s
61
- recovery_duration_int = recovery_duration.to_s.to_i
62
- raise 'The given recovery duration is not an integer.' if recovery_duration_str != recovery_duration_str.to_i.to_s
63
- raise 'The recovery duration has to be 1 minute at least.' if recovery_duration_int < 1
64
-
65
- @recovery_duration = recovery_duration_int
66
- end
67
-
68
- ##
69
- # Adding a speed heart rate of an interval to the object.
70
- # Params:
71
- # +speed_heart_rate+:: the average speed heart rate in bpm
72
- def speed_heart_rate(speed_heart_rate)
73
- speed_hr_str = speed_heart_rate.to_s
74
- speed_hr_int = speed_heart_rate.to_s.to_i
75
- raise 'The given average heart rate is not an integer.' if speed_hr_str != speed_hr_str.to_i.to_s
76
- raise 'The speed heart rate should be between 60 and 205 bpm.' if speed_hr_int < 60 || speed_hr_int > 205
77
-
78
- @speed_heart_rate = speed_hr_int
79
- end
80
-
81
- ##
82
- # Adding a recovery heart rate of an interval to the object.
83
- # Params:
84
- # +recovery_heart_rate+:: the average speed heart rate in bpm
85
- def recovery_heart_rate(recovery_heart_rate)
86
- recovery_hr_str = recovery_heart_rate.to_s
87
- recovery_hr_int = recovery_heart_rate.to_s.to_i
88
- raise 'The given average heart rate is not an integer.' if recovery_hr_str != recovery_hr_str.to_i.to_s
89
- raise 'The recovery heart rate should be between 60 and 205 bpm.' if recovery_hr_int < 60 || recovery_hr_int > 205
90
-
91
- @recovery_heart_rate = recovery_hr_int
92
- end
93
-
94
- ##
95
- # Adding a number of repetitions to the object.
96
- # Params:
97
- # +repetitions+:: number of interval repetitions
98
- def repetitions(repetitions)
99
- repetitions_str = repetitions.to_s
100
- repetitions_int = repetitions.to_s.to_i
101
- raise 'The given number of repetitions is not an integer.' if repetitions_str != repetitions_str.to_i.to_s
102
- raise 'The minimum number of repetitions is 1.' if repetitions_int < 1
103
-
104
- @repetitions = repetitions_int
105
- end
106
-
107
- ##
108
- # Adding an interval type to the object.
109
- # Params:
110
- # +type+:: interval type
111
- def type(type)
112
- @type = type
113
- end
114
-
115
- ##
116
- # Converting an interval to a string.
117
- def to_s
118
- "#{@sport} #{@info}"
119
- end
120
-
121
- ##
122
- # Converting an interval to a JSON-ized string.
123
- def to_hash
124
- hash = {
125
- name: @name,
126
- sport: @sport,
127
- info: @info,
128
- speed_duration: @speed_duration,
129
- recovery_duration: @recovery_duration,
130
- speed_heart_rate: @speed_heart_rate,
131
- recovery_heart_rate: @recovery_heart_rate,
132
- repetitions: @repetitions,
133
- type: @type
134
- }
135
-
136
- hash[:info] = @info if @info
137
- hash
138
- end
139
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sport'
4
+
5
+ ##
6
+ # This class represents an interval.
7
+ class Interval
8
+ ##
9
+ # Initialization method for the +Interval+ class.
10
+ # Params:
11
+ # +name+:: the name of the interval
12
+ def initialize(name)
13
+ @name = name
14
+ @sport = ''
15
+ @info = ''
16
+ @speed_duration = 0
17
+ @recovery_duration = 0
18
+ @speed_heart_rate = 0
19
+ @recovery_heart_rate = 0
20
+ @repetitions = 0
21
+ @type = ''
22
+ end
23
+
24
+ ##
25
+ # Adding a sport to the object.
26
+ # Params:
27
+ # +type+:: the type of the sport
28
+ def sport(type)
29
+ raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
30
+
31
+ @sport = type
32
+ end
33
+
34
+ ##
35
+ # Adding an info message to the object.
36
+ # Params:
37
+ # +message+:: the info message
38
+ def info(message)
39
+ @info = message
40
+ end
41
+
42
+ ##
43
+ # Adding a speed duration of an interval to the object.
44
+ # Params:
45
+ # +speed_duration+:: the duration of the speed segment in minutes
46
+ def speed_duration(speed_duration)
47
+ speed_duration_str = speed_duration.to_s
48
+ speed_duration_int = speed_duration.to_s.to_i
49
+ raise 'The given speed duration is not an integer.' if speed_duration_str != speed_duration_str.to_i.to_s
50
+ raise 'The speed duration has to be 1 minute at least.' if speed_duration_int < 1
51
+
52
+ @speed_duration = speed_duration_int
53
+ end
54
+
55
+ ##
56
+ # Adding a recovery duration of an interval to the object.
57
+ # Params:
58
+ # +recovery_duration+:: the duration of the recovery segment in minutes
59
+ def recovery_duration(recovery_duration)
60
+ recovery_duration_str = recovery_duration.to_s
61
+ recovery_duration_int = recovery_duration.to_s.to_i
62
+ raise 'The given recovery duration is not an integer.' if recovery_duration_str != recovery_duration_str.to_i.to_s
63
+ raise 'The recovery duration has to be 1 minute at least.' if recovery_duration_int < 1
64
+
65
+ @recovery_duration = recovery_duration_int
66
+ end
67
+
68
+ ##
69
+ # Adding a speed heart rate of an interval to the object.
70
+ # Params:
71
+ # +speed_heart_rate+:: the average speed heart rate in bpm
72
+ def speed_heart_rate(speed_heart_rate)
73
+ speed_hr_str = speed_heart_rate.to_s
74
+ speed_hr_int = speed_heart_rate.to_s.to_i
75
+ raise 'The given average heart rate is not an integer.' if speed_hr_str != speed_hr_str.to_i.to_s
76
+ raise 'The speed heart rate should be between 60 and 205 bpm.' if speed_hr_int < 60 || speed_hr_int > 205
77
+
78
+ @speed_heart_rate = speed_hr_int
79
+ end
80
+
81
+ ##
82
+ # Adding a recovery heart rate of an interval to the object.
83
+ # Params:
84
+ # +recovery_heart_rate+:: the average speed heart rate in bpm
85
+ def recovery_heart_rate(recovery_heart_rate)
86
+ recovery_hr_str = recovery_heart_rate.to_s
87
+ recovery_hr_int = recovery_heart_rate.to_s.to_i
88
+ raise 'The given average heart rate is not an integer.' if recovery_hr_str != recovery_hr_str.to_i.to_s
89
+ raise 'The recovery heart rate should be between 60 and 205 bpm.' if recovery_hr_int < 60 || recovery_hr_int > 205
90
+
91
+ @recovery_heart_rate = recovery_hr_int
92
+ end
93
+
94
+ ##
95
+ # Adding a number of repetitions to the object.
96
+ # Params:
97
+ # +repetitions+:: number of interval repetitions
98
+ def repetitions(repetitions)
99
+ repetitions_str = repetitions.to_s
100
+ repetitions_int = repetitions.to_s.to_i
101
+ raise 'The given number of repetitions is not an integer.' if repetitions_str != repetitions_str.to_i.to_s
102
+ raise 'The minimum number of repetitions is 1.' if repetitions_int < 1
103
+
104
+ @repetitions = repetitions_int
105
+ end
106
+
107
+ ##
108
+ # Adding an interval type to the object.
109
+ # Params:
110
+ # +type+:: interval type
111
+ def type(type)
112
+ @type = type
113
+ end
114
+
115
+ ##
116
+ # Converting an interval to a string.
117
+ def to_s
118
+ "#{@sport} #{@info}"
119
+ end
120
+
121
+ ##
122
+ # Converting an interval to a JSON-ized string.
123
+ def to_hash
124
+ hash = {
125
+ name: @name,
126
+ sport: @sport,
127
+ info: @info,
128
+ speed_duration: @speed_duration,
129
+ recovery_duration: @recovery_duration,
130
+ speed_heart_rate: @speed_heart_rate,
131
+ recovery_heart_rate: @recovery_heart_rate,
132
+ repetitions: @repetitions,
133
+ type: @type
134
+ }
135
+
136
+ hash[:info] = @info if @info
137
+ hash
138
+ end
139
+ end
data/lib/power.rb CHANGED
@@ -1,55 +1,55 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'series'
4
- require_relative 'sport'
5
-
6
- ##
7
- # This class represents a power training session.
8
- class Power
9
- ##
10
- # Initialization method for the +Power+ class.
11
- # Params:
12
- # +name+:: the name of the power session
13
- def initialize(name)
14
- @name = name
15
- @series = []
16
- @sport = ''
17
- end
18
-
19
- ##
20
- # Building a new series from the domain specific language.
21
- # Params:
22
- # +name+:: the name of the series
23
- # +block+:: power session data
24
- def series(name, &block)
25
- series_data = Series.new(name)
26
- series_data.instance_eval(&block)
27
- @series << series_data
28
- end
29
-
30
- ##
31
- # Adding a sport type to the object.
32
- # Params:
33
- # +type+:: the type of the sport
34
- def sport(type)
35
- raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
36
-
37
- @sport = type
38
- end
39
-
40
- ##
41
- # Converting a speed session to a string.
42
- def to_s
43
- @name
44
- end
45
-
46
- ##
47
- # Converting a session to a JSON-ized string.
48
- def to_hash
49
- {
50
- name: @name,
51
- sport: @sport,
52
- series: @series.collect(&:to_hash)
53
- }
54
- end
55
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'series'
4
+ require_relative 'sport'
5
+
6
+ ##
7
+ # This class represents a power training session.
8
+ class Power
9
+ ##
10
+ # Initialization method for the +Power+ class.
11
+ # Params:
12
+ # +name+:: the name of the power session
13
+ def initialize(name)
14
+ @name = name
15
+ @series = []
16
+ @sport = ''
17
+ end
18
+
19
+ ##
20
+ # Building a new series from the domain specific language.
21
+ # Params:
22
+ # +name+:: the name of the series
23
+ # +block+:: power session data
24
+ def series(name, &block)
25
+ series_data = Series.new(name)
26
+ series_data.instance_eval(&block)
27
+ @series << series_data
28
+ end
29
+
30
+ ##
31
+ # Adding a sport type to the object.
32
+ # Params:
33
+ # +type+:: the type of the sport
34
+ def sport(type)
35
+ raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
36
+
37
+ @sport = type
38
+ end
39
+
40
+ ##
41
+ # Converting a speed session to a string.
42
+ def to_s
43
+ @name
44
+ end
45
+
46
+ ##
47
+ # Converting a session to a JSON-ized string.
48
+ def to_hash
49
+ {
50
+ name: @name,
51
+ sport: @sport,
52
+ series: @series.collect(&:to_hash)
53
+ }
54
+ end
55
+ end
data/lib/series.rb CHANGED
@@ -1,57 +1,57 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # This class represents a series in power training session.
5
- class Series
6
- ##
7
- # Initialization method for the +Series+ class.
8
- # Params:
9
- # +name+:: the name of the series
10
- def initialize(name)
11
- @name = name
12
- @intensity = 0
13
- @repetitions = 0
14
- end
15
-
16
- ##
17
- # Adding an intensity in the range [1, 10] to the series.
18
- # Params:
19
- # +intensity+:: intensity level
20
- def intensity(intensity)
21
- intensity_str = intensity.to_s
22
- intensity_int = intensity.to_s.to_i
23
- raise 'The given intensity level is not an integer.' if intensity_str != intensity_str.to_i.to_s
24
- raise 'The intensity level should be between 1 and 10.' if intensity_int < 1 || intensity_int > 10
25
-
26
- @intensity = intensity_int
27
- end
28
-
29
- ##
30
- # Adding a number of repetitions to the object.
31
- # Params:
32
- # +repetitions+:: number of repetitions inside of a series
33
- def repetitions(repetitions)
34
- repetitions_str = repetitions.to_s
35
- repetitions_int = repetitions.to_s.to_i
36
- raise 'The given number of repetitions is not an integer.' if repetitions_str != repetitions_str.to_i.to_s
37
- raise 'The minimum number of repetitions is 1.' if repetitions_int < 1
38
-
39
- @repetitions = repetitions_int
40
- end
41
-
42
- ##
43
- # Converting a speed session to a string.
44
- def to_s
45
- @name
46
- end
47
-
48
- ##
49
- # Converting a session to a JSON-ized string.
50
- def to_hash
51
- {
52
- name: @name,
53
- intensity: @intensity,
54
- repetitions: @repetitions
55
- }
56
- end
57
- end
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # This class represents a series in power training session.
5
+ class Series
6
+ ##
7
+ # Initialization method for the +Series+ class.
8
+ # Params:
9
+ # +name+:: the name of the series
10
+ def initialize(name)
11
+ @name = name
12
+ @intensity = 0
13
+ @repetitions = 0
14
+ end
15
+
16
+ ##
17
+ # Adding an intensity in the range [1, 10] to the series.
18
+ # Params:
19
+ # +intensity+:: intensity level
20
+ def intensity(intensity)
21
+ intensity_str = intensity.to_s
22
+ intensity_int = intensity.to_s.to_i
23
+ raise 'The given intensity level is not an integer.' if intensity_str != intensity_str.to_i.to_s
24
+ raise 'The intensity level should be between 1 and 10.' if intensity_int < 1 || intensity_int > 10
25
+
26
+ @intensity = intensity_int
27
+ end
28
+
29
+ ##
30
+ # Adding a number of repetitions to the object.
31
+ # Params:
32
+ # +repetitions+:: number of repetitions inside of a series
33
+ def repetitions(repetitions)
34
+ repetitions_str = repetitions.to_s
35
+ repetitions_int = repetitions.to_s.to_i
36
+ raise 'The given number of repetitions is not an integer.' if repetitions_str != repetitions_str.to_i.to_s
37
+ raise 'The minimum number of repetitions is 1.' if repetitions_int < 1
38
+
39
+ @repetitions = repetitions_int
40
+ end
41
+
42
+ ##
43
+ # Converting a speed session to a string.
44
+ def to_s
45
+ @name
46
+ end
47
+
48
+ ##
49
+ # Converting a session to a JSON-ized string.
50
+ def to_hash
51
+ {
52
+ name: @name,
53
+ intensity: @intensity,
54
+ repetitions: @repetitions
55
+ }
56
+ end
57
+ end
data/lib/speed.rb CHANGED
@@ -1,83 +1,83 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'sport'
4
-
5
- ##
6
- # This class represents a speed training session.
7
- class Speed
8
- ##
9
- # Initialization method for the +Speed+ class.
10
- # Params:
11
- # +name+:: the name of the speed session
12
- def initialize(name)
13
- @name = name
14
- @sport = ''
15
- @info = ''
16
- @average_heart_rate = 0
17
- @total_duration = 0
18
- end
19
-
20
- ##
21
- # Adding a sport type to the object.
22
- # Params:
23
- # +type+:: the type of the sport
24
- def sport(type)
25
- raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
26
-
27
- @sport = type
28
- end
29
-
30
- ##
31
- # Adding a message to the object.
32
- # Params:
33
- # +message+:: the info message
34
- def info(message)
35
- @info = message
36
- end
37
-
38
- ##
39
- # Adding an average heart rate to the object.
40
- # Params:
41
- # +heart_rate+:: the average heart rate in bpm
42
- def average_heart_rate(heart_rate)
43
- heart_rate_str = heart_rate.to_s
44
- heart_rate_int = heart_rate.to_s.to_i
45
- raise 'The given average heart rate is not an integer.' if heart_rate_str != heart_rate_str.to_i.to_s
46
- raise 'The average heart rate should be between 60 and 205 bpm.' if heart_rate_int < 60 || heart_rate_int > 205
47
-
48
- @average_heart_rate = heart_rate_int
49
- end
50
-
51
- ##
52
- # Adding a total duration to the object.
53
- # Params:
54
- # +duration+:: the duration in minutes
55
- def total_duration(duration)
56
- duration_str = duration.to_s
57
- duration_int = duration.to_s.to_i
58
- raise 'The given average heart rate is not an integer.' if duration_str != duration_str.to_i.to_s
59
- raise 'The duration has to be 1 minute at least.' if duration_int < 1
60
-
61
- @total_duration = duration_int
62
- end
63
-
64
- ##
65
- # Converting a speed session to a string.
66
- def to_s
67
- "#{@sport} #{@info}"
68
- end
69
-
70
- ##
71
- # Converting a session to a JSON-ized string.
72
- def to_hash
73
- hash = {
74
- name: @name,
75
- sport: @sport,
76
- average_heart_rate: @average_heart_rate,
77
- total_duration: @total_duration
78
- }
79
-
80
- hash[:info] = @info if @info != ''
81
- hash
82
- end
83
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sport'
4
+
5
+ ##
6
+ # This class represents a speed training session.
7
+ class Speed
8
+ ##
9
+ # Initialization method for the +Speed+ class.
10
+ # Params:
11
+ # +name+:: the name of the speed session
12
+ def initialize(name)
13
+ @name = name
14
+ @sport = ''
15
+ @info = ''
16
+ @average_heart_rate = 0
17
+ @total_duration = 0
18
+ end
19
+
20
+ ##
21
+ # Adding a sport type to the object.
22
+ # Params:
23
+ # +type+:: the type of the sport
24
+ def sport(type)
25
+ raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
26
+
27
+ @sport = type
28
+ end
29
+
30
+ ##
31
+ # Adding a message to the object.
32
+ # Params:
33
+ # +message+:: the info message
34
+ def info(message)
35
+ @info = message
36
+ end
37
+
38
+ ##
39
+ # Adding an average heart rate to the object.
40
+ # Params:
41
+ # +heart_rate+:: the average heart rate in bpm
42
+ def average_heart_rate(heart_rate)
43
+ heart_rate_str = heart_rate.to_s
44
+ heart_rate_int = heart_rate.to_s.to_i
45
+ raise 'The given average heart rate is not an integer.' if heart_rate_str != heart_rate_str.to_i.to_s
46
+ raise 'The average heart rate should be between 60 and 205 bpm.' if heart_rate_int < 60 || heart_rate_int > 205
47
+
48
+ @average_heart_rate = heart_rate_int
49
+ end
50
+
51
+ ##
52
+ # Adding a total duration to the object.
53
+ # Params:
54
+ # +duration+:: the duration in minutes
55
+ def total_duration(duration)
56
+ duration_str = duration.to_s
57
+ duration_int = duration.to_s.to_i
58
+ raise 'The given average heart rate is not an integer.' if duration_str != duration_str.to_i.to_s
59
+ raise 'The duration has to be 1 minute at least.' if duration_int < 1
60
+
61
+ @total_duration = duration_int
62
+ end
63
+
64
+ ##
65
+ # Converting a speed session to a string.
66
+ def to_s
67
+ "#{@sport} #{@info}"
68
+ end
69
+
70
+ ##
71
+ # Converting a session to a JSON-ized string.
72
+ def to_hash
73
+ hash = {
74
+ name: @name,
75
+ sport: @sport,
76
+ average_heart_rate: @average_heart_rate,
77
+ total_duration: @total_duration
78
+ }
79
+
80
+ hash[:info] = @info if @info != ''
81
+ hash
82
+ end
83
+ end
data/lib/sport.rb CHANGED
@@ -1,15 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ruby-enum'
4
-
5
- ##
6
- # This class represents a collection of sports.
7
- class Sport
8
- include Ruby::Enum
9
-
10
- define :CYCLING, 'cycling'
11
- define :RUNNING, 'running'
12
- define :SWIMMING, 'swimming'
13
- define :CROSS_COUNTRY_SKIING, 'cross country skiing'
14
- define :WEIGHT_LIFTING, 'weight lifting'
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby-enum'
4
+
5
+ ##
6
+ # This class represents a collection of sports.
7
+ class Sport
8
+ include Ruby::Enum
9
+
10
+ define :CYCLING, 'cycling'
11
+ define :RUNNING, 'running'
12
+ define :SWIMMING, 'swimming'
13
+ define :CROSS_COUNTRY_SKIING, 'cross country skiing'
14
+ define :WEIGHT_LIFTING, 'weight lifting'
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ast-tdl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - firefly-cpp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-05 00:00:00.000000000 Z
12
+ date: 2024-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-enum
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubygems_version: 3.3.7
67
+ rubygems_version: 3.5.11
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: An experimental and minimalistic Training Description Language for Artificial