ast-tdl 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e1cae6b9c56c969808cd16ff2d58ec838db46745cf3f6b9b1eb3583536ad93b
4
- data.tar.gz: '0841bfa32e170d22ec587d027086ce4816a86d8116627c8f365000010ebd224a'
3
+ metadata.gz: 958f254f2b529fc7ebac3dbe7b8cea91cdc4aee005e92a3cdf3add30462b5c06
4
+ data.tar.gz: 07b57062cdbd2026c52d33fa6fea08be22eb32f413864b21ad8adab5dde4f468
5
5
  SHA512:
6
- metadata.gz: 179ff4d41c5e51f81f2298bd6363fdbd58afe24b729274a4fc50eb04ffacb3eec453726da1817f4995c55d9923d5202e15c1083f5a7e762993fb7aab08edba48
7
- data.tar.gz: 9e644b6a2f48ec60038a31c503a7d65fbfa4cc8bc89c19f8e9f2da31700f6299794eb292f37cfc2df72b05c9c8d92f8beb420f94c779055761d5fabfe9ca154c
6
+ metadata.gz: b27e545b912fb3dc74fd96b134e13540ecfbf799be3feb25009d1fdad3f29b8811f73a57f96beb18fc4ac84ea9a2ca74c55606fdb7b2c1a1606c52fe74bbcb88
7
+ data.tar.gz: f582e0a61eb96f7a89f004e041a80b753bbe3f5e302efc729b9f170c87d0904b027c22ed21a9b9ff19e8ab02ff8402cc778fba5c26da7ef0b5ffacc599dfa3c4
data/README.md CHANGED
@@ -1,68 +1,83 @@
1
1
  # Training Description Language (TDL) for Artificial Sport Trainer (AST)
2
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
+
3
7
  ## Motivation
4
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.
5
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
+
6
21
  ## Feature diagram
7
- ![scheme](https://user-images.githubusercontent.com/73126820/177509075-977b2e18-ebb7-40ce-9af9-ed7715717bf3.png)
22
+ ![ast-tdl](https://user-images.githubusercontent.com/73126820/193033601-6c94b328-30a4-4b25-86a3-0fb81cebca3d.png)
8
23
 
9
24
  ## Installation
10
- $ gem install ast-tdl
25
+ ```sh
26
+ $ gem install ast-tdl
27
+ ```
11
28
 
12
29
  ## Language description
13
- 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.
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.
14
37
 
15
38
  ## Examples
39
+ ### Example of a sports training
16
40
  ```ruby
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"
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"
23
47
  end
24
48
 
25
- session('Bike ride') do
26
- sport :cycling
27
- info :"Endurance ride with intervals"
28
- average_heart_rate :"140"
29
- total_duration :"120"
49
+ speed('Cross the country') do
50
+ sport Sport::CYCLING
51
+ info :"Endurance ride"
52
+ average_heart_rate :"140"
53
+ total_duration :"120"
30
54
  end
31
55
 
32
- interval('Sample interval') do
33
- sport :cycling
34
- info :Moderate
35
- speed_duration :"5"
36
- recovery_duration :"5"
56
+ interval('Following Emil Zatopek') do
57
+ sport Sport::RUNNING
58
+ info :Hard
59
+ speed_duration :"1"
60
+ recovery_duration :"1"
37
61
  speed_heart_rate :"180"
38
62
  recovery_heart_rate :"90"
39
63
  repetitions :"10"
64
+ type :fixed
40
65
  end
41
- end
42
- ```
43
-
44
- ### Session
45
- ```ruby
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
66
 
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"
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
64
78
  end
65
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.
66
81
 
67
82
  ## License
68
83
  This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
@@ -71,5 +86,6 @@ This package is distributed under the MIT License. This license can be found onl
71
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!
72
87
 
73
88
  ## References
74
-
75
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].
data/lib/ast.rb CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'json'
4
4
  require_relative 'interval'
5
- require_relative 'session'
5
+ require_relative 'power'
6
+ require_relative 'speed'
7
+ require_relative 'sport'
6
8
 
7
9
  ##
8
10
  # This module is intended to be used for building trainings
@@ -11,10 +13,9 @@ module Ast
11
13
  ##
12
14
  # Building a new training from the domain specific language.
13
15
  # Params:
14
- # +name+:: the name of the training
15
16
  # +block+:: training data
16
- def self.build(name, &block)
17
- training = Training.new(name)
17
+ def self.build(&block)
18
+ training = Training.new()
18
19
  training.instance_eval(&block)
19
20
  training
20
21
  end
@@ -26,21 +27,21 @@ module Ast
26
27
  # Initialization method for the +Training+ class.
27
28
  # Params:
28
29
  # +name+:: the name of the training
29
- def initialize(name)
30
- @name = name
31
- @session = []
30
+ def initialize
31
+ @speed = []
32
32
  @interval = []
33
+ @power = []
33
34
  end
34
35
 
35
36
  ##
36
- # Building a new session from the domain specific language.
37
+ # Building a new speed session from the domain specific language.
37
38
  # Params:
38
- # +name+:: the name of the session
39
- # +block+:: session data
40
- def session(name, &block)
41
- training_type = Session.new(name)
39
+ # +name+:: the name of the speed session
40
+ # +block+:: speed session data
41
+ def speed(name, &block)
42
+ training_type = Speed.new(name)
42
43
  training_type.instance_eval(&block)
43
- @session << training_type
44
+ @speed << training_type
44
45
  end
45
46
 
46
47
  ##
@@ -54,19 +55,37 @@ module Ast
54
55
  @interval << interval_data
55
56
  end
56
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
+
57
69
  ##
58
70
  # Converting a training to a string.
59
71
  def to_s
60
- "#{@name} #{@session[0]}"
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"
61
80
  end
62
81
 
63
82
  ##
64
83
  # Converting a training to a JSON-ized string.
65
84
  def json
66
85
  training_json = {
67
- name: @name,
68
- session: @session.collect(&:to_hash),
69
- interval: @interval.collect(&:to_hash)
86
+ speed: @speed.collect(&:to_hash),
87
+ interval: @interval.collect(&:to_hash),
88
+ power: @power.collect(&:to_hash)
70
89
  }
71
90
  JSON.pretty_generate(training_json)
72
91
  end
@@ -76,7 +95,7 @@ module Ast
76
95
  # Params:
77
96
  # +filename+:: the desired name of the file
78
97
  def save_to_file(filename)
79
- f = File.open(filename, 'w')
98
+ f = File.open("../trainings/#{filename}", 'w')
80
99
  f.puts(json)
81
100
  f.close
82
101
  end
data/lib/interval.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'sport'
4
+
3
5
  ##
4
6
  # This class represents an interval.
5
7
  class Interval
@@ -24,6 +26,8 @@ class Interval
24
26
  # Params:
25
27
  # +type+:: the type of the sport
26
28
  def sport(type)
29
+ raise 'The sport name has to be from the Sport class collection.' unless Sport.values.include? type
30
+
27
31
  @sport = type
28
32
  end
29
33
 
@@ -40,7 +44,12 @@ class Interval
40
44
  # Params:
41
45
  # +speed_duration+:: the duration of the speed segment in minutes
42
46
  def speed_duration(speed_duration)
43
- @speed_duration = speed_duration.to_s.to_i
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
44
53
  end
45
54
 
46
55
  ##
@@ -48,7 +57,12 @@ class Interval
48
57
  # Params:
49
58
  # +recovery_duration+:: the duration of the recovery segment in minutes
50
59
  def recovery_duration(recovery_duration)
51
- @recovery_duration = recovery_duration.to_s.to_i
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
52
66
  end
53
67
 
54
68
  ##
@@ -56,7 +70,12 @@ class Interval
56
70
  # Params:
57
71
  # +speed_heart_rate+:: the average speed heart rate in bpm
58
72
  def speed_heart_rate(speed_heart_rate)
59
- @speed_heart_rate = speed_heart_rate.to_s.to_i
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
60
79
  end
61
80
 
62
81
  ##
@@ -64,7 +83,12 @@ class Interval
64
83
  # Params:
65
84
  # +recovery_heart_rate+:: the average speed heart rate in bpm
66
85
  def recovery_heart_rate(recovery_heart_rate)
67
- @recovery_heart_rate = recovery_heart_rate.to_s.to_i
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
68
92
  end
69
93
 
70
94
  ##
@@ -72,7 +96,12 @@ class Interval
72
96
  # Params:
73
97
  # +repetitions+:: number of interval repetitions
74
98
  def repetitions(repetitions)
75
- @repetitions = repetitions.to_s.to_i
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
76
105
  end
77
106
 
78
107
  ##
data/lib/power.rb ADDED
@@ -0,0 +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
data/lib/series.rb ADDED
@@ -0,0 +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
data/lib/speed.rb ADDED
@@ -0,0 +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
data/lib/sport.rb ADDED
@@ -0,0 +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
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.1.1
4
+ version: 0.2.0
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-07-07 00:00:00.000000000 Z
12
+ date: 2022-09-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -24,7 +24,10 @@ files:
24
24
  - lib/ast-tdl.rb
25
25
  - lib/ast.rb
26
26
  - lib/interval.rb
27
- - lib/session.rb
27
+ - lib/power.rb
28
+ - lib/series.rb
29
+ - lib/speed.rb
30
+ - lib/sport.rb
28
31
  homepage: https://github.com/firefly-cpp/ast-tdl
29
32
  licenses:
30
33
  - MIT
data/lib/session.rb DELETED
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # This class represents a session.
5
- class Session
6
- ##
7
- # Initialization method for the +Session+ class.
8
- # Params:
9
- # +name+:: the name of the session
10
- def initialize(name)
11
- @name = name
12
- @sport = ''
13
- @info = ''
14
- @average_heart_rate = 0
15
- @total_duration = 0
16
- end
17
-
18
- ##
19
- # Adding a sport type to the object.
20
- # Params:
21
- # +type+:: the type of the sport
22
- def sport(type)
23
- @sport = type
24
- end
25
-
26
- ##
27
- # Adding a message to the object.
28
- # Params:
29
- # +message+:: the info message
30
- def info(message)
31
- @info = message
32
- end
33
-
34
- ##
35
- # Adding an average heart rate to the object.
36
- # Params:
37
- # +heart_rate+:: the average heart rate in bpm
38
- def average_heart_rate(heart_rate)
39
- @average_heart_rate = heart_rate.to_s.to_i
40
- end
41
-
42
- ##
43
- # Adding a total duration to the object.
44
- # Params:
45
- # +duration+:: the duration in minutes
46
- def total_duration(duration)
47
- @total_duration = duration.to_s.to_i
48
- end
49
-
50
- ##
51
- # Converting a session to a string.
52
- def to_s
53
- "#{@sport} #{@info}"
54
- end
55
-
56
- ##
57
- # Converting a session to a JSON-ized string.
58
- def to_hash
59
- hash = {
60
- name: @name,
61
- sport: @sport,
62
- average_heart_rate: @average_heart_rate,
63
- total_duration: @total_duration,
64
- }
65
-
66
- hash[:info] = @info if @info != ''
67
- hash
68
- end
69
- end