<commit_before>class Measure < MongoBase

  # Finds all measures by category
  # @return Array - This returns an Array of Hashes. Each Hash will have a category property for
  #         the name of the category. It will also have a measures property which will be
  #         another Array of Hashes. The sub hashes will have the name and id of each measure.
  def self.all_by_category
    mongo['measures'].group(:key => :category,
                            :initial => {:measures => []},
                            :reduce =>
                            'function(obj,prev) { 
                                  if (contains(prev.measures, obj.id) == false) {
                                    prev.measures.push({"id": obj.id, "name": obj.name});
                                  }
                             };')
  end
  
  # Finds all measures by category, except for core and core alternate measures
  # @return Array - This returns an Array of Hashes. Each Hash will have a category property for
  #         the name of the category. It will also have a measures property which will be
  #         another Array of Hashes. The sub hashes will have the name and id of each measure.
  def self.non_core_measures
    mongo['measures'].group(:key => :category, 
                            :cond => {:category => {"$nin" => ['Core', 'Core Alternate']}},
                            :initial => {:measures => []},
                            :reduce =>
                            'function(obj,prev) {
                                  var measureIds = [];
                                  for (var i = 0; i < prev.measures.length; i++) {
                                    measureIds.push(prev.measures[i].id)
                                  }<commit_msg>Fixing bug where contains was expecting an array of ids, but was getting an array of measure objects<commit_after>class Measure < MongoBase

  # Finds all measures by category
  # @return Array - This returns an Array of Hashes. Each Hash will have a category property for
  #         the name of the category. It will also have a measures property which will be
  #         another Array of Hashes. The sub hashes will have the name and id of each measure.
  def self.all_by_category
    mongo['measures'].group(:key => :category,
                            :initial => {:measures => []},
                            :reduce =>
                            'function(obj,prev) {
                                  var measureIds = [];
                                  for (var i = 0; i < prev.measures.length; i++) {
                                    measureIds.push(prev.measures[i].id)
                                  }
                                  if (contains(measureIds, obj.id) == false) {
                                    prev.measures.push({"id": obj.id, "name": obj.name});
                                  }
                             };')
  end
  
  # Finds all measures by category, except for core and core alternate measures
  # @return Array - This returns an Array of Hashes. Each Hash will have a category property for
  #         the name of the category. It will also have a measures property which will be
  #         another Array of Hashes. The sub hashes will have the name and id of each measure.
  def self.non_core_measures
    mongo['measures'].group(:key => :category, 
                            :cond => {:category => {"$nin" => ['Core', 'Core Alternate']}},
                            :initial => {:measures => []},
                            :reduce =>
                            'function(obj,prev) {
                                  var measureIds = [];
                                  for (var i = 0; i < prev.measures.length; i++) {
                                    measureIds.push(prev.measures[i].id)
                                  }
{'fraction_non_alphanumeric': 0.09069767441860466, 'fraction_numerical': 0.0007751937984496124, 'mean_word_length': 1.311044776119403, 'pattern_counts': {'":': 4, '<': 8, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '619615', 'n_tokens_mistral': 935, 'n_tokens_neox': 878, 'n_words': 337}