<commit_before>class ProcessAudits
  def self.execute(active_start, active_end, term_start, term_end, other_params, out_directory)
    active_audits = Policy.find_active_and_unterminated_in_range(active_start, active_end, other_params).no_timeout
    term_audits = Policy.find_terminated_in_range(term_start, term_end, other_params).no_timeout
    active_audits.each do |term|
      # TODO: Make the list of included ids match non-cancelled,
      # non-termed as of X date members
      enrollee_list = term.enrollees.reject { |en| en.canceled? }
      enrollee_list = enrollee_list.select do |en|
        en.coverage_end.nil? || (en.coverage_end > active_end)
      end
      out_f = File.open(File.join(out_directory, "#{term._id}_active.xml"), 'w')
      ser = CanonicalVocabulary::MaintenanceSerializer.new(
        term,
        "audit",
        "notification_only",
        enrollee_list.map(&:m_id),
        enrollee_list.map(&:m_id),
        { :term_boundry => active_end }
      )
      out_f.write(ser.serialize)
      out_f.close
    end
    term_audits.each do |term|
      # TODO: Make the list of included ids match non-cancelled,
      # termed as of X date members
      enrollee_list = term.enrollees.reject { |en| en.canceled? }
      enrollee_list = enrollee_list.select do |en|
        !en.coverage_end.nil? && (en.coverage_end <= active_end)
      end
      out_f = File.open(File.join(out_directory, "#{term._id}_term.xml"), 'w')
      ser = CanonicalVocabulary::MaintenanceSerializer.new(
        term,
        "audit",
        "notification_only",
        enrollee_list.map(&:m_id),
        enrollee_list.map(&:m_id),
        { :term_boundry => term_end }
      )
      out_f.write(ser.serialize)
      out_f.close
    end
  end
end<commit_msg>Still fixing audits.<commit_after>class ProcessAudits
  def self.execute(active_start, active_end, term_start, term_end, other_params, out_directory)
    active_audits = Policy.find_active_and_unterminated_in_range(active_start, active_end, other_params).no_timeout
    term_audits = Policy.find_terminated_in_range(term_start, term_end, other_params).no_timeout

    audit_ids = active_audits.map(&:id) | term_audits.map(&:id)

    audits = Policy.where("id" => {"$in" => audit_ids})
    audits.each do |term|
      # TODO: Make the list of included ids match non-cancelled,
      # non-termed as of X date members
      enrollee_list = term.enrollees.reject { |en| en.canceled? }
      subscriber = term.subscriber.m_id
      enrollee_list = enrollee_list.reject do |en|
        !en.coverage_end.blank? && (en.coverage_end < term_start) 
      end
      all_ids = enrollee_list.map(&:m_id) | [subscriber]
      out_f = File.open(File.join(out_directory, "#{term._id}_audit.xml"), 'w')
      ser = CanonicalVocabulary::MaintenanceSerializer.new(
        term,
        "audit",
        "notification_only",
        all_ids,
        all_ids,
        { :term_boundry => active_end }
      )
      out_f.write(ser.serialize)
      out_f.close
    end
  end
end
{'fraction_non_alphanumeric': 0.11037673496364839, 'fraction_numerical': 0.0, 'mean_word_length': 3.1127717391304346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '1337918', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1044, 'n_words': 189}