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

Fix #1000 - Update record when a user leaves the study #1001

Merged
merged 2 commits into from
Jul 15, 2019

Conversation

cagryInside
Copy link
Contributor

@cagryInside cagryInside commented Jul 14, 2019

This is a WIP PR, please do not merge.

This PR updates the spreadsheet when a travel-behavior study participant opt-outs from the study.

@barbeau Before merging this PR, could you please create a new Google script app and deploy the following code as a web application? The permissions should be the same as the one for registration app. Also, could you please update the GOOGLE_DOC_ID with the OneBusAway Travel Behavior Data - Email mapping file's id; I just didn't put it here because of the privacy concerns. Once you deploy the app, please let me know with the URL; like that I can update the PR.

Thanks a lot.

function doGet(e) {
  var GOOGLE_DOC_ID = "";

  var ss = SpreadsheetApp.openById(GOOGLE_DOC_ID);
  var sheet = ss.getSheets()[0];
  var d = new Date();
  var date = Utilities.formatDate(d, "GMT", "MM/dd/yyyy hh:mm:ss a");
  var dateIso = Utilities.formatDate(d, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
  
  var id = e.parameter.id;

  var row = findRowById(sheet, id);
  
  // Couldn't find the id in the spreadsheet
  if (row == -1) {
      return ContentService.createTextOutput("Couldn't find Id").setMimeType(ContentService.MimeType.TEXT);
  }

  sheet.getRange(row,5).setValue(date);
  sheet.getRange(row,6).setValue(dateIso);
  return ContentService.createTextOutput("STATUS OK").setMimeType(ContentService.MimeType.TEXT);
}


function findRowById(sheet, id) {
  var row = 1;
  while (true) {
    var val = sheet.getRange(row, 1).getValue();
    if (val == id) return row;
    if (val == "") return -1;
    row++;
  }
}

@barbeau
Copy link
Member

barbeau commented Jul 15, 2019

@cagryInside I went ahead and updated the PR with the new URL. Thanks!

@barbeau barbeau changed the title WIP -- Fix #1000 - Update record when a user leaves the study WIP - Fix #1000 - Update record when a user leaves the study Jul 15, 2019
@barbeau barbeau changed the title WIP - Fix #1000 - Update record when a user leaves the study Fix #1000 - Update record when a user leaves the study Jul 15, 2019
@barbeau barbeau merged commit 5e73fdd into OneBusAway:master Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants