<commit_before>class Course < ActiveRecord::Base
  acts_as_paranoid

  attr_accessible :creator_id, :description, :logo_url, :title
  before_create :populate_preference

  belongs_to :creator, class_name: "User"

  has_many :missions,       dependent: :destroy
  has_many :announcements,  dependent: :destroy
  has_many :user_courses,   dependent: :destroy
  has_many :trainings,      dependent: :destroy

  has_many :mcqs,             through: :trainings
  has_many :coding_questions, through: :trainings

  has_many :users, through: :user_courses

  has_many :std_answers,        through: :user_courses
  has_many :std_coding_answers, through: :user_courses

  has_many :submissions,          through: :user_courses
  has_many :training_submissions, through: :user_courses

  has_many :activities, dependent: :destroy

  has_many :levels,       dependent: :destroy
  has_many :achievements, dependent: :destroy

  has_many :tags,       dependent: :destroy
  has_many :tag_groups, dependent: :destroy

  has_many :course_themes, dependent: :destroy  # currently only has one though

  has_many :tutorial_groups,        dependent: :destroy
  has_many :file_uploads,           as: :owner
  has_many :course_preferences,     dependent: :destroy
  has_many :comment_subscriptions,  dependent: :destroy
  has_many :mass_enrollment_emails, dependent: :destroy
  has_many :enroll_requests,        dependent: :destroy
  has_many :pending_comments, class_name: "PendingComments"

  def asms
    missions + trainings
  end

  def commented_topics
    #self.comment_subscriptions.map { |cs| cs.topic }.select{ |cs| cs.}.uniq
    self.comment_subscriptions.reduce([]) {|acc, cs|  if cs.topic.comments.first then acc.push(cs.topic) else acc end}.uniq<commit_msg>using count instead of first.<commit_after>class Course < ActiveRecord::Base
  acts_as_paranoid

  attr_accessible :creator_id, :description, :logo_url, :title
  before_create :populate_preference

  belongs_to :creator, class_name: "User"

  has_many :missions,       dependent: :destroy
  has_many :announcements,  dependent: :destroy
  has_many :user_courses,   dependent: :destroy
  has_many :trainings,      dependent: :destroy

  has_many :mcqs,             through: :trainings
  has_many :coding_questions, through: :trainings

  has_many :users, through: :user_courses

  has_many :std_answers,        through: :user_courses
  has_many :std_coding_answers, through: :user_courses

  has_many :submissions,          through: :user_courses
  has_many :training_submissions, through: :user_courses

  has_many :activities, dependent: :destroy

  has_many :levels,       dependent: :destroy
  has_many :achievements, dependent: :destroy

  has_many :tags,       dependent: :destroy
  has_many :tag_groups, dependent: :destroy

  has_many :course_themes, dependent: :destroy  # currently only has one though

  has_many :tutorial_groups,        dependent: :destroy
  has_many :file_uploads,           as: :owner
  has_many :course_preferences,     dependent: :destroy
  has_many :comment_subscriptions,  dependent: :destroy
  has_many :mass_enrollment_emails, dependent: :destroy
  has_many :enroll_requests,        dependent: :destroy
  has_many :pending_comments, class_name: "PendingComments"

  def asms
    missions + trainings
  end

  def commented_topics
    # self.comment_subscriptions.map { |cs| cs.topic }.select{ |cs| cs.}.uniq
    self.comment_subscriptions.reduce([]) {|acc, cs|  if cs.topic.comments.count then acc.push(cs.topic) else acc end}.uniq
{'fraction_non_alphanumeric': 0.08672163775945407, 'fraction_numerical': 0.0, 'mean_word_length': 4.290225563909774, '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': '3700606', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1100, 'n_words': 281}