<commit_before># -*- encoding : utf-8 -*-
class Activity < ActiveRecord::Base

  belongs_to :target, :polymorphic => true
  belongs_to :comment_target, :polymorphic => true
  belongs_to :user
  belongs_to :project

  scope :for_task_lists, lambda{ where("target_type = 'TaskList' OR target_type = 'Task' OR comment_target_type = 'TaskList' OR comment_target_type = 'Task'") }
  scope :for_conversations, lambda{ where("target_type = 'Conversation' OR comment_target_type = 'Conversation'") }
  scope :for_tasks, lambda{ where("target_type = ? OR comment_target_type = ?", 'Task', 'Task') }
  scope :in_targets, lambda { |targets| where("target_id IN (?) OR comment_target_id IN (?)", Array(targets).collect(&:id), Array(targets).collect(&:id)) }
  scope :latest, lambda{ limit_per_page.by_id }
  scope :in_projects, lambda { |projects| where(:project_id => Array(projects).collect(&:id)) }
  scope :limit_per_page, lambda{ limit(Teambox.config.activities_per_page) }
  scope :by_id, lambda{ order('id DESC') }
  scope :by_updated, lambda{ order('updated_at DESC') }
  scope :threads, lambda{ where("target_type != 'Comment'") }
  scope :before, lambda { |activity_id| where("id < ?", activity_id) }
  scope :after, lambda { |activity_id| where("id > ?", activity_id) }
  scope :from_user, lambda { |user| where(:user_id => user.id) }

  def self.log(project,target,action,creator_id)
    project_id = project.try(:id)
    return if project.try(:is_importing)

    if target.is_a? Comment<commit_msg>fix scopes for postgresql in activity model<commit_after># -*- encoding : utf-8 -*-
class Activity < ActiveRecord::Base

  belongs_to :target, :polymorphic => true
  belongs_to :comment_target, :polymorphic => true
  belongs_to :user
  belongs_to :project

  scope :for_task_lists, :conditions => "target_type = 'TaskList' OR target_type = 'Task' OR comment_target_type = 'TaskList' OR comment_target_type = 'Task'"
  scope :for_conversations, :conditions => "target_type = 'Conversation' OR comment_target_type = 'Conversation'"
  scope :for_tasks, where("target_type = ? OR comment_target_type = ?", "Task", "Task" )
  scope :in_targets, lambda {|targets| where ["target_id IN (?) OR comment_target_id IN (?)", *(Array(targets).collect(&:id)*2)] }

  scope :latest, :order => 'id DESC', :limit => Teambox.config.activities_per_page

  scope :in_projects, lambda { |projects| { :conditions => ["project_id IN (?)", Array(projects).collect(&:id) ] } }
  scope :limit_per_page, :limit => Teambox.config.activities_per_page
  scope :by_id, :order => 'id DESC'
  scope :by_updated, :order => 'updated_at desc'
  scope :threads, :conditions => "target_type != 'Comment'"
  scope :before, lambda { |activity_id| { :conditions => ["id < ?", activity_id ] } }
  scope :after, lambda { |activity_id| { :conditions => ["id > ?", activity_id ] } }
  scope :from_user, lambda { |user| { :conditions => { :user_id => user.id } } }

  def self.log(project,target,action,creator_id)
    project_id = project.try(:id)
    return if project.try(:is_importing)

    if target.is_a? Comment
{'fraction_non_alphanumeric': 0.15271898404428524, 'fraction_numerical': 0.0009768804949527841, 'mean_word_length': 5.308008213552362, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, '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': '5862850', 'n_tokens_mistral': 1031, 'n_tokens_neox': 1017, 'n_words': 244}