<commit_before><commit_msg>Add some basic reporting on the state of the alpha taxonomy import<commit_after>module AlphaTaxonomy
  class BulkImportReport
    include AlphaTaxonomy::Helpers::ImportFileHelper

    def initialize(logger: Logger.new(STDOUT))
      @log = logger
    end

    def view
      check_import_file_is_present
      @no_alpha_taxon = []
      @no_content_item = []
      @updated = []

      grouped_mappings.each do |path, _taxon_titles|
        determine_update_state_of(path)
      end

      log_summary
    end

  private

    def grouped_mappings
      @grouped_mappings ||= ImportFile.new.grouped_mappings
    end

    def determine_update_state_of(path)
      content_item = Services.content_store.content_item(path)

      if content_item.blank?
        @no_content_item << { path: path }
        return
      end

      if content_item.links["alpha_taxons"].blank?
        @no_alpha_taxon << { path: path, cid: content_item.content_id }
      else
        @updated << { path: path, cid: content_item.content_id }
      end
    end

    def log_summary
      @log.info "BULK IMPORT SUMMARY"
      log_no_alpha_taxons
      log_no_content_items
      log_updated
      log_numbers
    end

    def log_numbers
      @log.info "Total #{@grouped_mappings.count}"
      @log.info "No alpha taxon:  #{@no_alpha_taxon.count}"
      @log.info "No content item found: #{@no_content_item.count}"
      @log.info "Updated: #{@updated.count}"
      @log.info "#{@no_alpha_taxon.count + @no_content_item.count + @updated.count} of #{@grouped_mappings.count} accounted for"
    end

    def log_no_alpha_taxons
      @log.info "************** No alpha taxon **************"
      @no_alpha_taxon.each do |bad_update|
        @log.info "#{bad_update[:cid]} - #{bad_update[:path]}"
      end
      @log.info ""
    end

    def log_no_content_items
      @log.info "************** No content item **************"
      @no_content_item.each do |bad_update|
        @log.info "#{bad_update[:path]}"
      end
      @log.info ""
    end

    def log_updated
      @log.info "************** Updated **************"
      @updated.each do |good_update|
        @log.info "#{good_update[:cid]} - #{good_update[:path]}"
      end
      @log.info ""
    end
  end
end
{'fraction_non_alphanumeric': 0.13582417582417583, 'fraction_numerical': 0.0, 'mean_word_length': 2.7619834710743802, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2480075', 'n_tokens_mistral': 750, 'n_tokens_neox': 738, 'n_words': 152}