From faec54fb64a710cbd65ddc39144bff456b47efe3 Mon Sep 17 00:00:00 2001 From: MoriTanosuke Date: Tue, 11 Jan 2011 06:19:25 -0800 Subject: [PATCH 1/6] Added weight chart. (not yet tested, because no perl at hand) --- lib/WWW/Fitbit/API.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) mode change 100755 => 100644 lib/WWW/Fitbit/API.pm diff --git a/lib/WWW/Fitbit/API.pm b/lib/WWW/Fitbit/API.pm old mode 100755 new mode 100644 index ce27a82..d17c701 --- a/lib/WWW/Fitbit/API.pm +++ b/lib/WWW/Fitbit/API.pm @@ -400,7 +400,8 @@ sub _request_graph_xml { 'distance_historical' => 'distanceFromSteps', 'steps_historical' => 'stepsTaken', 'sleep_time_historical' => 'timeAsleep', - 'wakeup_historical' => 'timesWokenUp' + 'wakeup_historical' => 'timesWokenUp', + 'weight_historical' => 'weight' }; if ( !defined $type_map->{$graph_type} ) { @@ -550,6 +551,13 @@ sub _parse_graph_xml { push( @entries, $total_wakes ); } + if ( $graph_type eq "weight_historical" ) { + # Sample description: "80.5 kg on Mon, Jan 1" + my @v = split / /, + $graph_data->{data}{chart}{graphs}{graph}{value}{description}; + my $weight = $v[0]; + push( @entries, $weight ); + } if ( $graph_type eq "steps_historical" ) { # Sample description: "11,232 steps on Sat, May 1" From b1e8061e3bd4919ece831fbab44eb7a0a58ff526 Mon Sep 17 00:00:00 2001 From: MoriTanosuke Date: Tue, 11 Jan 2011 07:30:08 -0800 Subject: [PATCH 2/6] Added get_weight_log() to get weights for each day. --- lib/WWW/Fitbit/API.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/WWW/Fitbit/API.pm b/lib/WWW/Fitbit/API.pm index d17c701..d284362 100644 --- a/lib/WWW/Fitbit/API.pm +++ b/lib/WWW/Fitbit/API.pm @@ -203,6 +203,24 @@ sub get_step_log { } +################################################################# +# Title : get_weight_log (public) +# Usage : $self->get_weight_log($date) +# Purpose : Displays weight in 1d intervals +# Parameters : date = YYYY-MM-DD (optional; default = today) +# Returns : Hash ref; keys = time, value +# values = YYYY-MM-DD HH:MM[A|P]M, decimal + +sub get_weight_log { + + my $self = shift; + + my ($date) = @_; + + return $self->_parse_graph_xml( "weight_historical", $date ); + +} + ################################################################# # Title : get_sleep_log (public) # Usage : $self->get_sleep_log($date) From b3335b4797ee9ab141da7ad8067884108df3e2bb Mon Sep 17 00:00:00 2001 From: MoriTanosuke Date: Tue, 11 Jan 2011 12:34:38 -0800 Subject: [PATCH 3/6] Fixed some issues with weight graph. It is now loading AND logged, but not working when I add a similar line for weight in script/test_client.pl... --- lib/WWW/Fitbit/API.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/WWW/Fitbit/API.pm b/lib/WWW/Fitbit/API.pm index d284362..05b079b 100644 --- a/lib/WWW/Fitbit/API.pm +++ b/lib/WWW/Fitbit/API.pm @@ -476,7 +476,7 @@ sub _parse_graph_xml { defined $date ? $self->_check_date_format($date) : $date = $self->_get_date(); - $self->{_logger}->info("Getting calories burned for date $date"); + $self->{_logger}->info("Getting $graph_type for date $date"); my $xml = $self->_request_graph_xml( $graph_type, $date ); my $graph_data; @@ -572,8 +572,9 @@ sub _parse_graph_xml { if ( $graph_type eq "weight_historical" ) { # Sample description: "80.5 kg on Mon, Jan 1" my @v = split / /, - $graph_data->{data}{chart}{graphs}{graph}{value}{description}; + $graph_data->{data}{chart}{graphs}{graph}[0]{value}[1]{description}; my $weight = $v[0]; + $self->{_logger}->debug("weight = $weight"); push( @entries, $weight ); } if ( $graph_type eq "steps_historical" ) { @@ -728,4 +729,3 @@ as Perl itself. =cut - From fae6bc814ff7a694e3806376ce2bd8a633c5e74d Mon Sep 17 00:00:00 2001 From: MoriTanosuke Date: Tue, 11 Jan 2011 12:35:57 -0800 Subject: [PATCH 4/6] Added an example call to get_weight_log, but this unexpectedly returning "1" and not the weight. --- script/test_client.pl | 2 ++ 1 file changed, 2 insertions(+) mode change 100755 => 100644 script/test_client.pl diff --git a/script/test_client.pl b/script/test_client.pl old mode 100755 new mode 100644 index 23c9b18..50c858f --- a/script/test_client.pl +++ b/script/test_client.pl @@ -31,3 +31,5 @@ my $st = $fb->total_sleep_time("2010-05-01"); print "sleep = hours[$st->{hours_asleep}], wakes[$st->{wakes}]\n"; + +print "weight = " . $fb->get_weight_log("2011-01-11") . "\n"; From 784a6935c6c8d7afbe55a790e436ec9f217ab938 Mon Sep 17 00:00:00 2001 From: MoriTanosuke Date: Tue, 11 Jan 2011 22:29:26 -0800 Subject: [PATCH 5/6] Added Data::Dumper for output --- script/test_client.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/test_client.pl b/script/test_client.pl index 50c858f..3192241 100644 --- a/script/test_client.pl +++ b/script/test_client.pl @@ -10,6 +10,7 @@ # use WWW::Fitbit::API; +use Data::Dumper; my $fb = WWW::Fitbit::API->new( config => 'conf/fitbit.conf' ); @@ -32,4 +33,4 @@ my $st = $fb->total_sleep_time("2010-05-01"); print "sleep = hours[$st->{hours_asleep}], wakes[$st->{wakes}]\n"; -print "weight = " . $fb->get_weight_log("2011-01-11") . "\n"; +print "weight = " . Data::Dumper($fb->get_weight_log("2011-01-11")) . "\n"; From 19cc0e5f00415b1ee29ae851a7a4e9eeceeab995 Mon Sep 17 00:00:00 2001 From: MoriTanosuke Date: Wed, 12 Jan 2011 08:24:32 -0800 Subject: [PATCH 6/6] Fixed the output of weight value. Still, it is not good and should be converted from array to scalar in API.pm, line 574+. --- script/test_client.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/test_client.pl b/script/test_client.pl index 3192241..fb63dd5 100644 --- a/script/test_client.pl +++ b/script/test_client.pl @@ -10,7 +10,6 @@ # use WWW::Fitbit::API; -use Data::Dumper; my $fb = WWW::Fitbit::API->new( config => 'conf/fitbit.conf' ); @@ -33,4 +32,5 @@ my $st = $fb->total_sleep_time("2010-05-01"); print "sleep = hours[$st->{hours_asleep}], wakes[$st->{wakes}]\n"; -print "weight = " . Data::Dumper($fb->get_weight_log("2011-01-11")) . "\n"; +my @weight = $fb->get_weight_log("2011-01-11"); +print "weight = $weight[0]\n";