<commit_before># frozen_string_literal: true

module GobiertoSeeds
  class Recipe
    def self.run(site)
      description = site.custom_fields.localized_string.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "description")
      if description.new_record?
        description.name_translations = { ca: "Descripció", en: "Description", es: "Descripción" }
        description.position = 1
        description.options = { configuration: {} }
        description.save
      end

      frequency = site.custom_fields.vocabulary_options.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "frequency")
      if frequency.new_record?
        vocabulary = site.vocabularies.find_or_initialize_by(slug: "datasets-frequency")
        if vocabulary.new_record?
          vocabulary.name_translations = { ca: "Freqüència", en: "Frequency", es: "Frecuencia" }
          vocabulary.save
          vocabulary.terms.create(name_translations: { ca: "Anual", en: "Annual", es: "Anual" })
          vocabulary.terms.create(name_translations: { ca: "Trimestral", en: "Quarterly", es: "Trimestral" })
          vocabulary.terms.create(name_translations: { ca: "Mensual", en: "Monthly", es: "Mensual" })
          vocabulary.terms.create(name_translations: { ca: "Diària", en: "Daily", es: "Diaria" })
        end
        frequency.name_translations = { ca: "Freqüència", en: "Frequency", es: "Frecuencia" }
        frequency.position = 2
        frequency.options = {
          configuration: { vocabulary_type: "single_select" },
          vocabulary_id: vocabulary.id.to_s
        }
        frequency.save
      end

      category = site.custom_fields.vocabulary_options.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "category")
      return unless category.new_record?

      vocabulary = site.vocabularies.find_or_initialize_by(slug: "datasets-category")
      if vocabulary.new_record?
        vocabulary.name_translations = { ca: "Categoria", en: "Category", es: "Categoría" }
        vocabulary.save
        vocabulary.terms.create(name_translations: { ca: "General", en: "General", es: "General" })
      end
      category.name_translations = { ca: "Categoria", en: "Category", es: "Categoría" }
      category.position = 3
      category.options = {
        configuration: { vocabulary_type: "single_select" },
        vocabulary_id: vocabulary.id.to_s
      }
      category.save
    end
  end
end<commit_msg>Update gobierto data seed recipe<commit_after># frozen_string_literal: true

module GobiertoSeeds
  class Recipe
    DEFAULT_CATEGORY_NAMES = [
      "Sector público",
      "Transporte",
      "Medio ambiente",
      "Ciencia y tecnología",
      "Economía",
      "Medio Rural",
      "Demografía",
      "Hacienda",
      "Educación",
      "Cultura y ocio",
      "Turismo",
      "Empleo",
      "Sociedad y bienestar",
      "Urbanismo e infraestructuras",
      "Comercio",
      "Legislación y justicia",
      "Salud",
      "Seguridad",
      "Industria",
      "Energía",
      "Deporte",
      "Vivienda"
    ].freeze

    def self.run(site)
      description = site.custom_fields.localized_string.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "description")
      if description.new_record?
        description.name_translations = { ca: "Descripció", en: "Description", es: "Descripción" }
        description.position = 1
        description.options = { configuration: {} }
        description.save
      end

      frequency = site.custom_fields.vocabulary_options.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "frequency")
      if frequency.new_record?
        vocabulary = site.vocabularies.find_or_initialize_by(slug: "datasets-frequency")
        if vocabulary.new_record?
          vocabulary.name_translations = { ca: "Freqüència de conjunt de dades", en: "Dataset frequency", es: "Frecuencia de conjunto de datos" }
          vocabulary.save
          vocabulary.terms.create(name_translations: { ca: "Anual", en: "Annual", es: "Anual" })
          vocabulary.terms.create(name_translations: { ca: "Trimestral", en: "Quarterly", es: "Trimestral" })
          vocabulary.terms.create(name_translations: { ca: "Mensual", en: "Monthly", es: "Mensual" })
          vocabulary.terms.create(name_translations: { ca: "Diària", en: "Daily", es: "Diaria" })
        end
        frequency.name_translations = { ca: "Freqüència", en: "Frequency", es: "Frecuencia" }
        frequency.position = 2
        frequency.options = {
          configuration: { vocabulary_type: "single_select" },
          vocabulary_id: vocabulary.id.to_s
        }
        frequency.save
      end

      category = site.custom_fields.vocabulary_options.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "category")
      return unless category.new_record?

      vocabulary = site.vocabularies.find_or_initialize_by(slug: "datasets-category")
      if vocabulary.new_record?
        vocabulary.name_translations = { ca: "Categoria de conjunt de dades", en: "Dataset Category", es: "Categoría de conjunto de datos" }
        vocabulary.save
        DEFAULT_CATEGORY_NAMES.each do |category_name|
          vocabulary.terms.create(
            name_translations: Hash[site.configuration.available_locales.product([category_name])]
          )
        end
      end
      category.name_translations = { ca: "Categoria", en: "Category", es: "Categoría" }
      category.position = 3
      category.options = {
        configuration: { vocabulary_type: "multiple_select" },
        vocabulary_id: vocabulary.id.to_s
      }
      category.save
    end
  end
end
{'fraction_non_alphanumeric': 0.11686026047166491, 'fraction_numerical': 0.0010559662090813093, 'mean_word_length': 3.109182935647144, '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': '4809491', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1806, 'n_words': 338}