forked from cmaion/polar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolar_physdata2txt
executable file
·52 lines (44 loc) · 3.46 KB
/
polar_physdata2txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
# Converts RAW Polar user physical data data files in txt file format
require "#{File.dirname(__FILE__)}/lib/polar_data_parser"
def usage
puts "Usage:"
puts " #{__FILE__} <directory> [<txt file>]"
end
dir = ARGV[0]
unless dir
usage
exit -2
end
output_file = ARGV[1] || File.join(dir, 'output.txt')
def output_txt(parsed)
phys = parsed[:phys]
start_time = phys.snapshot_start_time && phys.snapshot_start_time.date.year > 0 ? DateTime.new(phys.snapshot_start_time.date.year, phys.snapshot_start_time.date.month, phys.snapshot_start_time.date.day, phys.snapshot_start_time.time.hour, phys.snapshot_start_time.time.minute, phys.snapshot_start_time.time.seconds, "%+i" % (phys.snapshot_start_time.time_zone_offset / 60)).to_time.to_s : 'N/D'
buffer = ""
buffer << "Snapshot date : #{start_time}\n"
buffer << "Last modified : #{pb_sysdatetime_to_string phys.last_modified}\n"
buffer << "Gender : #{phys.gender.value.to_s}\n"
buffer << "Birthday : #{pb_date_to_string phys.birthday.value}\n"
buffer << "Weight : #{"%.1f" % phys.weight.value} [#{phys.weight.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.weight.last_modified})\n"
buffer << "Height : #{"%.1f" % phys.height.value} (last modified #{pb_sysdatetime_to_string phys.height.last_modified})\n"
buffer << "HR max : #{phys.maximum_heartrate.value} [#{phys.maximum_heartrate.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.maximum_heartrate.last_modified})\n"
buffer << "HR resting : #{phys.resting_heartrate.value} [#{phys.resting_heartrate.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.resting_heartrate.last_modified})\n"
buffer << "Aerobic threshold : #{phys.aerobic_threshold.value} [#{phys.aerobic_threshold.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.aerobic_threshold.last_modified})\n"
buffer << "Anaerobic threshold : #{phys.anaerobic_threshold.value} [#{phys.anaerobic_threshold.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.anaerobic_threshold.last_modified})\n"
buffer << "VO2max : #{phys.vo2max.value} [#{phys.vo2max.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.vo2max.last_modified})\n"
buffer << "Training background : #{phys.training_background.value.to_s} (last modified #{pb_sysdatetime_to_string phys.training_background.last_modified})\n"
buffer << "Typical day : #{phys.typical_day.value.to_s} (last modified #{pb_sysdatetime_to_string phys.typical_day.last_modified})\n" if phys.typical_day
buffer << "Weekly recovery time sum : #{phys.weekly_recovery_time_sum.value} (last modified #{pb_sysdatetime_to_string phys.weekly_recovery_time_sum.last_modified})\n" if phys.weekly_recovery_time_sum
buffer << "Functional threshold power: #{phys.functional_threshold_power.value} [#{phys.functional_threshold_power.setting_source.to_s}] (last modified #{pb_sysdatetime_to_string phys.functional_threshold_power.last_modified})\n" if phys.functional_threshold_power
buffer
end
puts "Converting Polar user physical data in '#{dir}' to TXT format as '#{output_file}'..."
parsed = PolarDataParser.parse_user_physdata(dir)
if parsed.key?(:phys)
File.open(output_file, 'w') do |f|
f << output_txt(parsed)
end
puts "Done"
else
puts "Error: couldn't find user physical data"
end