postrunner 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c470dc3a2d1c211ae2c294e98392d9a2621b2ade
4
- data.tar.gz: 201bf757b216cb48ab8bf4cf9ace6fae602b7730
3
+ metadata.gz: 9758b2893a319550c0ee7f653680bf2ccca06c32
4
+ data.tar.gz: 074ef7f186b98726a3519bd9c2c94d05d60ab7e3
5
5
  SHA512:
6
- metadata.gz: 2e9a5edc603c22081b74c538f5249943eabc266bb9eb54083c57e7664f948df27f9881a83f47d2db28862360c614e81cd2139b9775819ce46c7321b1d59a104e
7
- data.tar.gz: 9bcd6103ac667230b1309b1bf31bcdda583ba651d016dee32510786faa8da52d13f4d06daf8c069f0ff4bdfb3d0563a1a324f865f55e80ef82ede97bbc291b20
6
+ metadata.gz: 8f2dfbc2814b86b58260b5ee431903b4cc784bfe3edac8b9f59204a10ffa238e4a7e372ca47e5fb9cf63266d50b9d3ef00ff4aa8fca043c27463100f1624630b
7
+ data.tar.gz: f19618a36b8b04c73ef7292b659e40fa5c7703a15e6e0163fad5fcb5a338378bbc6e637d471eb6f9507e4313db2224225111a8d2a81e1915fc00f972ca9b85fc
@@ -487,7 +487,9 @@ module PostRunner
487
487
  def determine_resting_heart_rate
488
488
  # Find the smallest heart rate. TODO: While being awake.
489
489
  @heart_rate.each_with_index do |heart_rate, idx|
490
- next unless heart_rate && heart_rate > 0
490
+ next unless heart_rate && heart_rate > 0 &&
491
+ @activity_type[idx] != :resting
492
+
491
493
  if @resting_heart_rate.nil? || @resting_heart_rate > heart_rate
492
494
  @resting_heart_rate = heart_rate
493
495
  end
@@ -96,10 +96,10 @@ module PostRunner
96
96
  value = event.speed_low_alert
97
97
  when 'cad_high_alert'
98
98
  name = 'Cadence high alert'
99
- value = "#{event.cad_high_alert} spm"
99
+ value = "#{2 * event.cad_high_alert} spm"
100
100
  when 'cad_low_alert'
101
101
  name = 'Cadence low alert'
102
- value = "#{event.cad_low_alert} spm"
102
+ value = "#{2 * event.cad_low_alert} spm"
103
103
  when 'power_high_alert'
104
104
  name = 'Power high alert'
105
105
  value = event.power_high_alert
@@ -134,6 +134,12 @@ module PostRunner
134
134
  when 'vo2max'
135
135
  name = 'VO2Max'
136
136
  value = event.vo2max
137
+ when 'lactate_threshold_heart_rate'
138
+ name = 'Lactate Threshold Heart Rate'
139
+ value = "#{event.lactate_threshold_heart_rate} bpm"
140
+ when 'lactate_threshold_speed'
141
+ name = 'Lactate Threshold Pace'
142
+ value = pace(event, 'lactate_threshold_speed')
137
143
  else
138
144
  name = event.event
139
145
  value = event.data
@@ -143,6 +149,18 @@ module PostRunner
143
149
  table.cell(value)
144
150
  end
145
151
 
152
+ def pace(fdr, field, show_unit = true)
153
+ speed = fdr.get(field)
154
+ case @unit_system
155
+ when :metric
156
+ "#{speedToPace(speed)}#{show_unit ? ' min/km' : ''}"
157
+ when :statute
158
+ "#{speedToPace(speed, 1609.34)}#{show_unit ? ' min/mi' : ''}"
159
+ else
160
+ Log.fatal "Unknown unit system #{@unit_system}"
161
+ end
162
+ end
163
+
146
164
  end
147
165
 
148
166
  end
@@ -211,6 +211,23 @@ module PostRunner
211
211
  list.sort
212
212
  end
213
213
 
214
+ # Read in all Monitoring_B FIT files that overlap with the given interval.
215
+ # @param start_date [Time] Interval start time
216
+ # @param end_date [Time] Interval end date
217
+ # @return [Array of Monitoring_B] Content of Monitoring_B FIT files
218
+ def monitorings(start_date, end_date)
219
+ monitorings = []
220
+ @store['devices'].each do |id, device|
221
+ monitorings += device.monitorings(start_date.gmtime, end_date.gmtime)
222
+ end
223
+
224
+ monitorings.reverse.map do |m|
225
+ read_fit_file(File.join(fit_file_dir(m.fit_file_name, m.device.long_uid,
226
+ 'monitor'), m.fit_file_name))
227
+ end
228
+ end
229
+
230
+
214
231
  # Return the reference index of the given FFS_Activity.
215
232
  # @param activity [FFS_Activity]
216
233
  # @return [Fixnum] Reference index as used in the UI
@@ -320,7 +337,6 @@ module PostRunner
320
337
  end
321
338
 
322
339
  def daily_report(day)
323
- monitorings = []
324
340
  # 'day' specifies the current day. But we don't know what timezone the
325
341
  # watch was set to for a given date. The files are always named after
326
342
  # the moment of finishing the recording expressed as GMT time.
@@ -328,17 +344,12 @@ module PostRunner
328
344
  # file. Recording is always flipped to a new file at midnight GMT but
329
345
  # there are usually multiple files per GMT day.
330
346
  day_as_time = Time.parse(day).gmtime
331
- @store['devices'].each do |id, device|
332
- # To get weekly intensity minutes we need 7 days of data prior to the
333
- # current date and 1 day after to include the following night. We add
334
- # at least 12 extra hours to accomodate time zone changes.
335
- monitorings += device.monitorings(day_as_time - 8 * 24 * 60 * 60,
336
- day_as_time + 36 * 60 * 60)
337
- end
338
- monitoring_files = monitorings.reverse.map do |m|
339
- read_fit_file(File.join(fit_file_dir(m.fit_file_name, m.device.long_uid,
340
- 'monitor'), m.fit_file_name))
341
- end
347
+ # To get weekly intensity minutes we need 7 days of data prior to the
348
+ # current date and 1 day after to include the following night. We add
349
+ # at least 12 extra hours to accomodate time zone changes.
350
+ monitoring_files = monitorings(day_as_time - 8 * 24 * 60 * 60,
351
+ day_as_time + 36 * 60 * 60)
352
+
342
353
  puts MonitoringStatistics.new(monitoring_files).daily(day)
343
354
  end
344
355
 
@@ -352,16 +363,12 @@ module PostRunner
352
363
  # to a new file at midnight GMT but there are usually multiple files per
353
364
  # GMT day.
354
365
  day_as_time = Time.parse(day).gmtime
355
- @store['devices'].each do |id, device|
356
- # We are looking for all files that potentially overlap with our
357
- # localtime day.
358
- monitorings += device.monitorings(day_as_time - 8 * 24 * 60 * 60,
359
- day_as_time + 33 * 24 * 60 * 60)
360
- end
361
- monitoring_files = monitorings.sort.map do |m|
362
- read_fit_file(File.join(fit_file_dir(m.fit_file_name, m.device.long_uid,
363
- 'monitor'), m.fit_file_name))
364
- end
366
+ # To get weekly intensity minutes we need 7 days of data prior to the
367
+ # current month start and 1 after to inclide the following night. We add
368
+ # at least 12 extra hours to accomondate time zone changes.
369
+ monitoring_files = monitorings(day_as_time - 8 * 24 * 60 * 60,
370
+ day_as_time + 32 * 24 * 60 * 60)
371
+
365
372
  puts MonitoringStatistics.new(monitoring_files).monthly(day)
366
373
  end
367
374
 
@@ -154,7 +154,7 @@ EOT
154
154
  Log.level = Logger::DEBUG
155
155
  end
156
156
  opts.on('-h', '--help', 'Show this message') do
157
- $stderr.puts opts
157
+ $stdout.puts opts
158
158
  return nil
159
159
  end
160
160
  opts.on('--version', 'Show version number') do
@@ -189,7 +189,7 @@ import [ <fit file> | <directory> ]
189
189
  previous import is being used.
190
190
 
191
191
  list
192
- List all FIT files stored in the data base.
192
+ List all FIT files stored in the database.
193
193
 
194
194
  monthly [ <YYYY-MM-DD> ]
195
195
 
@@ -197,11 +197,12 @@ module PostRunner
197
197
  t = FlexiTable.new
198
198
  left = { :halign => :left }
199
199
  right = { :halign => :right }
200
- t.set_column_attributes([ left ] + [ right ] * 7)
200
+ t.set_column_attributes([ left ] + [ right ] * 10)
201
201
  t.head
202
- t.row([ 'Day', 'Steps', '%', 'Goal', 'Intensity', '%',
203
- 'Floors', '% of 10' ])
204
- t.row([ '', '', '', '', 'Minutes', 'Week', '', '' ])
202
+ t.row([ 'Day', 'Steps', '% of', 'Goal', 'Wk. Int.', '% of',
203
+ 'Floors', '% of', 'Floors', 'Dist.', 'Cals.' ])
204
+ t.row([ '', '', 'Goal', 'Steps', 'Minutes', '150', 'clmbd.', '10',
205
+ 'descd.', 'km', 'kCal' ])
205
206
  t.body
206
207
  totals = Hash.new(0)
207
208
  counted_days = 0
@@ -238,9 +239,23 @@ module PostRunner
238
239
 
239
240
  floors = analyzer.total_floors
240
241
  floors_climbed = floors[:floors_climbed]
241
- totals[:floors] += floors_climbed
242
+ totals[:floors_climbed] += floors_climbed
242
243
  t.cell(floors_climbed)
243
244
  t.cell(percent(floors_climbed, 10))
245
+
246
+ floors_descended = floors[:floors_descended]
247
+ totals[:floors_descended] += floors_descended
248
+ t.cell(floors_descended)
249
+
250
+
251
+ distance = steps_distance_calories[:distance]
252
+ totals[:distance] += distance
253
+ t.cell(distance.to_i)
254
+
255
+ calories = steps_distance_calories[:calories]
256
+ totals[:calories] += calories
257
+ t.cell(calories.to_i)
258
+
244
259
  t.new_row
245
260
  counted_days += 1
246
261
  end
@@ -252,8 +267,11 @@ module PostRunner
252
267
  t.cell(totals[:steps_goal])
253
268
  t.cell(totals[:intensity_minutes].to_i)
254
269
  t.cell('')
255
- t.cell(totals[:floors])
270
+ t.cell(totals[:floors_climbed])
256
271
  t.cell('')
272
+ t.cell(totals[:floors_descended])
273
+ t.cell(totals[:distance].to_i)
274
+ t.cell(totals[:calories].to_i)
257
275
  t.new_row
258
276
 
259
277
  if counted_days > 0
@@ -263,8 +281,11 @@ module PostRunner
263
281
  t.cell((totals[:steps_goal] / counted_days).to_i)
264
282
  t.cell((totals[:intensity_minutes] / counted_days).to_i)
265
283
  t.cell(percent(totals[:intensity_minutes], (counted_days / 7.0) * 150))
266
- t.cell((totals[:floors] / counted_days).to_i)
284
+ t.cell((totals[:floors_climbed] / counted_days).to_i)
267
285
  t.cell(percent(totals[:floors] / counted_days, 10))
286
+ t.cell((totals[:floors_descended] / counted_days).to_i)
287
+ t.cell('%.0f' % (totals[:distance] / counted_days))
288
+ t.cell((totals[:calories] / counted_days).to_i)
268
289
  end
269
290
 
270
291
  t
@@ -354,7 +375,7 @@ module PostRunner
354
375
  ma.intensity_minutes[:moderate_minutes] +
355
376
  2 * ma.intensity_minutes[:vigorous_minutes]
356
377
 
357
- break if current_date.wday == @first_day_of_week
378
+ break if date.wday == @first_day_of_week
358
379
  end
359
380
  end
360
381
 
@@ -11,5 +11,5 @@
11
11
  #
12
12
 
13
13
  module PostRunner
14
- VERSION = "0.4.0"
14
+ VERSION = "0.5.0"
15
15
  end
@@ -27,7 +27,7 @@ should work on other operating systems as well.}
27
27
  spec.require_paths = ["lib"]
28
28
  spec.required_ruby_version = '>=2.0'
29
29
 
30
- spec.add_dependency 'fit4ruby', '~> 1.1.0'
30
+ spec.add_dependency 'fit4ruby', '~> 1.2.0'
31
31
  spec.add_dependency 'perobs', '~> 2.2'
32
32
  spec.add_dependency 'nokogiri', '~> 1.6'
33
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postrunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schlaeger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fit4ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.0
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: perobs
29
29
  requirement: !ruby/object:Gem::Requirement