fit4ruby 3.10.0 → 3.11.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: d40c0fc77ae8184b42aa80643dfb6b0f036b3eab7f37bdb8ee66b76a9feaafc5
4
- data.tar.gz: 6e8ce1d3472e67a3c7ba58200fdf6b395e009349e68dca0618a92b3176f8ff19
3
+ metadata.gz: 550fffeb71313287a1a1037974608c23b738da5a34c6aaca39374fea562b7426
4
+ data.tar.gz: 923417ab9520777208f4bd830696d7012c68b8ad2e7d39572749bad42301d560
5
5
  SHA512:
6
- metadata.gz: 366a5e5b4f55ee4918c822e26eda16d6381a1e872b8af68504283def72f096e00717dc68f9bd52403d8e6662c4e2aff83d12d26e201d568794bca407513b5bd8
7
- data.tar.gz: a4eda75c90f65d26b9786570ee0fa07e578a3d627996170385411305b17a7a9697b043de70b335e485f3ca5780cdb0157506d34212ab0c54947c4111fb951fbf
6
+ metadata.gz: 990ce2d227826d09a114e55652bbc4287dc1b8c2e1a4a534a6ade8bbcc2baed3a321a4508ca6b880a6af745c007f58a60649b0f32bf75a6782f0e7df1498f26d
7
+ data.tar.gz: 3e6fe4df5bda73caa364937a13b1e4a764a65a55723026260f381d9a108441a030dc8ec8ff2876e7ece8527575571933164f8c23eae485e8f1ea09c479fe6924
data/fit4ruby.gemspec CHANGED
@@ -22,7 +22,7 @@ EOT
22
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
23
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
24
  spec.require_paths = ["lib"]
25
- spec.required_ruby_version = '>=2.0'
25
+ spec.required_ruby_version = '>=2.3'
26
26
 
27
27
  spec.add_dependency('bindata', '~>2.4.8')
28
28
  spec.add_development_dependency('yard', '~>0.9.20')
@@ -188,7 +188,7 @@ module Fit4Ruby
188
188
  # sessions.
189
189
  def total_distance
190
190
  d = 0.0
191
- @sessions.each { |s| d += s.total_distance }
191
+ @sessions.each { |s| d += (s.total_distance || 0) }
192
192
  d
193
193
  end
194
194
 
@@ -315,11 +315,21 @@ module Fit4Ruby
315
315
  @sessions[0].sport
316
316
  end
317
317
 
318
+ # Sets the sport type of this activity.
319
+ def sport=(sport)
320
+ @sessions[0].sport = sport
321
+ end
322
+
318
323
  # Returns the sport subtype of this activity.
319
324
  def sub_sport
320
325
  @sessions[0].sub_sport
321
326
  end
322
327
 
328
+ # Sets the sport subtype of this activity.
329
+ def sub_sport=(sub_sport)
330
+ @sessions[0].sub_sport = sub_sport
331
+ end
332
+
323
333
  # Write the Activity data to a file.
324
334
  # @param io [IO] File reference
325
335
  # @param id_mapper [FitMessageIdMapper] Maps global FIT record types to
@@ -639,4 +649,3 @@ module Fit4Ruby
639
649
  end
640
650
 
641
651
  end
642
-
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby -w
2
- # encoding: UTF-8
3
2
  #
4
3
  # = Converters.rb -- Fit4Ruby - FIT file processing library for Ruby
5
4
  #
@@ -9,34 +8,47 @@
9
8
  # it under the terms of version 2 of the GNU General Public License as
10
9
  # published by the Free Software Foundation.
11
10
  #
11
+ # frozen_string_literal: true
12
12
 
13
13
  module Fit4Ruby
14
-
15
14
  module Converters
15
+ FACTORS = {
16
+ 'm' => { 'km' => 0.001, 'in' => 39.3701, 'ft' => 3.28084,
17
+ 'mi' => 0.000621371 },
18
+ 'mm' => { 'cm' => 0.1, 'in' => 0.0393701 },
19
+ 'm/s' => { 'km/h' => 3.6, 'mph' => 2.23694 },
20
+ 'min/km' => { 'min/mi' => 1.60934 },
21
+ 'kg' => { 'lbs' => 2.20462262 },
22
+ 'C' => { 'F' => 9.0 / 5.0 }
23
+ }.freeze
24
+ OFFSETS = {
25
+ 'C' => { 'F' => 32 }
26
+ }.freeze
16
27
 
17
28
  def conversion_factor(from_unit, to_unit)
18
- factors = {
19
- 'm' => { 'km' => 0.001, 'in' => 39.3701, 'ft' => 3.28084,
20
- 'mi' => 0.000621371 },
21
- 'mm' => { 'cm' => 0.1, 'in' => 0.0393701 },
22
- 'm/s' => { 'km/h' => 3.6, 'mph' => 2.23694 },
23
- 'min/km' => { 'min/mi' => 1.60934 },
24
- 'kg' => { 'lbs' => 0.453592 }
25
- }
26
29
  return 1.0 if from_unit == to_unit
27
- unless factors.include?(from_unit)
28
- Log.fatal "No conversion factors defined for unit " +
30
+
31
+ unless FACTORS.include?(from_unit)
32
+ Log.fatal 'No conversion factors defined for unit ' \
29
33
  "'#{from_unit}' to '#{to_unit}'"
30
34
  end
31
35
 
32
- factor = factors[from_unit][to_unit]
36
+ factor = FACTORS[from_unit][to_unit]
33
37
  if factor.nil?
34
- Log.fatal "No conversion factor from '#{from_unit}' to '#{to_unit}' " +
35
- "defined."
38
+ Log.fatal "No conversion factor from '#{from_unit}' to '#{to_unit}' " \
39
+ 'defined.'
36
40
  end
41
+
37
42
  factor
38
43
  end
39
44
 
45
+ def conversion_offset(from_unit, to_unit)
46
+ return 0.0 if from_unit == to_unit || !OFFSETS.include?(from_unit) ||
47
+ !OFFSETS[from_unit].include?(to_unit)
48
+
49
+ OFFSETS[from_unit][to_unit]
50
+ end
51
+
40
52
  def speedToPace(speed, distance = 1000.0)
41
53
  if speed && speed > 0.01
42
54
  # We only show 2 fractional digits, so make sure we round accordingly
@@ -89,4 +101,3 @@ module Fit4Ruby
89
101
  end
90
102
 
91
103
  end
92
-
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby -w
2
- # encoding: UTF-8
3
2
  #
4
3
  # = FitDataRecord.rb -- Fit4Ruby - FIT file processing library for Ruby
5
4
  #
@@ -9,22 +8,21 @@
9
8
  # it under the terms of version 2 of the GNU General Public License as
10
9
  # published by the Free Software Foundation.
11
10
  #
11
+ # frozen_string_literal: true
12
12
 
13
13
  require 'fit4ruby/FitMessageIdMapper'
14
- require 'fit4ruby/GlobalFitMessages.rb'
14
+ require 'fit4ruby/GlobalFitMessages'
15
15
  require 'fit4ruby/BDFieldNameTranslator'
16
16
 
17
17
  module Fit4Ruby
18
-
19
18
  class FitDataRecord
20
-
21
19
  include Converters
22
20
  include BDFieldNameTranslator
23
21
 
24
- RecordOrder = [ 'user_data', 'user_profile', 'workout', 'workout_set',
25
- 'device_info', 'data_sources', 'event',
26
- 'record', 'lap', 'length', 'session', 'heart_rate_zones',
27
- 'personal_records' ]
22
+ RecordOrder = ['user_data', 'user_profile', 'workout', 'workout_set',
23
+ 'device_info', 'data_sources', 'event',
24
+ 'record', 'lap', 'length', 'session', 'heart_rate_zones',
25
+ 'personal_records']
28
26
 
29
27
  attr_reader :message, :timestamp
30
28
 
@@ -33,7 +31,7 @@ module Fit4Ruby
33
31
 
34
32
  # Create instance variables that correspond to every field of the
35
33
  # corresponding FIT data record.
36
- @message.fields_by_name.each do |name, field|
34
+ @message.fields_by_name.each do |name, _|
37
35
  create_instance_variable(name)
38
36
  end
39
37
 
@@ -51,9 +49,9 @@ module Fit4Ruby
51
49
  end
52
50
 
53
51
  def set(name, value)
54
- ivar_name = '@' + name
52
+ ivar_name = "@#{name}"
55
53
  unless instance_variable_defined?(ivar_name)
56
- Log.debug("Unknown FIT record field '#{name}' in global message " +
54
+ Log.debug("Unknown FIT record field '#{name}' in global message " \
57
55
  "#{@message.name} (#{@message.number}).")
58
56
  return
59
57
  end
@@ -62,7 +60,7 @@ module Fit4Ruby
62
60
 
63
61
  def get(name)
64
62
  # This is a request for a native FIT field.
65
- ivar_name = '@' + name
63
+ ivar_name = "@#{name}"
66
64
  return nil unless instance_variable_defined?(ivar_name)
67
65
 
68
66
  instance_variable_get(ivar_name)
@@ -82,17 +80,17 @@ module Fit4Ruby
82
80
  end
83
81
  end
84
82
 
85
- value * conversion_factor(unit, to_unit)
83
+ conversion_offset(unit, to_unit) + value * conversion_factor(unit, to_unit)
86
84
  end
87
85
 
88
- def ==(fdr)
89
- @message.each_field(field_values_as_hash) do |number, field|
90
- ivar_name = '@' + field.name
86
+ def ==(other)
87
+ @message.each_field(field_values_as_hash) do |_, field|
88
+ ivar_name = "@#{field.name}"
91
89
  # Comparison of values is done in the fit file format as the accuracy
92
90
  # of native formats is better and could lead to wrong results if a
93
91
  # value hasn't been read back from a fit file yet.
94
92
  v1 = field.native_to_fit(instance_variable_get(ivar_name))
95
- v2 = field.native_to_fit(fdr.instance_variable_get(ivar_name))
93
+ v2 = field.native_to_fit(other.instance_variable_get(ivar_name))
96
94
 
97
95
  return false unless v1 == v2
98
96
  end
@@ -100,16 +98,15 @@ module Fit4Ruby
100
98
  true
101
99
  end
102
100
 
103
- def <=>(fdr)
104
- @timestamp == fdr.timestamp ?
101
+ def <=>(other)
102
+ @timestamp == other.timestamp ?
105
103
  RecordOrder.index(@message.name) <=>
106
- RecordOrder.index(fdr.message.name) :
107
- @timestamp <=> fdr.timestamp
104
+ RecordOrder.index(other.message.name) :
105
+ @timestamp <=> other.timestamp
108
106
  end
109
107
 
110
108
  def write(io, id_mapper)
111
- global_fit_message = @message.construct(
112
- field_values = field_values_as_hash)
109
+ global_fit_message = @message.construct(field_values = field_values_as_hash)
113
110
 
114
111
  # Map the global message number to the current local message number.
115
112
  unless (local_message_number = id_mapper.get_local(global_fit_message))
@@ -134,10 +131,10 @@ module Fit4Ruby
134
131
 
135
132
  # Fill the BinData::Struct object with the values from the corresponding
136
133
  # instance variables.
137
- global_fit_message.each_field(field_values) do |number, field|
134
+ global_fit_message.each_field(field_values) do |_, field|
138
135
  bin_data_type = FitDefinitionFieldBase.fit_type_to_bin_data(field.type)
139
136
  field_name = to_bd_field_name(field.name)
140
- field_def = [ bin_data_type, field_name ]
137
+ field_def = [bin_data_type, field_name]
141
138
 
142
139
  iv = "@#{field.name}"
143
140
  if instance_variable_defined?(iv) &&
@@ -147,7 +144,7 @@ module Fit4Ruby
147
144
  # If we don't have a corresponding variable or the variable is nil
148
145
  # we write the 'undefined' value instead.
149
146
  value = FitDefinitionFieldBase.undefined_value(field.type)
150
- values[field.name] = field.opts[:array] ? [ value ] :
147
+ values[field.name] = field.opts[:array] ? [value] :
151
148
  field.type == 'string' ? '' : value
152
149
  end
153
150
 
@@ -157,17 +154,17 @@ module Fit4Ruby
157
154
  values[field.name] += "\0"
158
155
  elsif field.opts[:array]
159
156
  # For Arrays we use a BinData::Array to write them.
160
- field_def = [ :array, field_name,
161
- { :type => bin_data_type,
162
- :initial_length => values[field.name].size } ]
157
+ field_def = [:array, field_name,
158
+ { type: bin_data_type,
159
+ initial_length: values[field.name].size }]
163
160
  end
164
161
  fields << field_def
165
162
  end
166
- bd = BinData::Struct.new(:endian => :little, :fields => fields)
163
+ bd = BinData::Struct.new(endian: :little, fields: fields)
167
164
 
168
165
  # Fill the BinData::Struct object with the values from the corresponding
169
166
  # instance variables.
170
- global_fit_message.each_field(field_values) do |number, field|
167
+ global_fit_message.each_field(field_values) do |_, field|
171
168
  bd[to_bd_field_name(field.name)] = values[field.name]
172
169
  end
173
170
 
@@ -183,13 +180,13 @@ module Fit4Ruby
183
180
  }
184
181
 
185
182
  @message.each_field(field_values_as_hash) do |number, field|
186
- ivar_name = '@' + field.name
183
+ ivar_name = "@#{field.name}"
187
184
  fit_value = field.native_to_fit(instance_variable_get(ivar_name))
188
185
  unless field.is_undefined?(fit_value)
189
186
  fld = {
190
187
  'number' => number,
191
188
  'value' => field.fit_to_native(fit_value),
192
- #'human' => field.to_human(fit_value),
189
+ # 'human' => field.to_human(fit_value),
193
190
  'type' => field.type
194
191
  }
195
192
  fld['unit'] = field.opts[:unit] if field.opts[:unit]
@@ -214,7 +211,7 @@ module Fit4Ruby
214
211
  # set of fields. It does not contain any AltField objects.
215
212
  field_values = {}
216
213
  @message.fields_by_name.each_key do |name|
217
- field_values[name] = instance_variable_get('@' + name)
214
+ field_values[name] = instance_variable_get("@#{name}")
218
215
  end
219
216
 
220
217
  field_values
@@ -223,12 +220,9 @@ module Fit4Ruby
223
220
  def create_instance_variable(name)
224
221
  # Create a new instance variable for 'name'. We initialize it with a
225
222
  # provided default value or nil.
226
- instance_variable_set('@' + name, nil)
223
+ instance_variable_set("@#{name}", nil)
227
224
  # And create an accessor method for it as well.
228
225
  self.class.__send__(:attr_accessor, name)
229
226
  end
230
-
231
227
  end
232
-
233
228
  end
234
-
@@ -16,6 +16,10 @@ module Fit4Ruby
16
16
 
17
17
  GlobalFitDictionaries = GlobalFitDictList.new do
18
18
 
19
+ dict 'activity'
20
+ entry 0, 'manual'
21
+ entry 1, 'auto_multi_sport'
22
+
19
23
  dict 'activity_type'
20
24
  entry 0, 'generic'
21
25
  entry 1, 'running'
@@ -23,50 +27,8 @@ module Fit4Ruby
23
27
  entry 3, 'transition'
24
28
  entry 4, 'fitness_equipment'
25
29
  entry 5, 'swimming'
26
- entry 6, 'basketball'
27
- entry 7, 'soccer'
28
- entry 8, 'tennis'
29
- entry 9, 'american_football'
30
- entry 10, 'training'
31
- entry 11, 'walking'
32
- entry 12, 'cross_country_skiing'
33
- entry 13, 'alpine_skiing'
34
- entry 14, 'snowboarding'
35
- entry 15, 'rowing'
36
- entry 16, 'mountaineering'
37
- entry 17, 'hiking'
38
- entry 18, 'multisport'
39
- entry 19, 'paddling'
40
- entry 20, 'flying'
41
- entry 21, 'e_biking'
42
- entry 22, 'motorcycling'
43
- entry 23, 'boating'
44
- entry 24, 'driving'
45
- entry 25, 'golf'
46
- entry 26, 'hang_gliding'
47
- entry 27, 'horseback_riding'
48
- entry 28, 'hunting'
49
- entry 29, 'fishing'
50
- entry 30, 'inline_skating'
51
- entry 31, 'rock_climbing'
52
- entry 32, 'sailing'
53
- entry 33, 'ice_skating'
54
- entry 34, 'sky_diving'
55
- entry 35, 'snowshoeing'
56
- entry 36, 'snowmobiling'
57
- entry 37, 'stand_up_paddleboarding'
58
- entry 38, 'surfing'
59
- entry 39, 'wakeboarding'
60
- entry 40, 'water_skiing'
61
- entry 41, 'kayaking'
62
- entry 42, 'rafting'
63
- entry 43, 'windsurfing'
64
- entry 44, 'kitesurfing'
65
- entry 45, 'tactical'
66
- entry 46, 'jumpmaster'
67
- entry 47, 'boxing'
68
- entry 48, 'floor_climbing'
69
- entry 53, 'diving'
30
+ entry 6, 'walking'
31
+ entry 8, 'sedentary'
70
32
  entry 254, 'all'
71
33
 
72
34
  dict 'activity_level'
@@ -642,7 +642,7 @@ module Fit4Ruby
642
642
  field 83, 'uint16', 'vertical_ratio', :scale => 100, :unit => '%' # guessed
643
643
  field 84, 'uint16', 'gct_balance', :scale => 100, :unit => '%' # guessed
644
644
  field 85, 'uint16', 'stride_length', :scale => 10000, :unit => 'm' # guessed
645
- field 87, 'uint16', 'undefined_value_87' # first seen on F3 FW6.80
645
+ field 87, 'uint16', 'stroke_distance', :scale => 100, :unit => 'm'
646
646
  field 88, 'uint16', 'undefined_value_88' # first seen on F3HR FW3.60
647
647
  field 90, 'sint8', 'performance_condition' # guessed
648
648
  field 100, 'sint32', 'undocumented_field_100'
@@ -817,7 +817,7 @@ module Fit4Ruby
817
817
  message 34, 'activity'
818
818
  field 0, 'uint32', 'total_timer_time', :type => 'duration', :scale => 1000
819
819
  field 1, 'uint16', 'num_sessions'
820
- field 2, 'enum', 'type', :dict => 'activity_type'
820
+ field 2, 'enum', 'type', :dict => 'activity'
821
821
  field 3, 'enum', 'event', :dict => 'event'
822
822
  field 4, 'enum', 'event_type', :dict => 'event_type'
823
823
  field 5, 'uint32', 'local_timestamp', :type => 'date_time'
@@ -1115,14 +1115,19 @@ module Fit4Ruby
1115
1115
  field 73, 'uint16z', 'undocumented_field_73'
1116
1116
  field 254, 'uint16', 'message_index'
1117
1117
 
1118
- # Not part of the official ANT SDK doc.
1119
- message 160, 'undocumented_160'
1120
- field 3, 'uint32', 'undocumented_field_3'
1121
- field 4, 'uint32', 'undocumented_field_4'
1118
+ message 160, 'gps_metadata'
1119
+ field 0, 'uint16', 'timestamp_ms'
1120
+ field 1, 'sint32', 'position_lat'
1121
+ field 2, 'sint32', 'position_long'
1122
+ field 3, 'uint32', 'enhanced_altitude', :scale => 5, :offset => 500, :unit => 'm'
1123
+ field 4, 'uint32', 'enhanced_speed', :unit => 'm/s', :scale => 1000
1124
+ field 5, 'uint16', 'heading', :unit => 'degrees', :scale => 100
1125
+ field 6, 'uint32', 'utc_timestamp', :type => 'date_time'
1126
+ field 7, 'sint16', 'velocity', :array => true, :scale => 100, :unit => 'm/s'
1127
+ field 253, 'uint32', 'timestamp', :type => 'date_time'
1122
1128
 
1123
- # Not part of the official ANT SDK doc.
1124
- message 188, 'undocumented_188'
1125
- field 0, 'enum', 'undocumented_field_0'
1129
+ message 188, 'ohr_settings'
1130
+ field 0, 'enum', 'switch'
1126
1131
  field 253, 'uint32', 'timestamp', :type => 'date_time'
1127
1132
 
1128
1133
  message 206, 'field_description'
@@ -1263,6 +1268,24 @@ module Fit4Ruby
1263
1268
  field 252, 'uint8', 'undocumented_field_252'
1264
1269
  field 253, 'uint32', 'timestamp', :type => 'date_time'
1265
1270
 
1271
+ # Not part of the official ANT SDK doc.
1272
+ message 312, 'undocumented_312'
1273
+ field 0, 'enum', 'undocumented_field_0'
1274
+ field 9, 'uint32', 'interval_start', :type => 'date_time'
1275
+ field 15, 'uint8', 'min_heart_rate', :unit => 'bpm'
1276
+ field 16, 'uint8', 'max_heart_rate', :unit => 'bpm'
1277
+ field 21, 'sint32', 'position_lat', :type => 'coordinate'
1278
+ field 22, 'sint32', 'position_long', :type => 'coordinate'
1279
+ field 27, 'uint32', 'interval_end', :type => 'date_time'
1280
+ field 32, 'sint8', 'avg_temperature', :unit => 'C'
1281
+ field 33, 'sint8', 'max_temperature', :unit => 'C'
1282
+ field 34, 'sint8', 'min_temperature', :unit => 'C'
1283
+ field 37, 'uint16', 'undocumented_field_37'
1284
+ field 38, 'uint16', 'undocumented_field_38'
1285
+ field 39, 'uint16', 'undocumented_field_39'
1286
+ field 253, 'uint32', 'timestamp', :type => 'date_time'
1287
+ field 254, 'uint16', 'message_index'
1288
+
1266
1289
  # Not part of the official ANT SDK doc.
1267
1290
  message 325, 'undocumented_325'
1268
1291
  field 0, 'uint8', 'undocumented_field_0'
@@ -1305,4 +1328,3 @@ module Fit4Ruby
1305
1328
  end
1306
1329
 
1307
1330
  end
1308
-
@@ -1,4 +1,4 @@
1
1
  module Fit4Ruby
2
2
  # The version number of the library.
3
- VERSION = '3.10.0'
3
+ VERSION = '3.11.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fit4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schlaeger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-14 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -178,7 +178,7 @@ homepage: https://github.com/scrapper/fit4ruby
178
178
  licenses:
179
179
  - GNU GPL version 2
180
180
  metadata: {}
181
- post_install_message:
181
+ post_install_message:
182
182
  rdoc_options: []
183
183
  require_paths:
184
184
  - lib
@@ -186,15 +186,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - ">="
188
188
  - !ruby/object:Gem::Version
189
- version: '2.0'
189
+ version: '2.3'
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubygems_version: 3.2.32
197
- signing_key:
196
+ rubygems_version: 3.4.10
197
+ signing_key:
198
198
  specification_version: 4
199
199
  summary: Library to read and write GARMIN FIT files.
200
200
  test_files: