<commit_before>angular.module('zentodone').factory('tasks', function ($rootScope, hoodie, $q, Task) {

  var debug = new window.$debug('zentodone:services/task');
  var contexts = {}; // context name -> list of thing id's
  var projects = {};

  hoodie.store.on('change:task', function(name, task) {
    $rootScope.$broadcast('taskChange', {
      type: name,
      task: task
    })
  })

  // update the contexts/projects hash based on the task
  var trackHash = function(hash, type, task) {
    var plural = type + 's'

          if (task[plural]) {
            for (var j = 0; j < task[plural].length; ++j) {
              var name = task[plural][j];
              if (!(name in hash)) {
                hash[name] = []
              }
              hash[name].push(task.id)
            }
          }
  }

  return {
    get: function(id) {
      return $q.when(hoodie.store.find('task', id))
    },
    getAll: function(type) {
      var promise = $q.when(hoodie.store.findAll('task'))
      if (!Task.isType(type)) {
        return promise
      }

      var deferred = $q.defer()
      promise.then(function(tasksData) {
        var tasksDataOfType = []
        for (var i = 0; i < tasksData.length; i++) {
          if (tasksData[i].taskType === type) {
            tasksDataOfType.push(tasksData[i])<commit_msg>add some functions to get count and projects/contexts<commit_after>angular.module('zentodone').factory('tasks', function ($rootScope, hoodie, $q, Task) {

  var debug = new window.$debug('zentodone:services/task');
  var contexts = {}; // context name -> list of thing id's
  var projects = {};

  hoodie.store.on('change:task', function(name, task) {
    $rootScope.$broadcast('taskChange', {
      type: name,
      task: task
    })
  })

  // update the contexts/projects hash based on the task
  var trackHash = function(hash, type, task) {
    var plural = type + 's'

          if (task[plural]) {
            for (var j = 0; j < task[plural].length; ++j) {
              var name = task[plural][j];
              if (!(name in hash)) {
                hash[name] = []
              }
              hash[name].push(task.id)
            }
          }
  }

  /* FIXME: does this pollute some outside namespace, or is this tied
   *        to inbox ? */
  $rootScope.getContextsCount = function(context) {
    if (context) {
      return contexts[context].length;
    } else {
      return Object.keys(contexts).length;
    }
  }
  $rootScope.getProjectsCount = function(project) {
    if (project) {
      return projects[project].length;
    } else {
    return Object.keys(projects).length;
    }
  }
  $rootScope.getContexts = function() {
    return Object.keys(contexts);
  }
  $rootScope.getProjects = function() {
    return Object.keys(projects);
  }

  return {
    get: function(id) {
      return $q.when(hoodie.store.find('task', id))
    },
    getAll: function(type) {
      var promise = $q.when(hoodie.store.findAll('task'))
      if (!Task.isType(type)) {
        return promise
      }

      var deferred = $q.defer()
      promise.then(function(tasksData) {
        var tasksDataOfType = []
        for (var i = 0; i < tasksData.length; i++) {
          if (tasksData[i].taskType === type) {
            tasksDataOfType.push(tasksData[i])
{'fraction_non_alphanumeric': 0.14773073408467866, 'fraction_numerical': 0.0012183978068839476, 'mean_word_length': 2.2227674190382727, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '790197', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1016, 'n_words': 235}