<commit_before>var exec = require("cordova/exec");

var Health = function () {
  this.name = "health";
};

Health.prototype.isAvailable = function (onSuccess, onError) {
  exec(onSuccess, onError, "health", "isAvailable", []);
};

Health.prototype.disconnect = function (onSuccess, onError) {
  exec(onSuccess, onError, "health", "disconnect", []);
};

Health.prototype.promptInstallFit = function (onSuccess, onError) {
  exec(onSuccess, onError, "health", "promptInstallFit", []);
};

Health.prototype.requestAuthorization = function (datatypes, onSuccess, onError) {
  exec(onSuccess, onError, "health", "requestAuthorization", datatypes);
};

Health.prototype.isAuthorized = function (datatypes, onSuccess, onError) {
  exec(onSuccess, onError, "health", "isAuthorized", datatypes);
};

Health.prototype.query = function (opts, onSuccess, onError) {
  //calories.active is done by asking all calories and subtracting the basal
  if(opts.dataType =='calories.active'){
    //get basal average in the time window between endDate and BASAL_CALORIES_QUERY_PERIOD
    navigator.health.queryAggregated({
      dataType:'calories.basal',
      endDate: opts.endDate,
      startDate: opts.startDate
    }, function(data){
      var basal_ms = data.value / (opts.endDate - opts.startDate);
      //now get the total
      opts.dataType ='calories';
      navigator.health.query(opts, function(data){
        //and subtract the basal
        for(var i=0; i<data.length; i++){
          data[i].value -= basal_ms * (data[i].endDate.getTime() - data[i].startDate.getTime());

          //although it shouldn't happen, after subtracting, sometimes the values are negative,
          //in that case let's return 0 (negative values don't make sense)
          if(data[i].value <0) data[i].value = 0;
        }
        onSuccess(data);
      }, onError);
    }, onError);
  } else {
    //standard case, just use the name as it is
    if(opts.startDate && (typeof opts.startDate == 'object'))<commit_msg>Pass bucket in when querying calories.active<commit_after>var exec = require("cordova/exec");

var Health = function () {
  this.name = "health";
};

Health.prototype.isAvailable = function (onSuccess, onError) {
  exec(onSuccess, onError, "health", "isAvailable", []);
};

Health.prototype.disconnect = function (onSuccess, onError) {
  exec(onSuccess, onError, "health", "disconnect", []);
};

Health.prototype.promptInstallFit = function (onSuccess, onError) {
  exec(onSuccess, onError, "health", "promptInstallFit", []);
};

Health.prototype.requestAuthorization = function (datatypes, onSuccess, onError) {
  exec(onSuccess, onError, "health", "requestAuthorization", datatypes);
};

Health.prototype.isAuthorized = function (datatypes, onSuccess, onError) {
  exec(onSuccess, onError, "health", "isAuthorized", datatypes);
};

Health.prototype.query = function (opts, onSuccess, onError) {
  //calories.active is done by asking all calories and subtracting the basal
  if(opts.dataType =='calories.active'){
    //get basal average in the time window between endDate and BASAL_CALORIES_QUERY_PERIOD
    navigator.health.queryAggregated({
      dataType:'calories.basal',
      endDate: opts.endDate,
      startDate: opts.startDate,
      bucket: opts.bucket
    }, function(data){
      var basal_ms = data.value / (opts.endDate - opts.startDate);
      //now get the total
      opts.dataType ='calories';
      navigator.health.query(opts, function(data){
        //and subtract the basal
        for(var i=0; i<data.length; i++){
          data[i].value -= basal_ms * (data[i].endDate.getTime() - data[i].startDate.getTime());

          //although it shouldn't happen, after subtracting, sometimes the values are negative,
          //in that case let's return 0 (negative values don't make sense)
          if(data[i].value <0) data[i].value = 0;
        }
        onSuccess(data);
      }, onError);
    }, onError);
  } else {
    //standard case, just use the name as it is
    if(opts.startDate && (typeof opts.startDate == 'object'))
{'fraction_non_alphanumeric': 0.13897131552917902, 'fraction_numerical': 0.0019782393669634025, 'mean_word_length': 3.703488372093023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6399613', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1236, 'n_words': 318}