2022-08-27 11:52:29 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ml
|
|
|
|
class Experiment < ApplicationRecord
|
2022-10-11 01:57:18 +05:30
|
|
|
include AtomicInternalId
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
PACKAGE_PREFIX = 'ml_experiment_'
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
validates :name, :project, presence: true
|
|
|
|
validates :name, uniqueness: { scope: :project, message: "should be unique in the project" }
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :user
|
|
|
|
has_many :candidates, class_name: 'Ml::Candidate'
|
2023-03-04 22:38:38 +05:30
|
|
|
has_many :metadata, class_name: 'Ml::ExperimentMetadata'
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
scope :with_candidate_count, -> {
|
|
|
|
left_outer_joins(:candidates)
|
|
|
|
.select("ml_experiments.*, count(ml_candidates.id) as candidate_count")
|
|
|
|
.group(:id)
|
|
|
|
}
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
has_internal_id :iid, scope: :project
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def package_name
|
|
|
|
"#{PACKAGE_PREFIX}#{iid}"
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
class << self
|
|
|
|
def by_project_id_and_iid(project_id, iid)
|
|
|
|
find_by(project_id: project_id, iid: iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
def by_project_id_and_name(project_id, name)
|
|
|
|
find_by(project_id: project_id, name: name)
|
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def by_project_id(project_id)
|
2023-01-13 00:05:48 +05:30
|
|
|
where(project_id: project_id).order(id: :desc)
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
def package_for_experiment?(package_name)
|
|
|
|
return false unless package_name&.starts_with?(PACKAGE_PREFIX)
|
|
|
|
|
|
|
|
iid = package_name.delete_prefix(PACKAGE_PREFIX)
|
|
|
|
|
|
|
|
numeric?(iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def numeric?(value)
|
|
|
|
value.match?(/\A\d+\z/)
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
end
|
|
|
|
end
|