<commit_before>class Project < ActiveRecord::Base
  include Searchable
  include SourceRank
  HAS_DEPENDENCIES = false
  STATUSES = ['Active', 'Deprecated', 'Unmaintained', 'Help Wanted', 'Removed']

  validates_presence_of :name, :platform

  #  validate unique name and platform (case senstivite )

  has_many :versions
  has_many :dependencies, -> { group 'project_name' }, through: :versions
  has_many :github_contributions, through: :github_repository
  has_many :contributors, through: :github_contributions, source: :github_user
  has_many :github_tags, through: :github_repository
  has_many :dependents, class_name: 'Dependency'
  has_many :repository_dependencies
  has_many :dependent_manifests, through: :repository_dependencies, source: :manifest
  has_many :dependent_repositories, -> { group('github_repositories.id').order('github_repositories.stargazers_count DESC') }, through: :dependent_manifests, source: :github_repository
  has_many :subscriptions
  has_many :project_suggestions
  belongs_to :github_repository
  has_one :readme, through: :github_repository

  scope :platform, ->(platform) { where('lower(platform) = ?', platform.try(:downcase)) }
  scope :with_homepage, -> { where("homepage <> ''") }
  scope :with_repository_url, -> { where("repository_url <> ''") }
  scope :without_repository_url, -> { where("repository_url IS ? OR repository_url = ''", nil) }
  scope :with_repo, -> { joins(:github_repository).where('github_repositories.id IS NOT NULL') }
  scope :without_repo, -> { where(github_repository_id: nil) }

  scope :with_license, -> { where("licenses <> ''") }
  scope :without_license, -> { where("licenses IS ? OR licenses = ''", nil) }
  scope :unlicensed, -> { not_deprecated.without_license.with_repo.where("github_repositories.license IS ? OR github_repositories.license = ''", nil) }

  scope :with_versions, -> { where('versions_count > 0') }
  scope :without_versions, -> { where('versions_count < 1') }
  scope :few_versions, -> { where('versions_count < 2') }
  scope :many_versions, -> { where('versions_count > 2') }

  scope :with_dependents, -> { where('dependents_count > 0') }

  scope :with_github_url, -> { where('repository_url ILIKE ?', '%github.com%') }
  scope :with_gitlab_url, -> { where('repository_url ILIKE ?', '%gitlab.com%') }
  scope :with_bitbucket_url, -> { where('repository_url ILIKE ?', '%bitbucket.org%') }
  scope :with_launchpad_url, -> { where('repository_url ILIKE ?', '%launchpad.net%') }
  scope :with_sourceforge_url, -> { where('repository_url ILIKE ?', '%sourceforge.net%') }

  scope :most_watched, -> { joins(:subscriptions).group('projects.id').order("COUNT(subscriptions.id) DESC") }
  scope :most_dependents, -> { with_dependents.order('dependents_count DESC') }

  scope :not_deprecated, -> { where('projects."status" != ? OR projects."status" IS NULL', "Deprecated")}
  scope :deprecated, -> { where('projects."status" = ?', "Deprecated")}

  scope :bus_factor, -> { not_deprecated.
                          joins(:github_repository)
                         .where('github_repositories.github_contributions_count < 6')
                         .where('github_repositories.github_contributions_count > 0')
                         .where('github_repositories.stargazers_count > 0')
                          }

  after_commit :update_github_repo_async, on: :create
  after_commit :set_dependents_count
  before_save  :normalize_licenses,
               :set_latest_release_published_at,
               :set_latest_release_number,
               :set_source_rank,
               :set_language

  def to_param
    { name: name, platform: platform.downcase }
  end

  def to_s
    name
  end

  def follows_semver?<commit_msg>Added removed scope<commit_after>class Project < ActiveRecord::Base
  include Searchable
  include SourceRank
  HAS_DEPENDENCIES = false
  STATUSES = ['Active', 'Deprecated', 'Unmaintained', 'Help Wanted', 'Removed']

  validates_presence_of :name, :platform

  #  validate unique name and platform (case senstivite )

  has_many :versions
  has_many :dependencies, -> { group 'project_name' }, through: :versions
  has_many :github_contributions, through: :github_repository
  has_many :contributors, through: :github_contributions, source: :github_user
  has_many :github_tags, through: :github_repository
  has_many :dependents, class_name: 'Dependency'
  has_many :repository_dependencies
  has_many :dependent_manifests, through: :repository_dependencies, source: :manifest
  has_many :dependent_repositories, -> { group('github_repositories.id').order('github_repositories.stargazers_count DESC') }, through: :dependent_manifests, source: :github_repository
  has_many :subscriptions
  has_many :project_suggestions
  belongs_to :github_repository
  has_one :readme, through: :github_repository

  scope :platform, ->(platform) { where('lower(platform) = ?', platform.try(:downcase)) }
  scope :with_homepage, -> { where("homepage <> ''") }
  scope :with_repository_url, -> { where("repository_url <> ''") }
  scope :without_repository_url, -> { where("repository_url IS ? OR repository_url = ''", nil) }
  scope :with_repo, -> { joins(:github_repository).where('github_repositories.id IS NOT NULL') }
  scope :without_repo, -> { where(github_repository_id: nil) }

  scope :with_license, -> { where("licenses <> ''") }
  scope :without_license, -> { where("licenses IS ? OR licenses = ''", nil) }
  scope :unlicensed, -> { not_deprecated.without_license.with_repo.where("github_repositories.license IS ? OR github_repositories.license = ''", nil) }

  scope :with_versions, -> { where('versions_count > 0') }
  scope :without_versions, -> { where('versions_count < 1') }
  scope :few_versions, -> { where('versions_count < 2') }
  scope :many_versions, -> { where('versions_count > 2') }

  scope :with_dependents, -> { where('dependents_count > 0') }

  scope :with_github_url, -> { where('repository_url ILIKE ?', '%github.com%') }
  scope :with_gitlab_url, -> { where('repository_url ILIKE ?', '%gitlab.com%') }
  scope :with_bitbucket_url, -> { where('repository_url ILIKE ?', '%bitbucket.org%') }
  scope :with_launchpad_url, -> { where('repository_url ILIKE ?', '%launchpad.net%') }
  scope :with_sourceforge_url, -> { where('repository_url ILIKE ?', '%sourceforge.net%') }

  scope :most_watched, -> { joins(:subscriptions).group('projects.id').order("COUNT(subscriptions.id) DESC") }
  scope :most_dependents, -> { with_dependents.order('dependents_count DESC') }

  scope :not_deprecated, -> { where('projects."status" != ? OR projects."status" != ? OR projects."status" IS NULL', "Deprecated", "Removed")}
  scope :deprecated, -> { where('projects."status" = ?', "Deprecated")}
  scope :removed, -> { where('projects."status" = ?', "Removed")}


  scope :bus_factor, -> { not_deprecated.
                          joins(:github_repository)
                         .where('github_repositories.github_contributions_count < 6')
                         .where('github_repositories.github_contributions_count > 0')
                         .where('github_repositories.stargazers_count > 0')
                          }

  after_commit :update_github_repo_async, on: :create
  after_commit :set_dependents_count
  before_save  :normalize_licenses,
               :set_latest_release_published_at,
               :set_latest_release_number,
               :set_source_rank,
               :set_language

  def to_param
    { name: name, platform: platform.downcase }
  end

  def to_s
    name
  end

  def follows_semver?
{'fraction_non_alphanumeric': 0.1366763694098968, 'fraction_numerical': 0.0021169621593014024, 'mean_word_length': 4.242024965325936, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 72, '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': '6398078', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2282, 'n_words': 454}