<commit_before>require 'qreport'
require 'qreport/model'
require 'qreport/initialization'

module Qreport
  class ReportRun
    include Model, Initialization

    attr_accessor :id
    attr_accessor :name, :sql, :additional_columns
    attr_accessor :description
    attr_accessor :arguments
    attr_accessor :report_id
    attr_accessor :report_sql
    attr_accessor :columns, :base_columns, :column_signature
    attr_accessor :report_table
    attr_accessor :nrows
    attr_accessor :created_at, :started_at, :finished_at

    # Construct report_table name from column names and types.
    def report_table
      @report_table ||=
        "#{name}_#{column_signature}".
        gsub(/[^a-z0-9_]/i, '_').freeze
    end

    def column_signature
      @column_signature ||=
        begin
          return @column_signature = "ERROR" if base_columns.empty?
          column_signature_string = columns.to_json
          @column_signature_hash = Digest::MD5.hexdigest(column_signature_string)
          Base64.strict_encode64(Digest::MD5.digest(column_signature_string)).
            sub(/=+$/, '').
            gsub(/[^a-z0-9]/i, '_').
            downcase.
            freeze
        end
    end

    def base_columns
      @base_columns ||= EMPTY_Array
    end

    def additional_columns
      @additional_columns ||= EMPTY_Array
    end

    def columns
      @columns ||=
        base_columns +
        additional_columns.map{|x| x.map(&:to_s)}
    end<commit_msg>Reset columns if base_columns or additional_columns changes.<commit_after>require 'qreport'
require 'qreport/model'
require 'qreport/initialization'

module Qreport
  class ReportRun
    include Model, Initialization

    attr_accessor :id
    attr_accessor :name, :sql, :additional_columns
    attr_accessor :description
    attr_accessor :arguments
    attr_accessor :report_id
    attr_accessor :report_sql
    attr_accessor :columns, :base_columns, :column_signature
    attr_accessor :report_table
    attr_accessor :nrows
    attr_accessor :created_at, :started_at, :finished_at

    # Construct report_table name from column names and types.
    def report_table
      @report_table ||=
        "#{name}_#{column_signature}".
        gsub(/[^a-z0-9_]/i, '_').freeze
    end

    def column_signature
      @column_signature ||=
        begin
          return @column_signature = "ERROR" if base_columns.empty?
          column_signature_string = columns.to_json
          @column_signature_hash = Digest::MD5.hexdigest(column_signature_string)
          Base64.strict_encode64(Digest::MD5.digest(column_signature_string)).
            sub(/=+$/, '').
            gsub(/[^a-z0-9]/i, '_').
            downcase.
            freeze
        end
    end

    def base_columns
      @base_columns ||= EMPTY_Array
    end
    def base_columns= x
      @base_columns = x
      @columns = nil
    end

    def additional_columns
      @additional_columns ||= EMPTY_Array
    end
    def additional_columns= x
      @additional_columns ||= EMPTY_Array
      @columns = nil
    end

    def columns
      @columns ||=
        base_columns +
        additional_columns.map{|x| x.map(&:to_s)}
    end
{'fraction_non_alphanumeric': 0.09136895352513437, 'fraction_numerical': 0.006323110970597534, 'mean_word_length': 2.7223529411764704, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7287855', 'n_tokens_mistral': 991, 'n_tokens_neox': 961, 'n_words': 203}