<commit_before>class SingleEvent < ActiveRecord::Base

  after_destroy :update_event

  belongs_to :category
  belongs_to :venue
  belongs_to :event
  belongs_to :picture

  delegate :title, :description, to: :event, prefix: true
  delegate :twitter, to: :event

  has_many :comments, as: :commentable, dependent: :destroy
  has_and_belongs_to_many :users, uniq: true

  scope :in_future,
    where("occurrence >= ?", Time.now)
  scope :today_or_in_future,
    where("occurrence >= ?", Time.now.beginning_of_day)
  scope :recent,
    lambda { |limit = 3| today_or_in_future.limit(limit) }
  scope :rule_based_in_future,
    in_future.where(based_on_rule: true)
  scope :in_next,
    lambda { |delta| where(occurrence: (Time.now.to_date)..((Time.now + delta).to_date)) }
  scope :in_next_from,
    lambda { |delta, start_date| where(occurrence: (start_date)..((start_date + delta).to_date)) }
  scope :recent_to_soon,
    lambda { |delta| where(occurrence: (Time.now.to_date - delta)..((Time.now + delta).to_date)) }
  scope :only_tagged_with,
    lambda { |tag| tagged_with(tag) | joins(:event).where('events.id in (?)', Event.tagged_with(tag).map(&:id)) }
  scope :for_user,
    lambda { |user| user ? scoped.select{ |single_event| single_event.is_for_user? user } : scoped }
  default_scope order(:occurrence)

  acts_as_taggable

  def self.search(search)
    unscoped.find(:all, :conditions => ['name LIKE ? OR description LIKE ?', "%#{search}%", "%#{search}%"])
  end

  def full_name
    self.name.blank? ? self.event.name : "#{self.event.name} (#{self.name})"
  end

  alias :title :full_name

  def name_with_date
    if self.full_day
      "#{self.full_name} am #{self.occurrence.strftime("%d.%m.%Y")}"
    else
      "#{self.full_name} am #{self.occurrence.strftime("%d.%m.%Y um %H:%M")}"
    end
  end

  def <=>(other)
    if (self.occurrence.year != other.occurrence.year) || (self.occurrence.month != other.occurrence.month) || (self.occurrence.day != other.occurrence.day)
      # not on same day
      return self.occurrence <=> other.occurrence
    elsif self.full_day
      if other.full_day
        # both are all day, sort via topic
        return self.full_name <=> other.full_name
      else
        # self is all day, other is not
        return -1
      end
    elsif other.full_day
      # other is all day, self is not
      return 1
    else
      # both are not all day, sort via time
      time_comparison = (self.occurrence <=> other.occurrence)

      if time_comparison == 0
        # they are at the same time, sort via topic
        return self.full_name <=> other.full_name
      else
        return time_comparison
      end
    end
  end

  def short_description
    return event.short_description if self.description.blank?
    ActionController::Base.helpers.strip_tags(self.description).truncate 80
  end

  def to_opengraph
    ogdata = event.to_opengraph.merge({
      "og:title"       => name_with_date,
      "og:description" => short_description
    })
    ogdata = ogdata.merge venue.to_opengraph unless venue.nil?
    ogdata = ogdata.reject { |key, value| value.blank? }
    ogdata
  end

  alias :self_category :category
  def category
    self.self_category || (self.event && self.event.category)
  end

  alias :self_venue :venue
  def venue
    self.self_venue || self.event.venue
  end

  alias :self_picture :picture
  def picture
    self.self_picture || self.event.picture
  end

  # Get the attribute from the Event model unless they exist here
  [:url, :twitter_hashtag, :duration, :full_day].each do |item|
    define_method item.to_s do
      value = self.read_attribute(item)
      if !value.nil? && !(value.class.to_s == "String" && value.blank?)
        value
      elsif !self.event.blank?
        self.event.read_attribute(item)
      end
    end
  end

  def to_ri_cal_event
    ri_cal_event = RiCal::Component::Event.new
    ri_cal_event.summary = full_name
    ri_cal_event.description = ActionController::Base.helpers.strip_tags("#{description}\n\n#{event.description}".strip)

    start_time = occurrence
    end_time  = (occurrence + (event.schedule.duration || 1.hour))
<commit_msg>SingleEvent Kategorie ID auch von event durchreichen, Scope für Kategorie<commit_after>class SingleEvent < ActiveRecord::Base

  after_destroy :update_event

  belongs_to :category
  belongs_to :venue
  belongs_to :event
  belongs_to :picture

  delegate :title, :description, to: :event, prefix: true
  delegate :twitter, to: :event

  has_many :comments, as: :commentable, dependent: :destroy
  has_and_belongs_to_many :users, uniq: true

  scope :in_future,
    where("occurrence >= ?", Time.now)
  scope :today_or_in_future,
    where("occurrence >= ?", Time.now.beginning_of_day)
  scope :recent,
    lambda { |limit = 3| today_or_in_future.limit(limit) }
  scope :rule_based_in_future,
    in_future.where(based_on_rule: true)
  scope :in_next,
    lambda { |delta| where(occurrence: (Time.now.to_date)..((Time.now + delta).to_date)) }
  scope :in_next_from,
    lambda { |delta, start_date| where(occurrence: (start_date)..((start_date + delta).to_date)) }
  scope :recent_to_soon,
    lambda { |delta| where(occurrence: (Time.now.to_date - delta)..((Time.now + delta).to_date)) }
  scope :only_tagged_with,
    lambda { |tag| tagged_with(tag) | joins(:event).where('events.id in (?)', Event.tagged_with(tag).map(&:id)) }
  #scope :for_user,
  #  lambda { |user| user ? scoped.select{ |single_event| single_event.is_for_user? user } : scoped }
  
  # Categories as an array of ids
  scope :in_categories,
    lambda { |categories| joins(:event).where('single_events.category_id IN (?) OR (single_events.category_id IS NULL AND events.category_id IN (?))', categories, categories) }

  # Tags (hated tags are ignored unless a loved tag is present)
  # TODO: Implement

  default_scope order(:occurrence)

  acts_as_taggable

  def self.search(search)
    unscoped.find(:all, :conditions => ['name LIKE ? OR description LIKE ?', "%#{search}%", "%#{search}%"])
  end

  def full_name
    self.name.blank? ? self.event.name : "#{self.event.name} (#{self.name})"
  end

  alias :title :full_name

  def name_with_date
    if self.full_day
      "#{self.full_name} am #{self.occurrence.strftime("%d.%m.%Y")}"
    else
      "#{self.full_name} am #{self.occurrence.strftime("%d.%m.%Y um %H:%M")}"
    end
  end

  def <=>(other)
    if (self.occurrence.year != other.occurrence.year) || (self.occurrence.month != other.occurrence.month) || (self.occurrence.day != other.occurrence.day)
      # not on same day
      return self.occurrence <=> other.occurrence
    elsif self.full_day
      if other.full_day
        # both are all day, sort via topic
        return self.full_name <=> other.full_name
      else
        # self is all day, other is not
        return -1
      end
    elsif other.full_day
      # other is all day, self is not
      return 1
    else
      # both are not all day, sort via time
      time_comparison = (self.occurrence <=> other.occurrence)

      if time_comparison == 0
        # they are at the same time, sort via topic
        return self.full_name <=> other.full_name
      else
        return time_comparison
      end
    end
  end

  def short_description
    return event.short_description if self.description.blank?
    ActionController::Base.helpers.strip_tags(self.description).truncate 80
  end

  def to_opengraph
    ogdata = event.to_opengraph.merge({
      "og:title"       => name_with_date,
      "og:description" => short_description
    })
    ogdata = ogdata.merge venue.to_opengraph unless venue.nil?
    ogdata = ogdata.reject { |key, value| value.blank? }
    ogdata
  end

  alias :self_category :category
  def category
    self.self_category || (self.event && self.event.category)
  end

  def category_overwritten?
    read_attribute(:category_id) != nil
  end

  alias :self_venue :venue
  def venue
    self.self_venue || self.event.venue
  end

  alias :self_picture :picture
  def picture
    self.self_picture || self.event.picture
  end

  # Get the attribute from the Event model unless they exist here
  [:url, :twitter_hashtag, :duration, :full_day, :category_id].each do |item|
    define_method item.to_s do
      value = self.read_attribute(item)
      if !value.nil? && !(value.class.to_s == "String" && value.blank?)
        value
      elsif !self.event.blank?
        self.event.read_attribute(item)
      end
    end
  end

  def to_ri_cal_event
    ri_cal_event = RiCal::Component::Event.new
    ri_cal_event.summary = full_name
    ri_cal_event.description = ActionController::Base.helpers.strip_tags("#{description}\n\n#{event.description}".strip)

    start_time = occurrence
    end_time  = (occurrence + (event.schedule.duration || 1.hour))

{'fraction_non_alphanumeric': 0.12142613053878575, 'fraction_numerical': 0.0015947146599840528, 'mean_word_length': 3.3465346534653464, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '6169755', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2896, 'n_words': 689}