<commit_before># encoding: utf-8
require 'json'
require_relative '../../../models/visualization/member'
require_relative '../../../models/visualization/presenter'
require_relative '../../../models/visualization/collection'
require_relative '../../../models/visualization/locator'
require_relative '../../../models/visualization/copier'
require_relative '../../../models/visualization/table_blender'
require_relative '../../../models/map/presenter'

class Api::Json::VisualizationsController < Api::ApplicationController
  include CartoDB

  ssl_required :index, :show, :create, :update, :destroy
  skip_before_filter :api_authorization_required, only: [:vizjson1, :vizjson2]

  def index
    collection  = Visualization::Collection.new.fetch(
      params.dup.merge(scope_for(current_user))
    )
    response    = {
      visualizations: collection,
      total_entries:  collection.count
    }
    render_jsonp(response)
  end #index

  def create
    if params[:source_visualization_id]
      source    = Visualization::Member.new(
                    id: params.fetch(:source_visualization_id)
                  ).fetch
      member    = Visualization::Copier.new(
                    current_user, source, params.fetch(:name, nil)
                  )
    elsif params[:tables]
      tables    = params[:tables].map do |table_name| 
                    ::Table.find_by_subdomain(request.subdomain, table_name)
                  end
      map       = Visualization::TableBlender.new(current_user, tables).blend
      member    = Visualization::Member.new(
                    payload.merge(map_id: map.id, type: 'derived')
                  )
      member.store
    else
      member    = Visualization::Member.new(payload).store<commit_msg>call #copy on Visualization::Copier when copying a visualization<commit_after># encoding: utf-8
require 'json'
require_relative '../../../models/visualization/member'
require_relative '../../../models/visualization/presenter'
require_relative '../../../models/visualization/collection'
require_relative '../../../models/visualization/locator'
require_relative '../../../models/visualization/copier'
require_relative '../../../models/visualization/table_blender'
require_relative '../../../models/map/presenter'

class Api::Json::VisualizationsController < Api::ApplicationController
  include CartoDB

  ssl_required :index, :show, :create, :update, :destroy
  skip_before_filter :api_authorization_required, only: [:vizjson1, :vizjson2]

  def index
    collection  = Visualization::Collection.new.fetch(
      params.dup.merge(scope_for(current_user))
    )
    response    = {
      visualizations: collection,
      total_entries:  collection.count
    }
    render_jsonp(response)
  end #index

  def create
    if params[:source_visualization_id]
      source    = Visualization::Member.new(
                    id: params.fetch(:source_visualization_id)
                  ).fetch
      member    = Visualization::Copier.new(
                    current_user, source, params.fetch(:name, nil)
                  ).copy.store
    elsif params[:tables]
      tables    = params[:tables].map do |table_name| 
                    ::Table.find_by_subdomain(request.subdomain, table_name)
                  end
      map       = Visualization::TableBlender.new(current_user, tables).blend
      member    = Visualization::Member.new(
                    payload.merge(map_id: map.id, type: 'derived')
                  )
      member.store
    else
      member    = Visualization::Member.new(payload).store
{'fraction_non_alphanumeric': 0.12647887323943663, 'fraction_numerical': 0.0016901408450704226, 'mean_word_length': 2.630879345603272, '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': '4665092', 'n_tokens_mistral': 1000, 'n_tokens_neox': 971, 'n_words': 177}