diff options
Diffstat (limited to 'app/models/ml')
-rw-r--r-- | app/models/ml/candidate.rb | 13 | ||||
-rw-r--r-- | app/models/ml/experiment.rb | 26 |
2 files changed, 37 insertions, 2 deletions
diff --git a/app/models/ml/candidate.rb b/app/models/ml/candidate.rb index e181217f01c..29e1ba88528 100644 --- a/app/models/ml/candidate.rb +++ b/app/models/ml/candidate.rb @@ -2,11 +2,24 @@ module Ml class Candidate < ApplicationRecord + enum status: { running: 0, scheduled: 1, finished: 2, failed: 3, killed: 4 } + validates :iid, :experiment, presence: true + validates :status, inclusion: { in: statuses.keys } belongs_to :experiment, class_name: 'Ml::Experiment' belongs_to :user has_many :metrics, class_name: 'Ml::CandidateMetric' has_many :params, class_name: 'Ml::CandidateParam' + + default_value_for(:iid) { SecureRandom.uuid } + + class << self + def with_project_id_and_iid(project_id, iid) + return unless project_id.present? && iid.present? + + joins(:experiment).find_by(experiment: { project_id: project_id }, iid: iid) + end + end end end diff --git a/app/models/ml/experiment.rb b/app/models/ml/experiment.rb index 7ef9c70ba7e..e4e9baac4c8 100644 --- a/app/models/ml/experiment.rb +++ b/app/models/ml/experiment.rb @@ -2,11 +2,33 @@ module Ml class Experiment < ApplicationRecord - validates :name, :iid, :project, presence: true - validates :iid, :name, uniqueness: { scope: :project, message: "should be unique in the project" } + include AtomicInternalId + + validates :name, :project, presence: true + validates :name, uniqueness: { scope: :project, message: "should be unique in the project" } belongs_to :project belongs_to :user has_many :candidates, class_name: 'Ml::Candidate' + + has_internal_id :iid, scope: :project + + def artifact_location + 'not_implemented' + end + + 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 + + def has_record?(project_id, name) + where(project_id: project_id, name: name).exists? + end + end end end |