<commit_before># == Schema Information
#
# Table name: events
#
#  id             :integer          not null, primary key
#  title          :string           not null
#  description    :string
#  image          :string
#  inactive_image :string
#  content_ids    :text             default([]), is an Array
#  publish_days   :text             default([]), is an Array
#  duration       :integer          not null
#  kind           :string
#  user_level     :integer          default(1)
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#
module Api
  class EventSerializer < ActiveModel::Serializer
    attributes :id,
               :title,
               :description,
               :image,
               :inactive_image,
               :contents,
               :duration,
               :kind,
               :user_level,
               :is_available,
               :completed

    def title
      lang = current_user.preferred_lang
      unless lang == ApplicationController::DEFAULT_LANGUAGE
        resp = TranslatedAttribute.where(translatable_id: object.id, name: "title").last
        return title = resp ? resp.content : object.title
      end
      title = object.title
    end

    def description
      lang = current_user.preferred_lang
      unless lang == ApplicationController::DEFAULT_LANGUAGE
        resp = TranslatedAttribute.where(translatable_id: object.id, name: "description").last
        return description = resp ? resp.content : object.description
      end
      description = object.description
    end

    def image
      image = object.image
      image ? image.url : ''
    end

    def inactive_image
      inactive_image = object.inactive_image
      inactive_image ? inactive_image.url : ''
    end

    def contents
      ids = object.content_ids.map.reject { |id| id.empty? }
      branches_neurons_ids = TreeService::NeuronsFetcher.new(nil).neurons_ids_by_branch
      ids.map do |id|
        content = Content.find(id)
        neuron = content.neuron
        title = neuron.title
        lang = current_user.preferred_lang
        unless lang == ApplicationController::DEFAULT_LANGUAGE
          resp = TranslatedAttribute.where(translatable_id: neuron.id, name: "title").last
          title = resp ? resp.content : title
        end
        {
          content_id: id,
          neuron: title,
          neuron_color: TreeService::NeuronsFetcher.new(neuron).neuron_color(branches_neurons_ids)
        }
      end
    end

    def is_available
      !current_user.user_events.find_by_event_id(object.id)
    end

    def completed
      event_user = current_user.user_events.find_by_event_id(object.id)
      event_user ? event_user.completed : false
    end<commit_msg>fix title neuron translated into events<commit_after># == Schema Information
#
# Table name: events
#
#  id             :integer          not null, primary key
#  title          :string           not null
#  description    :string
#  image          :string
#  inactive_image :string
#  content_ids    :text             default([]), is an Array
#  publish_days   :text             default([]), is an Array
#  duration       :integer          not null
#  kind           :string
#  user_level     :integer          default(1)
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#
module Api
  class EventSerializer < ActiveModel::Serializer
    attributes :id,
               :title,
               :description,
               :image,
               :inactive_image,
               :contents,
               :duration,
               :kind,
               :user_level,
               :is_available,
               :completed

    def title
      lang = current_user.preferred_lang
      unless lang == ApplicationController::DEFAULT_LANGUAGE
        resp = TranslatedAttribute.where(translatable_id: object.id, name: "title").last
        return title = resp ? resp.content : object.title
      end
      title = object.title
    end

    def description
      lang = current_user.preferred_lang
      unless lang == ApplicationController::DEFAULT_LANGUAGE
        resp = TranslatedAttribute.where(translatable_id: object.id, name: "description").last
        return description = resp ? resp.content : object.description
      end
      description = object.description
    end

    def image
      image = object.image
      image ? image.url : ''
    end

    def inactive_image
      inactive_image = object.inactive_image
      inactive_image ? inactive_image.url : ''
    end

    def contents
      ids = object.content_ids.map.reject { |id| id.empty? }
      branches_neurons_ids = TreeService::NeuronsFetcher.new(nil).neurons_ids_by_branch
      ids.map do |id|
        content = Content.find(id)
        neuron = content.neuron
        neuron_title = neuron.title
        lang = current_user.preferred_lang
        unless lang == ApplicationController::DEFAULT_LANGUAGE
          resp = TranslatedAttribute.where(translatable_id: neuron.id, name: "title", translatable_type: "Neuron").last
          neuron_title = resp ? resp.content : neuron_title
        end
        {
          content_id: id,
          neuron: neuron_title,
          neuron_color: TreeService::NeuronsFetcher.new(neuron).neuron_color(branches_neurons_ids)
        }
      end
    end

    def is_available
      !current_user.user_events.find_by_event_id(object.id)
    end

    def completed
      event_user = current_user.user_events.find_by_event_id(object.id)
      event_user ? event_user.completed : false
    end
{'fraction_non_alphanumeric': 0.07685433422698838, 'fraction_numerical': 0.00035746201966041106, 'mean_word_length': 2.0646221248630887, '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': '5922604', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1532, 'n_words': 358}