basis-band 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -4,28 +4,38 @@ This is extremely alpha quality, based on the existing PHP example at
4
4
  [https://github.com/btroia/basis-data-export](https://github.com/btroia/basis-data-export).
5
5
  That example includes instructions for finding your userid.
6
6
 
7
- The command line tool here does just a one-day dump of the JSON data raw. Pass
8
- it your userid and a date, and it'll spit back the raw data on stdout. For
9
- instance to dump my data for Oct 14th, 2013 (of course, xxxxx represents my
10
- userid, but I'm not posting that):
7
+ Includes a command line tool that can be used to either capture the raw JSON
8
+ responses from app.mybasis.com, or to convert the metrics from the API
9
+ responses into CSV. Assuming your userid is represented by xxxxx, here are
10
+ some simple examples.
11
+
12
+ If you pass -u and -d options the raw text will be fetched from the API and
13
+ output on standard output:
11
14
 
12
15
  ```
13
- > miker $ basis-band xxxxxxxxxxxxxxxxxxxxxxxx 2013-10-14
16
+ > miker $ basis-band -c xxxxx -d 2013-10-14
17
+ {"metrics":{"skin_temp":{"min":77.0,"max":95.0,"sum":113642.0,"summary":{"max_skin_temp_per_minute":null...
14
18
  ```
15
19
 
16
- Or if you want to pretty print and paginate:
20
+ If you want the metric data as CSV instead of raw JSON:
17
21
 
18
22
  ```
19
- > miker $ basis-band xxxxxxxxxxxxxxxxxxxxxxxx 2013-10-14 | python -mjson.tool | more
20
- {
21
- "bodystates": [
22
- [
23
- 1381816740,
24
- 1381842000,
25
- "sleep"
26
- ...
23
+ > miker $ basis-band -c xxxxx -d 2013-10-14 -c
24
+ t,skin_temp,heartrate,air_temp,calories,gsr,steps
25
+ 2013/10/14 00:00:00,93.2,69,92.3,1.3,0.00128,0
26
+ 2013/10/14 00:01:00,93.3,68,92.3,1.3,0.00136,0
27
+ 2013/10/14 00:02:00,94.3,68,92.3,1.3,0.00156,0
27
28
  ...
28
29
  ```
29
30
 
30
- Just pushing up what I have so far, this is really meant to be a way to export to
31
- CSV eventually so I can use this data in spreadsheets. To be done.
31
+ If you already have the JSON in a local file, you can pass it in on standard
32
+ input and transform it to CSV:
33
+
34
+ ```
35
+ > miker $ basis-band -c < cache/2013-10-14.json
36
+ t,skin_temp,heartrate,air_temp,calories,gsr,steps
37
+ 2013/10/14 00:00:00,93.2,69,92.3,1.3,0.00128,0
38
+ 2013/10/14 00:01:00,93.3,68,92.3,1.3,0.00136,0
39
+ 2013/10/14 00:02:00,94.3,68,92.3,1.3,0.00156,0
40
+ ...
41
+ ```
@@ -8,9 +8,20 @@ class ApiResponseModel
8
8
  @starttime = Time.at(@json['starttime'])
9
9
  end
10
10
 
11
+ def state_for_time(t)
12
+ matches = @json["bodystates"].select { |s|
13
+ t >= s[0] && t < s[1]
14
+ }
15
+ if matches.length == 1
16
+ matches[0][2]
17
+ else
18
+ "unknown"
19
+ end
20
+ end
21
+
11
22
  def hash_for_minute(min)
12
23
  t = @starttime + (min * 60)
13
- res = {'t' => t.strftime("%Y/%m/%d %H:%M:%S")}
24
+ res = {'t' => t.strftime("%Y/%m/%d %H:%M:%S"), 'state' => state_for_time(t.to_i)}
14
25
  for m in @json["metrics"].keys
15
26
  res[m] = @json["metrics"][m]["values"][min]
16
27
  end
@@ -1,3 +1,3 @@
1
1
  module BasisBand
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.1'
3
3
  end
@@ -2,16 +2,35 @@ require 'test/unit'
2
2
  require 'basis-band'
3
3
 
4
4
  class ApiResponseModelTest < Test::Unit::TestCase
5
- def test_defaults_url
5
+ def setup
6
6
  test_fn = File.expand_path('../2013-10-01.json', __FILE__)
7
7
  raw = File.read(test_fn)
8
- m = ApiResponseModel.new(raw)
9
- minutes = m.samples_by_minute
8
+ @m = ApiResponseModel.new(raw)
9
+ end
10
+
11
+ def test_parse_samples
12
+ minutes = @m.samples_by_minute
10
13
  assert minutes.length == 1440
11
14
  min_first = minutes.first
12
15
  assert min_first["air_temp"] == 80.6
13
16
  min_last = minutes.last
14
17
  assert min_last["air_temp"] == 81.5
15
18
  end
19
+
20
+ def test_state_for_time_begin
21
+ assert @m.state_for_time(1380607140) == "inactive"
22
+ end
23
+
24
+ def test_state_for_time_end_overlap
25
+ assert @m.state_for_time(1380648120) == "light_activity"
26
+ end
27
+
28
+ def test_state_for_time_middle
29
+ assert @m.state_for_time(1380657480) == "moderate_activity"
30
+ end
31
+
32
+ def test_state_for_time_unknown
33
+ assert @m.state_for_time(1390697860) == "unknown"
34
+ end
16
35
  end
17
36
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basis-band
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- description: A library and collection for tools for exporting monitoring data from
30
+ description: A library and collection of tools for exporting monitoring data from
31
31
  the website for the Basis B1 Band device. See http://mybasis.com
32
32
  email: mikerowehl@gmail.com
33
33
  executables: