<commit_before># encoding: UTF-8

require 'json'
require_relative './carto_json_serializer'

class Carto::State < ActiveRecord::Base
  belongs_to :visualization, class_name: Carto::Visualization
  belongs_to :user, class_name: Carto::User

  default_scope order('created_at DESC')

  serialize :json, ::Carto::CartoJsonSymbolizerSerializer

  validates :json, carto_json_symbolizer: true
  validates :visualization, :user, presence: true

  after_initialize :ensure_json

  def repopulate_widget_ids(widgets)
    return if widgets.empty?

    new_widgets_json = {}
    widgets_json = json[:widgets]
    widgets.each_with_index do |widget, index|
      new_widgets_json[widget.id.to_sym] = widgets_json[widgets_json.keys[index]]
    end

    new_json = json
    new_json[:widgets] = new_widgets_json

    update_attribute(:json, new_json)
  end

  private

  def ensure_json
    self.json ||= Hash.new
  end
end<commit_msg>remove dead code: not necessary until widget state is fixed<commit_after># encoding: UTF-8

require 'json'
require_relative './carto_json_serializer'

class Carto::State < ActiveRecord::Base
  belongs_to :visualization, class_name: Carto::Visualization
  belongs_to :user, class_name: Carto::User

  default_scope order('created_at DESC')

  serialize :json, ::Carto::CartoJsonSymbolizerSerializer

  validates :json, carto_json_symbolizer: true
  validates :visualization, :user, presence: true

  after_initialize :ensure_json

  private

  def ensure_json
    self.json ||= Hash.new
  end
end
{'fraction_non_alphanumeric': 0.0903098220171391, 'fraction_numerical': 0.0013183915622940012, 'mean_word_length': 5.096385542168675, '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': '3710765', 'n_tokens_mistral': 511, 'n_tokens_neox': 481, 'n_words': 114}