<commit_before>require_dependency 'profile_suggestion'

class ProfileSuggestion

  CATEGORIES.merge!({:common_classroom => _('Classroom in common')})

  RULES += %w[
    people_with_common_classroom
  ]

  def self.people_with_common_classroom(person)
    usp_id = person.usp_id
    return if usp_id.nil?
    person_attempts = 0
    StoaPlugin::UspAlunoTurmaGrad.classrooms_from_person(usp_id).each do |classroom|
      person_attempts += 1
      return unless person.profile_suggestions.count < N_SUGGESTIONS && person_attempts < MAX_ATTEMPTS
      StoaPlugin::UspAlunoTurmaGrad.find_all_by_codtur(classroom.codtur).each do |same_class|
        classmate = Person.find_by_usp_id(same_class.codpes)
        unless classmate.nil? || classmate == person || classmate.is_a_friend?(person) || person.already_request_friendship?(classmate)
          suggestion = person.profile_suggestions.find_or_initialize_by_suggestion_id(classmate.id)
          suggestion.common_classroom = 1
          suggestion.save
        end
      end
    end
  end

  def self.people_with_common_discipline(person)
    person_attempts = 0
    person_attempts += 1<commit_msg>suggestions: update use of RULES on stoa plugin<commit_after>require_dependency 'profile_suggestion'

class ProfileSuggestion

  CATEGORIES.merge!({:common_classroom => _('Classroom in common')})

  RULES[:people_with_common_classroom] = {
    :threshold => 2, :weight => 1, :connection => 'Profile'
  }
  def self.people_with_common_classroom(person)
    usp_id = person.usp_id
    return if usp_id.nil?
    person_attempts = 0
    StoaPlugin::UspAlunoTurmaGrad.classrooms_from_person(usp_id).each do |classroom|
      person_attempts += 1
      return unless person.profile_suggestions.count < N_SUGGESTIONS && person_attempts < MAX_ATTEMPTS
      StoaPlugin::UspAlunoTurmaGrad.find_all_by_codtur(classroom.codtur).each do |same_class|
        classmate = Person.find_by_usp_id(same_class.codpes)
        unless classmate.nil? || classmate == person || classmate.is_a_friend?(person) || person.already_request_friendship?(classmate)
          suggestion = person.profile_suggestions.find_or_initialize_by_suggestion_id(classmate.id)
          suggestion.common_classroom = 1
          suggestion.save
        end
      end
    end
  end

  def self.people_with_common_discipline(person)
    person_attempts = 0
    person_attempts += 1
{'fraction_non_alphanumeric': 0.08507963118189438, 'fraction_numerical': 0.005029337803855826, 'mean_word_length': 4.1778741865509765, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '3619548', 'n_tokens_mistral': 829, 'n_tokens_neox': 776, 'n_words': 124}