Skip to content

Reading weight graphs #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions lib/WWW/Fitbit/API.pm
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -400,7 +418,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} ) {
Expand Down Expand Up @@ -457,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;
Expand Down Expand Up @@ -550,6 +569,14 @@ 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}[0]{value}[1]{description};
my $weight = $v[0];
$self->{_logger}->debug("weight = $weight");
push( @entries, $weight );
}
if ( $graph_type eq "steps_historical" ) {

# Sample description: "11,232 steps on Sat, May 1"
Expand Down Expand Up @@ -702,4 +729,3 @@ as Perl itself.

=cut


3 changes: 3 additions & 0 deletions script/test_client.pl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@

my $st = $fb->total_sleep_time("2010-05-01");
print "sleep = hours[$st->{hours_asleep}], wakes[$st->{wakes}]\n";

my @weight = $fb->get_weight_log("2011-01-11");
print "weight = $weight[0]\n";