<commit_before># frozen_string_literal: true
# == Schema Information
#
# Table name: contents
#
#  id                   :integer          not null, primary key
#  type                 :string
#  title                :string
#  description          :text
#  is_published         :boolean
#  position             :integer
#  created_at           :datetime         not null
#  updated_at           :datetime         not null
#  picture_file_name    :string
#  picture_content_type :string
#  picture_file_size    :integer
#  picture_updated_at   :datetime
#

class Activity < Content
  has_many :related_contents, dependent: :destroy
  has_many :publications, through: :related_contents
  belongs_to :programme, class_name: 'Activity'
  has_many :programme_activities, class_name: 'Activity', foreign_key: 'programme_id'

  scope :programmes, -> {joins(:content_type).where(content_types: {title: ContentType::PROGRAMME}).published.order(:title)}
  scope :by_programme, ->(programme) {where("programme_id = ? OR id = ?", programme, programme)}

  acts_as_taggable

  def is_programme?
    content_type && content_type.title == ContentType::PROGRAMME
  end

  class << self
    def fetch_all(options)
      tags = options['tags'].split(',')               if options['tags'].present?
      type = options['type']                          if options['type'].present?
      partners = options['partners']                  if options['partners'].present?
      programme = options['programme'] if options['programme'].present?
      status = options['status'] if options['status'].present?

      activities = Activity.by_published.order_by_status_and_title
      activities = activities.by_tags(tags)   if tags.present?
      activities = activities.by_type(type)   if type.present?
      activities = activities.by_partners(partners)   if partners.present?
      activities = activities.by_programme(programme) if programme.present?<commit_msg>Fix ambiguity in SQL query<commit_after># frozen_string_literal: true
# == Schema Information
#
# Table name: contents
#
#  id                   :integer          not null, primary key
#  type                 :string
#  title                :string
#  description          :text
#  is_published         :boolean
#  position             :integer
#  created_at           :datetime         not null
#  updated_at           :datetime         not null
#  picture_file_name    :string
#  picture_content_type :string
#  picture_file_size    :integer
#  picture_updated_at   :datetime
#

class Activity < Content
  has_many :related_contents, dependent: :destroy
  has_many :publications, through: :related_contents
  belongs_to :programme, class_name: 'Activity'
  has_many :programme_activities, class_name: 'Activity', foreign_key: 'programme_id'

  scope :programmes, -> {joins(:content_type).where(content_types: {title: ContentType::PROGRAMME}).published.order(:title)}
  scope :by_programme, ->(programme) {where("contents.programme_id = ? OR contents.id = ?", programme, programme)}

  acts_as_taggable

  def is_programme?
    content_type && content_type.title == ContentType::PROGRAMME
  end

  class << self
    def fetch_all(options)
      tags = options['tags'].split(',')               if options['tags'].present?
      type = options['type']                          if options['type'].present?
      partners = options['partners']                  if options['partners'].present?
      programme = options['programme'] if options['programme'].present?
      status = options['status'] if options['status'].present?

      activities = Activity.by_published.order_by_status_and_title
      activities = activities.by_tags(tags)   if tags.present?
      activities = activities.by_type(type)   if type.present?
      activities = activities.by_partners(partners)   if partners.present?
      activities = activities.by_programme(programme) if programme.present?
{'fraction_non_alphanumeric': 0.10391604811876119, 'fraction_numerical': 0.0, 'mean_word_length': 3.0413650465356774, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '5500346', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1090, 'n_words': 249}