<commit_before># frozen_string_literal: true

class FulcrumController < ApplicationController
  before_action :authenticate_user!
  before_action :publisher_stats

  def dashboard
    redirect_to action: :index, partials: :dashboard
  end

  def exec
    case params[:cmd]
    when 'ingest'
      ExtractIngestJob.perform_later(params[:token], params[:base], params[:source], params[:target])
    when 'reindex_everything'
      ReindexJob.perform_later('everything')
    when 'reindex_monographs'
      ReindexJob.perform_later('monographs')
    when 'reindex_file_sets'
      ReindexJob.perform_later('file_sets')
    end
    redirect_to action: :index, partials: :dashboard
  end

  def index # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
    @partials = params[:partials]
    @individuals = []
    @institutions = []
    @publishers_stats = { presses: [], timestampe: Time.now.utc.to_s }
    if ['dashboard', 'products', 'components', 'individuals', 'institutions', 'publishers', 'users', 'tokens', 'logs', 'grants', 'monographs', 'assets', 'pages', 'reports', 'customize', 'settings', 'help', 'csv', 'jobs'].include? @partials
      if /dashboard/.match?(@partials)
        @individuals = Individual.where("identifier like ? or name like ?", "%#{params['individual_filter']}%", "%#{params['individual_filter']}%").map { |individual| ["#{individual.identifier} (#{individual.name})", individual.id] }
        @institutions = Institution.where("identifier like ? or name like ?", "%#{params['institution_filter']}%", "%#{params['institution_filter']}%").map { |institution| ["#{institution.identifier} (#{institution.name})", institution.id] }
      end
      if /publishers/.match?(@partials)
        begin
          @publishers_stats = YAML.load(File.read(publisher_stats_file)) || { presses: [], timestampe: Time.now.utc.to_s } # rubocop:disable Security/YAMLLoad
        rescue StandardError => e
          Rails.logger.error(e.message)
        end
      end
      incognito(incognito_params(params)) if /incognito/i.match?(params['submit'] || '')<commit_msg>Recalculate stats only for publishers partial<commit_after># frozen_string_literal: true

class FulcrumController < ApplicationController
  before_action :authenticate_user!

  def dashboard
    redirect_to action: :index, partials: :dashboard
  end

  def exec
    case params[:cmd]
    when 'ingest'
      ExtractIngestJob.perform_later(params[:token], params[:base], params[:source], params[:target])
    when 'reindex_everything'
      ReindexJob.perform_later('everything')
    when 'reindex_monographs'
      ReindexJob.perform_later('monographs')
    when 'reindex_file_sets'
      ReindexJob.perform_later('file_sets')
    end
    redirect_to action: :index, partials: :dashboard
  end

  def index # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
    @partials = params[:partials]
    @individuals = []
    @institutions = []
    @publishers_stats = { presses: [], timestampe: Time.now.utc.to_s }
    if ['dashboard', 'products', 'components', 'individuals', 'institutions', 'publishers', 'users', 'tokens', 'logs', 'grants', 'monographs', 'assets', 'pages', 'reports', 'customize', 'settings', 'help', 'csv', 'jobs'].include? @partials
      if /dashboard/.match?(@partials)
        @individuals = Individual.where("identifier like ? or name like ?", "%#{params['individual_filter']}%", "%#{params['individual_filter']}%").map { |individual| ["#{individual.identifier} (#{individual.name})", individual.id] }
        @institutions = Institution.where("identifier like ? or name like ?", "%#{params['institution_filter']}%", "%#{params['institution_filter']}%").map { |institution| ["#{institution.identifier} (#{institution.name})", institution.id] }
      end
      if /publishers/.match?(@partials)
        publisher_stats
        begin
          @publishers_stats = YAML.load(File.read(publisher_stats_file)) || { presses: [], timestampe: Time.now.utc.to_s } # rubocop:disable Security/YAMLLoad
        rescue StandardError => e
          Rails.logger.error(e.message)
        end
      end
      incognito(incognito_params(params)) if /incognito/i.match?(params['submit'] || '')
{'fraction_non_alphanumeric': 0.1534994068801898, 'fraction_numerical': 0.0, 'mean_word_length': 4.540078843626807, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6596798', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1283, 'n_words': 252}