<commit_before># frozen_string_literal: true

require_dependency "gobierto_data"

module GobiertoData
  class Visualization < ApplicationRecord
    include GobiertoData::Favoriteable

    belongs_to :query
    belongs_to :user
    has_one :dataset, through: :query
    enum privacy_status: { open: 0, closed: 1 }

    translates :name

    scope :active, -> { joins(:dataset).where(GobiertoData::Dataset.table_name => { visibility_level: GobiertoData::Dataset.visibility_levels[:active] }) }

    validates :query, :user, :name, presence: true
    delegate :site, :dataset, :visibility_level, to: :query
  end
end
<commit_msg>Add result instance method to visualization model<commit_after># frozen_string_literal: true

require_dependency "gobierto_data"

module GobiertoData
  class Visualization < ApplicationRecord
    include GobiertoData::Favoriteable

    belongs_to :query
    belongs_to :user
    has_one :dataset, through: :query
    enum privacy_status: { open: 0, closed: 1 }

    translates :name

    scope :active, -> { joins(:dataset).where(GobiertoData::Dataset.table_name => { visibility_level: GobiertoData::Dataset.visibility_levels[:active] }) }

    validates :query, :user, :name, presence: true
    delegate :site, :dataset, :visibility_level, to: :query

    def result(include_draft: false)
      return unless sql.present?

      Connection.execute_query(site, sql, include_draft: include_draft)
    end
  end
end

{'fraction_non_alphanumeric': 0.09652777777777778, 'fraction_numerical': 0.002777777777777778, 'mean_word_length': 4.673228346456693, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4320055', 'n_tokens_mistral': 448, 'n_tokens_neox': 430, 'n_words': 111}