Permalink
Browse files

Merge pull request #3 from MoriTanosuke/master

Use "foodsLocale" for units.
  • Loading branch information...
2 parents 705a434 + 9dbc8bc commit 346f1aafdb0701a72949ecfee68415541b5fac77 @loghound committed Jan 10, 2013
Showing with 27 additions and 11 deletions.
  1. +25 −8 fitbit.js
  2. +2 −3 readme.md
View
@@ -42,29 +42,35 @@ function refreshTimeSeries() {
return;
}
+ Logger.log('Refreshing timeseries data...');
var user = authorize();
var doc = SpreadsheetApp.getActiveSpreadsheet();
doc.setFrozenRows(2);
// header rows
- doc.getRange("a1").setValue(user.fullName);
+ doc.getRange("a1").setValue(user.displayName);
doc.getRange("a1").setComment("DOB:" + user.dateOfBirth);
doc.getRange("b1").setValue(
- user.country + "/" + user.state + "/" + user.city);
+ user.country);
// add the loggables for the last update
doc.getRange("c1").setValue("Loggables:");
doc.getRange("c1").setComment(getLoggables());
// period for the last update
doc.getRange("d1").setValue("Period: " + getPeriod());
+ doc.getRange("e1").setValue(user.avatar);
var options = {
"oAuthServiceName" : "fitbit",
"oAuthUseToken" : "always",
- "method" : "GET"
+ "method" : "GET",
+ "headers": {
+ "Accept-Language": user.foodsLocale
+ }
};
// get inspired here http://wiki.fitbit.com/display/API/API-Get-Time-Series
var activities = getLoggables();
for ( var activity in activities) {
+ Logger.log('Refreshing ' + activity)
var dateString = "today";
var currentActivity = activities[activity];
try {
@@ -93,7 +99,7 @@ function refreshTimeSeries() {
var val = row[j];
cell.offset(index, 0).setValue(val["dateTime"]);
// set the date index
- cell.offset(index, 1 + activity * 1.0).setValue(val["value"]);
+ cell.offset(index, 1 + activity * 1.0).setValue(Number(val["value"]));
// set the value index index
index++;
}
@@ -195,6 +201,7 @@ function renderFitbitConfigurationDialog() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle("Configure Fitbit");
app.setStyleAttribute("padding", "10px");
+ app.setHeight('0.9');
var helpLabel = app
.createLabel("From here you will configure access to fitbit -- Just supply your own"
@@ -224,17 +231,27 @@ function renderFitbitConfigurationDialog() {
listPanel.setWidget(2, 1, consumerSecret);
// add checkboxes to select loggables
- var loggables = app.createListBox(true).setId("loggables").setName(
- "loggables");
+ var loggables = app.createListBox(true).setId("loggables").setName("loggables");
loggables.setVisibleItemCount(3);
for ( var resource in LOGGABLES) {
loggables.addItem(LOGGABLES[resource]);
}
listPanel.setWidget(3, 0, app.createLabel("Resources:"));
listPanel.setWidget(3, 1, loggables);
- var period = app.createTextBox().setId("period").setName("period");
- listPanel.setWidget(4, 0, app.createLabel("Period: (7d, 2w, 6m, 1y, max, ...)"));
+ var period = app.createListBox(false).setId("period").setName("period");
+ period.setVisibleItemCount(1);
+ // add valid timeperiods
+ period.addItem('1d');
+ period.addItem('7d');
+ period.addItem('30d');
+ period.addItem('1w');
+ period.addItem('1m');
+ period.addItem('3m');
+ period.addItem('6m');
+ period.addItem('1y');
+ period.addItem('max');
+ listPanel.setWidget(4, 0, app.createLabel("Period:"));
listPanel.setWidget(4, 1, period);
// Ensure that all form fields get sent along to the handler
View
@@ -15,9 +15,8 @@ Sadly to get started is a bit of a pain.
Want to help? here are some ideas to enhance this
-1. Add the ability to select which 'columns' you want to see
-2. Get smarter about how long a time series to pull down -- only pull down newer data
-3. Make a template with interesting data or graphs and share it.
+1. Get smarter about how long a time series to pull down -- only pull down newer data
+2. Make a template with interesting data or graphs and share it.
I've submitted this to google to include int he script gallery so it might get easier eventually.

0 comments on commit 346f1aa

Please sign in to comment.