forked from cmaion/polar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolar_physdata2txt
executable file
·52 lines (44 loc) · 4.05 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.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 : #{PolarData::PbUserGender::Gender.value_to_names_map[phys.gender.value].first.to_s}\n"
buffer << "Birthday : #{pb_date_to_string phys.birthday.value}\n"
buffer << "Weight : #{"%.1f" % phys.weight.value} [#{PolarData::PbUserWeight::WeightSettingSource.value_to_names_map[phys.weight.setting_source].first.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} [#{PolarData::PbUserHrAttribute::HrSettingSource.value_to_names_map[phys.maximum_heartrate.setting_source].first.to_s}] (last modified #{pb_sysdatetime_to_string phys.maximum_heartrate.last_modified})\n"
buffer << "HR resting : #{phys.resting_heartrate.value} [#{PolarData::PbUserHrAttribute::HrSettingSource.value_to_names_map[phys.resting_heartrate.setting_source].first.to_s}] (last modified #{pb_sysdatetime_to_string phys.resting_heartrate.last_modified})\n"
buffer << "Aerobic threshold : #{phys.aerobic_threshold.value} [#{PolarData::PbUserHrAttribute::HrSettingSource.value_to_names_map[phys.aerobic_threshold.setting_source].first.to_s}] (last modified #{pb_sysdatetime_to_string phys.aerobic_threshold.last_modified})\n"
buffer << "Anaerobic threshold : #{phys.anaerobic_threshold.value} [#{PolarData::PbUserHrAttribute::HrSettingSource.value_to_names_map[phys.anaerobic_threshold.setting_source].first.to_s}] (last modified #{pb_sysdatetime_to_string phys.anaerobic_threshold.last_modified})\n"
buffer << "VO2max : #{phys.vo2max.value} [#{PolarData::PbUserVo2Max::Vo2MaxSettingSource.value_to_names_map[phys.vo2max.setting_source].first.to_s}] (last modified #{pb_sysdatetime_to_string phys.vo2max.last_modified})\n"
buffer << "Training background : #{PolarData::PbUserTrainingBackground::TrainingBackground.value_to_names_map[phys.training_background.value].first.to_s} (last modified #{pb_sysdatetime_to_string phys.training_background.last_modified})\n"
buffer << "Typical day : #{PolarData::PbUserTypicalDay::TypicalDay.value_to_names_map[phys.typical_day.value].first.to_s} (last modified #{pb_sysdatetime_to_string phys.typical_day.last_modified})\n"
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"
buffer << "Functional threshold power: #{phys.functional_threshold_power.value} [#{PolarData::PbUserFunctionalThresholdPower::FTPSettingSource.value_to_names_map[phys.functional_threshold_power.setting_source].first.to_s}] (last modified #{pb_sysdatetime_to_string phys.functional_threshold_power.last_modified})\n"
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