<commit_before>include ActionView::Helpers::TextHelper
require 'erb'

module Marty
  class DiagnosticController < ActionController::Base
    layout false
    def op
      begin
        # inject request object into base class of all diagnostics
        Base.request = request

        # determine if request is aggregate and return result
        params[:scope] = 'nodal' unless params[:scope]
        diag = self.class.get_sub_class(params[:op])
        @result = params[:scope] == 'local' ? diag.generate : diag.aggregate
      rescue NameError
        render file: 'public/400', formats: [:html], status: 400, layout: false
      else
        respond_to do |format|
          format.html {@result = diag.display(@result, params[:scope])}
          format.json {render json: @result}
        end
      end
    end

    def self.get_sub_class klass
      const_get(klass.downcase.camelize)
    end

    private
    ############################################################################
    #
    # Diagnostics
    #
    ############################################################################
    class Base
      @@read_only = Marty::Util.db_in_recovery?
      @@template = ActionController::Base.new.lookup_context.
                     find_template("marty/diagnostic/diag").identifier

      def self.request
        @@request
      end

      def self.request= req
        @@request = req
      end

      def self.aggregate op_name=name.demodulize
        get_nodal_diags(op_name)
      end

      def self.get_nodal_diags op_name, scope='local'
        self.get_nodes.map do |n|
          ssl = ENV['HTTPS'] == 'on'
          uri = Addressable::URI.new(host: n, port: ssl ? 443 : @@request.port)
          uri.query_values = {op: op_name.underscore,
                              scope: scope}
          uri.scheme = ssl ? 'https' : 'http'<commit_msg>up version + request fix<commit_after>include ActionView::Helpers::TextHelper
require 'erb'

module Marty
  class DiagnosticController < ActionController::Base
    layout false
    def op
      begin
        # inject request object into base class of all diagnostics
        Base.request = request

        # determine if request is aggregate and return result
        params[:scope] = 'nodal' unless params[:scope]
        diag = self.class.get_sub_class(params[:op])
        @result = params[:scope] == 'local' ? diag.generate : diag.aggregate
      rescue NameError
        render file: 'public/400', formats: [:html], status: 400, layout: false
      else
        respond_to do |format|
          format.html {@result = diag.display(@result, params[:scope])}
          format.json {render json: @result}
        end
      end
    end

    def self.get_sub_class klass
      const_get(klass.downcase.camelize)
    end

    private
    ############################################################################
    #
    # Diagnostics
    #
    ############################################################################
    class Base
      @@request   = nil
      @@read_only = Marty::Util.db_in_recovery?
      @@template  = ActionController::Base.new.lookup_context.
                      find_template("marty/diagnostic/diag").identifier

      def self.request
        @@request
      end

      def self.request= req
        @@request = req
      end

      def self.aggregate op_name=name.demodulize
        get_nodal_diags(op_name)
      end

      def self.get_nodal_diags op_name, scope='local'
        self.get_nodes.map do |n|
          ssl = ENV['HTTPS'] == 'on'
          uri = Addressable::URI.new(host: n, port: ssl ? 443 : @@request.port)
          uri.query_values = {op: op_name.underscore,
                              scope: scope}
          uri.scheme = ssl ? 'https' : 'http'
{'fraction_non_alphanumeric': 0.17174662072621255, 'fraction_numerical': 0.004770739464617015, 'mean_word_length': 2.4371584699453552, 'pattern_counts': {'":': 0, '<': 5, '<?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': '405610', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1020, 'n_words': 254}