ruby-fitbit 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +19 -2
- data/VERSION +1 -1
- data/bin/ruby-fitbit +26 -7
- data/lib/ruby-fitbit.rb +52 -0
- data/ruby-fitbit.gemspec +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This is a Ruby API for the fitbit and the data at fitbit.com
|
4
4
|
|
5
|
-
Currently the gem uses screen scraping to get the data, but it will switch over to use the official API once available. The current set of data it retrieves is pretty limited, but it should grow over time. Originally built just to display a dashboard of my current fitbit stats on my blog. I started adding additonal data scrapped from the graphs. Which allows me to export the data or do my own charting.
|
5
|
+
Currently the gem uses screen scraping to get the data, but it will switch over to use the official API once available. The current set of data it retrieves is pretty limited, but it should grow over time. Originally built just to display a dashboard of my current fitbit stats on my blog. I started adding additonal data scrapped from the graphs. Which allows me to export the data or do my own charting. This is heavily influenced by the Python fitbit API from @wadey (http://github.com/wadey/python-fitbit), and also has a bit of inspiration from the perl API (http://eric-blue.com/projects/fitbit/). Thanks for their code to help me work out the API.
|
6
6
|
|
7
7
|
== Usage
|
8
8
|
|
@@ -55,13 +55,30 @@ Currently the gem uses screen scraping to get the data, but it will switch over
|
|
55
55
|
|
56
56
|
done
|
57
57
|
|
58
|
+
Aggregated Data
|
59
|
+
ruby bin/ruby-fitbit dan@email.com pass summary 07/07/2010 07/04/2010
|
60
|
+
|
61
|
+
getting aggregated data
|
62
|
+
| 2010-07-04 | {"miles_walked"=>"2.97", "steps"=>"6976", "lightly_active"=>"3hrs 3min", "sedentary_active"=>"18hrs ... |
|
63
|
+
| 2010-07-05 | {"miles_walked"=>"4.98", "steps"=>"11711", "lightly_active"=>"2hrs 21min", "sedentary_active"=>"2hrs... |
|
64
|
+
| 2010-07-06 | {"miles_walked"=>"4.68", "steps"=>"10014", "lightly_active"=>"1hr 17min", "sedentary_active"=>"20hrs... |
|
65
|
+
...
|
66
|
+
Average Data over that time
|
67
|
+
+--------------+------------------+
|
68
|
+
| miles_walked | 4.03857142857143 |
|
69
|
+
| steps | 8953.85714285714 |
|
70
|
+
| calories | 2247.71428571429 |
|
71
|
+
+--------------+------------------+
|
58
72
|
|
59
73
|
|
60
74
|
== TODOs
|
61
75
|
|
62
76
|
* get food intake tracked etc
|
63
77
|
* add ability for gem to write data to fitbit, such as log and food entries
|
64
|
-
* build everything needed for a nice fitbit
|
78
|
+
* build everything needed for a nice fitbit mobile app to use this API.
|
79
|
+
* better cmd line output
|
80
|
+
* add data caching, currently it refetches every time. especially dumb when it does it twice for aggragate and avg data
|
81
|
+
* Support Avgs over all data_point
|
65
82
|
|
66
83
|
== Note on Patches/Pull Requests
|
67
84
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/ruby-fitbit
CHANGED
@@ -4,25 +4,33 @@ require 'hirb'
|
|
4
4
|
|
5
5
|
if(ARGV[0]!=nil && ARGV[1]!=nil)
|
6
6
|
fitbit = RubyFitbit.new(ARGV[0],ARGV[1])
|
7
|
+
|
8
|
+
begin
|
9
|
+
date = Time.parse(ARGV[3])
|
10
|
+
rescue
|
11
|
+
date = Time.now
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
end_date = Time.parse(ARGV[4])
|
16
|
+
rescue
|
17
|
+
end_date = Time.now
|
18
|
+
end
|
7
19
|
|
20
|
+
fitbit.get_data(date)
|
21
|
+
puts "Fitbit Data for #{date}"
|
8
22
|
puts "Calories Burned #{fitbit.calories}"
|
9
23
|
puts "Steps Taken #{fitbit.steps}"
|
10
24
|
puts "Milkes Walked #{fitbit.miles_walked}"
|
11
25
|
puts "Activity Levels Durations:"
|
12
26
|
puts "Sedentary #{fitbit.sedentary_active}"
|
13
27
|
puts "Lightly #{fitbit.lightly_active}"
|
14
|
-
puts "Fairly # => {fitbit.fairly_active}"
|
28
|
+
puts "Fairly # => #{fitbit.fairly_active}"
|
15
29
|
puts "Very #{fitbit.very_active}"
|
16
30
|
end
|
17
31
|
|
18
32
|
if ARGV[2]!=nil
|
19
33
|
|
20
|
-
begin
|
21
|
-
date = Time.parse(ARGV[3])
|
22
|
-
rescue
|
23
|
-
date = Time.now
|
24
|
-
end
|
25
|
-
|
26
34
|
case ARGV[2]
|
27
35
|
when 'calorie'
|
28
36
|
puts "calorie data for data #{date}"
|
@@ -30,6 +38,8 @@ if ARGV[2]!=nil
|
|
30
38
|
when 'activity'
|
31
39
|
puts "calorie data for data #{date}"
|
32
40
|
data = fitbit.get_activity_score_data(date)
|
41
|
+
when 'summary'
|
42
|
+
#do nothing just print the summary above
|
33
43
|
else
|
34
44
|
puts "steps data for data #{date}"
|
35
45
|
data = fitbit.get_steps_data(date)
|
@@ -37,4 +47,13 @@ if ARGV[2]!=nil
|
|
37
47
|
puts Hirb::Helpers::AutoTable.render(data)
|
38
48
|
end
|
39
49
|
|
50
|
+
if ARGV[4]!=nil
|
51
|
+
puts "getting aggregated data"
|
52
|
+
data = fitbit.get_aggregated_data(date, end_date)
|
53
|
+
puts Hirb::Helpers::AutoTable.render(data)
|
54
|
+
puts "Average Data over that time"
|
55
|
+
data = fitbit.get_avg_data(date, end_date)
|
56
|
+
puts Hirb::Helpers::AutoTable.render(data)
|
57
|
+
end
|
58
|
+
|
40
59
|
puts "done"
|
data/lib/ruby-fitbit.rb
CHANGED
@@ -46,6 +46,58 @@ class RubyFitbit
|
|
46
46
|
@lightly_active = page.search("//div[@class='lightly caption']/div[@class='number']").text.strip
|
47
47
|
@fairly_active = page.search("//div[@class='caption fairly']/div[@class='number']").text.strip
|
48
48
|
@very_active = page.search("//div[@class='caption very']/div[@class='number']").text.strip
|
49
|
+
data = {}
|
50
|
+
data['calories'] = @calories
|
51
|
+
data['steps'] = @steps
|
52
|
+
data['miles_walked'] = @miles_walked
|
53
|
+
data['sedentary_active'] = @sedentary_active
|
54
|
+
data['lightly_active'] = @lightly_active
|
55
|
+
data['fairly_active'] = @fairly_active
|
56
|
+
data['very_active'] = @very_active
|
57
|
+
data
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_aggregated_data(start_date = Time.now, end_date = Time.now)
|
61
|
+
data = {}
|
62
|
+
formatted_date = get_fitbit_date_format(end_date)
|
63
|
+
data[formatted_date] = get_data(end_date)
|
64
|
+
|
65
|
+
date = end_date + (24 * 60 * 60)
|
66
|
+
while date < start_date
|
67
|
+
formatted_date = get_fitbit_date_format(date)
|
68
|
+
data[formatted_date] = get_data(date)
|
69
|
+
date = date + (24 * 60 * 60)
|
70
|
+
end
|
71
|
+
|
72
|
+
data
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_avg_data(start_date = Time.now, end_date = Time.now)
|
76
|
+
data = {}
|
77
|
+
data['calories'] = 0
|
78
|
+
data['steps'] = 0
|
79
|
+
data['miles_walked'] = 0
|
80
|
+
# TODO these aren't numbers but times need to convert all to minutes and then back
|
81
|
+
#data['sedentary_active'] = 0
|
82
|
+
#data['lightly_active'] = 0
|
83
|
+
#data['fairly_active'] = 0
|
84
|
+
#data['very_active'] = 0
|
85
|
+
days = 0
|
86
|
+
|
87
|
+
days_data = get_aggregated_data(start_date, end_date)
|
88
|
+
days_data.keys.each do |key|
|
89
|
+
days += 1
|
90
|
+
current_data = days_data[key]
|
91
|
+
data.keys.each do |stat|
|
92
|
+
data[stat] += current_data[stat].to_f
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
data.keys.each do |key|
|
97
|
+
data[key] = (data[key]/days)
|
98
|
+
end
|
99
|
+
|
100
|
+
data
|
49
101
|
end
|
50
102
|
|
51
103
|
def get_steps_data(date = Time.now)
|
data/ruby-fitbit.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby-fitbit}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Mayer"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-10}
|
13
13
|
s.default_executable = %q{ruby-fitbit}
|
14
14
|
s.description = %q{This is a Ruby API for Fitbit.com, currently scraping, but soon will use the officail API (when released)}
|
15
15
|
s.email = %q{Danmayer@gmail.com}
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dan Mayer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-10 00:00:00 -04:00
|
18
18
|
default_executable: ruby-fitbit
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|