ast-tdl 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +49 -30
- data/lib/ast.rb +1 -2
- data/lib/interval.rb +60 -37
- data/lib/session.rb +24 -22
- metadata +3 -3
- data/lib/classes.rb +0 -148
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e1cae6b9c56c969808cd16ff2d58ec838db46745cf3f6b9b1eb3583536ad93b
|
4
|
+
data.tar.gz: '0841bfa32e170d22ec587d027086ce4816a86d8116627c8f365000010ebd224a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 179ff4d41c5e51f81f2298bd6363fdbd58afe24b729274a4fc50eb04ffacb3eec453726da1817f4995c55d9923d5202e15c1083f5a7e762993fb7aab08edba48
|
7
|
+
data.tar.gz: 9e644b6a2f48ec60038a31c503a7d65fbfa4cc8bc89c19f8e9f2da31700f6299794eb292f37cfc2df72b05c9c8d92f8beb420f94c779055761d5fabfe9ca154c
|
data/LICENSE
ADDED
@@ -0,0 +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.
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Training Description Language (TDL) for Artificial Sport Trainer (AST)
|
2
|
+
|
3
|
+
## Motivation
|
2
4
|
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.
|
3
5
|
|
6
|
+
## Feature diagram
|
7
|
+
![scheme](https://user-images.githubusercontent.com/73126820/177509075-977b2e18-ebb7-40ce-9af9-ed7715717bf3.png)
|
8
|
+
|
4
9
|
## Installation
|
5
10
|
$ gem install ast-tdl
|
6
11
|
|
@@ -9,40 +14,54 @@ Training Description Language (TDL) is implemented in Ruby. Currently, the descr
|
|
9
14
|
|
10
15
|
## Examples
|
11
16
|
```ruby
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
Ast.build('My first training') do
|
18
|
+
session('Short swimming session') do
|
19
|
+
sport :swim
|
20
|
+
info :"Very easy training"
|
21
|
+
average_heart_rate :"130"
|
22
|
+
total_duration :"30"
|
23
|
+
end
|
24
|
+
|
25
|
+
session('Bike ride') do
|
26
|
+
sport :cycling
|
27
|
+
info :"Endurance ride with intervals"
|
28
|
+
average_heart_rate :"140"
|
29
|
+
total_duration :"120"
|
30
|
+
end
|
31
|
+
|
32
|
+
interval('Sample interval') do
|
33
|
+
sport :cycling
|
34
|
+
info :Moderate
|
35
|
+
speed_duration :"5"
|
36
|
+
recovery_duration :"5"
|
37
|
+
speed_heart_rate :"180"
|
38
|
+
recovery_heart_rate :"90"
|
39
|
+
repetitions :"10"
|
40
|
+
end
|
35
41
|
end
|
36
42
|
```
|
37
43
|
|
38
44
|
### Session
|
39
45
|
```ruby
|
40
|
-
session(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
session('Bike ride') do
|
47
|
+
sport :cycling
|
48
|
+
info :"Endurance ride with intervals"
|
49
|
+
average_heart_rate :"140"
|
50
|
+
total_duration :"120"
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### Interval
|
55
|
+
```ruby
|
56
|
+
interval('Sample interval') do
|
57
|
+
sport :cycling
|
58
|
+
info :Moderate
|
59
|
+
speed_duration :"5"
|
60
|
+
recovery_duration :"5"
|
61
|
+
speed_heart_rate :"180"
|
62
|
+
recovery_heart_rate :"90"
|
63
|
+
repetitions :"10"
|
64
|
+
end
|
46
65
|
```
|
47
66
|
|
48
67
|
## License
|
@@ -53,4 +72,4 @@ This framework is provided as-is, and there are no guarantees that it fits your
|
|
53
72
|
|
54
73
|
## References
|
55
74
|
|
56
|
-
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).
|
75
|
+
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).
|
data/lib/ast.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json'
|
4
|
-
require_relative 'classes'
|
5
4
|
require_relative 'interval'
|
6
5
|
require_relative 'session'
|
7
6
|
|
@@ -69,7 +68,7 @@ module Ast
|
|
69
68
|
session: @session.collect(&:to_hash),
|
70
69
|
interval: @interval.collect(&:to_hash)
|
71
70
|
}
|
72
|
-
training_json
|
71
|
+
JSON.pretty_generate(training_json)
|
73
72
|
end
|
74
73
|
|
75
74
|
##
|
data/lib/interval.rb
CHANGED
@@ -7,81 +7,104 @@ class Interval
|
|
7
7
|
# Initialization method for the +Interval+ class.
|
8
8
|
# Params:
|
9
9
|
# +name+:: the name of the interval
|
10
|
-
def initialize(
|
11
|
-
@name =
|
12
|
-
@sport =
|
13
|
-
@info =
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
@sport = ''
|
13
|
+
@info = ''
|
14
|
+
@speed_duration = 0
|
15
|
+
@recovery_duration = 0
|
16
|
+
@speed_heart_rate = 0
|
17
|
+
@recovery_heart_rate = 0
|
18
|
+
@repetitions = 0
|
19
|
+
@type = ''
|
18
20
|
end
|
19
21
|
|
20
22
|
##
|
21
|
-
#
|
23
|
+
# Adding a sport to the object.
|
22
24
|
# Params:
|
23
25
|
# +type+:: the type of the sport
|
24
26
|
def sport(type)
|
25
|
-
@sport
|
27
|
+
@sport = type
|
26
28
|
end
|
27
29
|
|
28
30
|
##
|
29
|
-
#
|
31
|
+
# Adding an info message to the object.
|
30
32
|
# Params:
|
31
33
|
# +message+:: the info message
|
32
34
|
def info(message)
|
33
|
-
@info
|
35
|
+
@info = message
|
34
36
|
end
|
35
37
|
|
36
38
|
##
|
37
|
-
#
|
39
|
+
# Adding a speed duration of an interval to the object.
|
38
40
|
# Params:
|
39
|
-
# +
|
40
|
-
def
|
41
|
-
@
|
41
|
+
# +speed_duration+:: the duration of the speed segment in minutes
|
42
|
+
def speed_duration(speed_duration)
|
43
|
+
@speed_duration = speed_duration.to_s.to_i
|
42
44
|
end
|
43
45
|
|
44
46
|
##
|
45
|
-
#
|
47
|
+
# Adding a recovery duration of an interval to the object.
|
46
48
|
# Params:
|
47
|
-
# +
|
48
|
-
def
|
49
|
-
@
|
49
|
+
# +recovery_duration+:: the duration of the recovery segment in minutes
|
50
|
+
def recovery_duration(recovery_duration)
|
51
|
+
@recovery_duration = recovery_duration.to_s.to_i
|
50
52
|
end
|
51
53
|
|
52
54
|
##
|
53
|
-
#
|
55
|
+
# Adding a speed heart rate of an interval to the object.
|
54
56
|
# Params:
|
55
|
-
# +
|
56
|
-
def
|
57
|
-
@
|
57
|
+
# +speed_heart_rate+:: the average speed heart rate in bpm
|
58
|
+
def speed_heart_rate(speed_heart_rate)
|
59
|
+
@speed_heart_rate = speed_heart_rate.to_s.to_i
|
58
60
|
end
|
59
61
|
|
60
62
|
##
|
61
|
-
#
|
63
|
+
# Adding a recovery heart rate of an interval to the object.
|
62
64
|
# Params:
|
63
|
-
# +
|
64
|
-
def
|
65
|
-
@
|
65
|
+
# +recovery_heart_rate+:: the average speed heart rate in bpm
|
66
|
+
def recovery_heart_rate(recovery_heart_rate)
|
67
|
+
@recovery_heart_rate = recovery_heart_rate.to_s.to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Adding a number of repetitions to the object.
|
72
|
+
# Params:
|
73
|
+
# +repetitions+:: number of interval repetitions
|
74
|
+
def repetitions(repetitions)
|
75
|
+
@repetitions = repetitions.to_s.to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Adding an interval type to the object.
|
80
|
+
# Params:
|
81
|
+
# +type+:: interval type
|
82
|
+
def type(type)
|
83
|
+
@type = type
|
66
84
|
end
|
67
85
|
|
68
86
|
##
|
69
87
|
# Converting an interval to a string.
|
70
88
|
def to_s
|
71
|
-
"#{@sport
|
89
|
+
"#{@sport} #{@info}"
|
72
90
|
end
|
73
91
|
|
74
92
|
##
|
75
93
|
# Converting an interval to a JSON-ized string.
|
76
94
|
def to_hash
|
77
|
-
{
|
78
|
-
name: @name
|
79
|
-
sport: @sport
|
80
|
-
info: @info
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
95
|
+
hash = {
|
96
|
+
name: @name,
|
97
|
+
sport: @sport,
|
98
|
+
info: @info,
|
99
|
+
speed_duration: @speed_duration,
|
100
|
+
recovery_duration: @recovery_duration,
|
101
|
+
speed_heart_rate: @speed_heart_rate,
|
102
|
+
recovery_heart_rate: @recovery_heart_rate,
|
103
|
+
repetitions: @repetitions,
|
104
|
+
type: @type
|
85
105
|
}
|
106
|
+
|
107
|
+
hash[:info] = @info if @info
|
108
|
+
hash
|
86
109
|
end
|
87
110
|
end
|
data/lib/session.rb
CHANGED
@@ -7,61 +7,63 @@ class Session
|
|
7
7
|
# Initialization method for the +Session+ class.
|
8
8
|
# Params:
|
9
9
|
# +name+:: the name of the session
|
10
|
-
def initialize(
|
11
|
-
@name =
|
12
|
-
@sport =
|
13
|
-
@info =
|
14
|
-
@average_heart_rate =
|
15
|
-
@total_duration =
|
10
|
+
def initialize(name)
|
11
|
+
@name = name
|
12
|
+
@sport = ''
|
13
|
+
@info = ''
|
14
|
+
@average_heart_rate = 0
|
15
|
+
@total_duration = 0
|
16
16
|
end
|
17
17
|
|
18
18
|
##
|
19
|
-
#
|
19
|
+
# Adding a sport type to the object.
|
20
20
|
# Params:
|
21
21
|
# +type+:: the type of the sport
|
22
22
|
def sport(type)
|
23
|
-
@sport
|
23
|
+
@sport = type
|
24
24
|
end
|
25
25
|
|
26
26
|
##
|
27
|
-
#
|
27
|
+
# Adding a message to the object.
|
28
28
|
# Params:
|
29
29
|
# +message+:: the info message
|
30
30
|
def info(message)
|
31
|
-
@info
|
31
|
+
@info = message
|
32
32
|
end
|
33
33
|
|
34
34
|
##
|
35
|
-
#
|
35
|
+
# Adding an average heart rate to the object.
|
36
36
|
# Params:
|
37
37
|
# +heart_rate+:: the average heart rate in bpm
|
38
38
|
def average_heart_rate(heart_rate)
|
39
|
-
@average_heart_rate
|
39
|
+
@average_heart_rate = heart_rate.to_s.to_i
|
40
40
|
end
|
41
41
|
|
42
42
|
##
|
43
|
-
#
|
43
|
+
# Adding a total duration to the object.
|
44
44
|
# Params:
|
45
|
-
# +duration+:: the duration in
|
45
|
+
# +duration+:: the duration in minutes
|
46
46
|
def total_duration(duration)
|
47
|
-
@total_duration
|
47
|
+
@total_duration = duration.to_s.to_i
|
48
48
|
end
|
49
49
|
|
50
50
|
##
|
51
51
|
# Converting a session to a string.
|
52
52
|
def to_s
|
53
|
-
"#{@sport
|
53
|
+
"#{@sport} #{@info}"
|
54
54
|
end
|
55
55
|
|
56
56
|
##
|
57
57
|
# Converting a session to a JSON-ized string.
|
58
58
|
def to_hash
|
59
|
-
{
|
60
|
-
name: @name
|
61
|
-
sport: @sport
|
62
|
-
|
63
|
-
|
64
|
-
total_duration: @total_duration.collect(&:to_hash),
|
59
|
+
hash = {
|
60
|
+
name: @name,
|
61
|
+
sport: @sport,
|
62
|
+
average_heart_rate: @average_heart_rate,
|
63
|
+
total_duration: @total_duration,
|
65
64
|
}
|
65
|
+
|
66
|
+
hash[:info] = @info if @info != ''
|
67
|
+
hash
|
66
68
|
end
|
67
69
|
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.
|
4
|
+
version: 0.1.1
|
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
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -19,10 +19,10 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- LICENSE
|
22
23
|
- README.md
|
23
24
|
- lib/ast-tdl.rb
|
24
25
|
- lib/ast.rb
|
25
|
-
- lib/classes.rb
|
26
26
|
- lib/interval.rb
|
27
27
|
- lib/session.rb
|
28
28
|
homepage: https://github.com/firefly-cpp/ast-tdl
|
data/lib/classes.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
##
|
6
|
-
# This class represents a sport with a type.
|
7
|
-
class Sport
|
8
|
-
# The type of a sport.
|
9
|
-
attr_reader :type
|
10
|
-
|
11
|
-
##
|
12
|
-
# Initialization method for the +Sport+ class.
|
13
|
-
# Params:
|
14
|
-
# +type+:: the type of the sport
|
15
|
-
def initialize(type)
|
16
|
-
@type = type
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Converting +Sport+ class to a hash.
|
21
|
-
def to_hash
|
22
|
-
{
|
23
|
-
type: @type
|
24
|
-
}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# This class represents information with a message.
|
30
|
-
class Info
|
31
|
-
# The info message.
|
32
|
-
attr_reader :message
|
33
|
-
|
34
|
-
##
|
35
|
-
# Initialization method for the +Info+ class.
|
36
|
-
# Params:
|
37
|
-
# +message+:: the info message
|
38
|
-
def initialize(message)
|
39
|
-
@message = message
|
40
|
-
end
|
41
|
-
|
42
|
-
##
|
43
|
-
# Converting +Info+ class to a hash.
|
44
|
-
def to_hash
|
45
|
-
{
|
46
|
-
message: @message
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
##
|
52
|
-
# This class represents an average heart rate.
|
53
|
-
class AverageHeartRate
|
54
|
-
# An average heart rate.
|
55
|
-
attr_reader :heart_rate
|
56
|
-
|
57
|
-
##
|
58
|
-
# Initialization method for the +AverageHeartRate+ class.
|
59
|
-
# Params:
|
60
|
-
# +heart_rate+:: the average heart rate
|
61
|
-
def initialize(heart_rate)
|
62
|
-
heart_rate = heart_rate.to_s.to_i
|
63
|
-
raise ArgumentError, 'Maximum heart rate is 220.' if heart_rate > 220
|
64
|
-
|
65
|
-
@heart_rate = heart_rate
|
66
|
-
end
|
67
|
-
|
68
|
-
##
|
69
|
-
# Converting +AverageHeartRate+ class to a hash.
|
70
|
-
def to_hash
|
71
|
-
{
|
72
|
-
average_hr: @heart_rate
|
73
|
-
}
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
# This class represents a total duration of a session or an interval.
|
79
|
-
class TotalDuration
|
80
|
-
# The total duration in seconds.
|
81
|
-
attr_reader :duration
|
82
|
-
|
83
|
-
##
|
84
|
-
# Initialization method for the +TotalDuration+ class.
|
85
|
-
# Params:
|
86
|
-
# +duration+:: the total duration
|
87
|
-
def initialize(duration)
|
88
|
-
@duration = duration
|
89
|
-
end
|
90
|
-
|
91
|
-
##
|
92
|
-
# Converting +TotalDuration+ class to a hash.
|
93
|
-
def to_hash
|
94
|
-
{
|
95
|
-
duration: @duration
|
96
|
-
}
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
##
|
101
|
-
# This class represents an average heart rate in the resting period.
|
102
|
-
class AverageHeartRateRest
|
103
|
-
# The average rest heart rate.
|
104
|
-
attr_reader :average_heart_rate_rest
|
105
|
-
|
106
|
-
##
|
107
|
-
# Initialization method for the +AverageHeartRateRest+ class.
|
108
|
-
# Params:
|
109
|
-
# +average_heart_rate_rest+:: the average heart rate
|
110
|
-
def initialize(average_heart_rate_rest)
|
111
|
-
average_heart_rate_rest = average_heart_rate_rest.to_s.to_i
|
112
|
-
raise ArgumentError, 'Maximum heart rate is 220.' if average_heart_rate_rest > 220
|
113
|
-
|
114
|
-
@average_heart_rate_rest = average_heart_rate_rest
|
115
|
-
end
|
116
|
-
|
117
|
-
##
|
118
|
-
# Converting +AverageHeartRateRest+ class to a hash.
|
119
|
-
def to_hash
|
120
|
-
{
|
121
|
-
average_heart_rate_rest: @average_heart_rate_rest
|
122
|
-
}
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
##
|
127
|
-
# This class represents a total duration of a session or an
|
128
|
-
# interval in the resting period.
|
129
|
-
class TotalDurationRest
|
130
|
-
# The total duration in seconds.
|
131
|
-
attr_reader :total_duration_rest
|
132
|
-
|
133
|
-
##
|
134
|
-
# Initialization method for the +TotalDurationRest+ class.
|
135
|
-
# Params:
|
136
|
-
# +total_duration_rest+:: the total rest duration
|
137
|
-
def initialize(total_duration_rest)
|
138
|
-
@total_duration_rest = total_duration_rest
|
139
|
-
end
|
140
|
-
|
141
|
-
##
|
142
|
-
# Converting +TotalDurationRest+ class to a hash.
|
143
|
-
def to_hash
|
144
|
-
{
|
145
|
-
total_duration_rest: @total_duration_rest
|
146
|
-
}
|
147
|
-
end
|
148
|
-
end
|