<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.requestAuthorization = function (datatypes, onSuccess, onError) {
  exec(onSuccess, onError, "health", "requestAuthorization", datatypes);
};

Health.prototype.query = function (opts, onSuccess, onError) {
  if(opts.startDate)
  opts.startDate = opts.startDate.getTime();
  if(opts.endDate)
  opts.endDate = opts.endDate.getTime();
  exec(function(data){
    for(var i=0; i<data.length; i++){
      data[i].startDate = new Date(data[i].startDate);
      data[i].endDate = new Date(data[i].endDate);
    }
    onSuccess(data);
  }, onError, "health", "query", [opts]);
};

Health.prototype.queryAggregated = function (opts, onSuccess, onError) {
  if(opts.startDate)
    opts.startDate = opts.startDate.getTime();
  if(opts.endDate)
    opts.endDate = opts.endDate.getTime();
  exec(function(data){
    for(var i=0; i<data.length; i++){
      data[i].startDate = new Date(data[i].startDate);
      data[i].endDate = new Date(data[i].endDate);
    }
    onSuccess(data);
  }, onError, "health", "queryAggregated", [opts]);
};

Health.prototype.store = function (data, onSuccess, onError) {
  if(data.startDate)
  data.startDate = data.startDate.getTime();
  if(data.endDate)
  data.endDate = data.endDate.getTime();
  if(data.dataType =='activity'){
    data.value = navigator.health.toFitActivity(data.value);
  }
  exec(onSuccess, onError, "health", "store", [data]);
};

Health.prototype.toFitActivity = function(act){
  if((act == 'archery') ||
  (act == 'bowling') ||
  (act == 'fishing') ||
  (act == 'functional_strength') ||
  (act == 'hunting') ||
  (act == 'lacrosse') ||
  (act == 'mixed_metabolic_cardio') ||
  (act == 'paddle_sports') ||
  (act == 'play') ||
  (act == 'preparation_and_recovery') ||
  (act == 'snow_sports') ||<commit_msg>fixed a bug in android version<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.requestAuthorization = function (datatypes, onSuccess, onError) {
  exec(onSuccess, onError, "health", "requestAuthorization", datatypes);
};

Health.prototype.query = function (opts, onSuccess, onError) {
  navigator.health.requestAuthorization([opts.dataType], function(){
    if(opts.startDate)
    opts.startDate = opts.startDate.getTime();
    if(opts.endDate)
    opts.endDate = opts.endDate.getTime();
    exec(function(data){
      for(var i=0; i<data.length; i++){
        data[i].startDate = new Date(data[i].startDate);
        data[i].endDate = new Date(data[i].endDate);
      }
      onSuccess(data);
    }, onError, "health", "query", [opts]);
  }, onError);
};

Health.prototype.queryAggregated = function (opts, onSuccess, onError) {
  navigator.health.requestAuthorization([opts.dataType], function(){
    if(opts.startDate)
    opts.startDate = opts.startDate.getTime();
    if(opts.endDate)
    opts.endDate = opts.endDate.getTime();
    exec(function(data){
      for(var i=0; i<data.length; i++){
        data[i].startDate = new Date(data[i].startDate);
        data[i].endDate = new Date(data[i].endDate);
      }
      onSuccess(data);
    }, onError, "health", "queryAggregated", [opts]);
  }, onError);
};

Health.prototype.store = function (data, onSuccess, onError) {
  navigator.health.requestAuthorization([data.dataType], function(){
    if(data.startDate)
    data.startDate = data.startDate.getTime();
    if(data.endDate)
    data.endDate = data.endDate.getTime();
    if(data.dataType =='activity'){
      data.value = navigator.health.toFitActivity(data.value);
    }
    exec(onSuccess, onError, "health", "store", [data]);
  }, onError);
};

Health.prototype.toFitActivity = function(act){
  if((act == 'archery') ||
  (act == 'bowling') ||
  (act == 'fishing') ||
  (act == 'functional_strength') ||
  (act == 'hunting') ||
  (act == 'lacrosse') ||
  (act == 'mixed_metabolic_cardio') ||
  (act == 'paddle_sports') ||
  (act == 'play') ||
  (act == 'preparation_and_recovery') ||
  (act == 'snow_sports') ||
{'fraction_non_alphanumeric': 0.18606803980560055, 'fraction_numerical': 0.0009257116408238834, 'mean_word_length': 4.226118500604595, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6849180', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1497, 'n_words': 262}