Skip to content
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

Use "foodsLocale" for units. #3

Merged
merged 3 commits into from
Jan 10, 2013
Merged
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
33 changes: 25 additions & 8 deletions fitbit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down