<commit_before># encoding: utf-8

module CartoDB
  module Visualization
    class Presenter
      def initialize(visualization, options={})
        @visualization  = visualization
        @options        = options
      end #initialize

      def to_poro
        poro = {
          id:               visualization.id,
          name:             visualization.name,
          map_id:           visualization.map_id,
          active_layer_id:  visualization.active_layer_id,
          type:             visualization.type,
          tags:             visualization.tags,
          description:      visualization.description,
          privacy:          visualization.privacy.upcase,
          stats:            visualization.stats,
          created_at:       visualization.created_at,
          updated_at:       visualization.updated_at
        }
        poro.merge!(related) if options.fetch(:related, true)
        poro
      end #to_poro

      private

      attr_reader :visualization, :options

      def related
        {
          table:            table_data_for(visualization.table),
          related_tables:   related_tables,
        }
      end #related

      def table_data_for(table=nil)
        return {} unless table
        {
          id:               table.id,
          name:             table.name,
          privacy:          table.privacy_text,
          size:             table.table_size,
          row_count:        table.rows_estimated,
          updated_at:       table.updated_at
        }
      end #table_data_for

      def related_tables
        without_associated_table(visualization.related_tables)
          .map { |table| table_data_for(table) }
      end #related_tables

      def without_associated_table(tables)
        return tables unless visualization.table
        tables.select { |table| table.id != visualization.table.id }
      end #without_associated_table
    end # Presenter
  end # Visualization
end # CartoDB

<commit_msg>Include table field in Visualization JSON representation<commit_after># encoding: utf-8

module CartoDB
  module Visualization
    class Presenter
      def initialize(visualization, options={})
        @visualization  = visualization
        @options        = options
      end #initialize

      def to_poro
        poro = {
          id:               visualization.id,
          name:             visualization.name,
          map_id:           visualization.map_id,
          active_layer_id:  visualization.active_layer_id,
          type:             visualization.type,
          tags:             visualization.tags,
          description:      visualization.description,
          privacy:          visualization.privacy.upcase,
          stats:            visualization.stats,
          created_at:       visualization.created_at,
          updated_at:       visualization.updated_at,
          table:            table_data_for(visualization.table)
        }
        poro.merge!(related) if options.fetch(:related, true)
        poro
      end #to_poro

      private

      attr_reader :visualization, :options

      def related
        { related_tables:   related_tables }
      end #related

      def table_data_for(table=nil)
        return {} unless table
        {
          id:               table.id,
          name:             table.name,
          privacy:          table.privacy_text,
          size:             table.table_size,
          row_count:        table.rows_estimated,
          updated_at:       table.updated_at
        }
      end #table_data_for

      def related_tables
        without_associated_table(visualization.related_tables)
          .map { |table| table_data_for(table) }
      end #related_tables

      def without_associated_table(tables)
        return tables unless visualization.table
        tables.select { |table| table.id != visualization.table.id }
      end #without_associated_table
    end # Presenter
  end # Visualization
end # CartoDB


{'fraction_non_alphanumeric': 0.0644433299899699, 'fraction_numerical': 0.0005015045135406219, 'mean_word_length': 1.6789791806581598, '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': '6703141', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1024, 'n_words': 220}