Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-06 15:08:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-06 15:08:07 +0300
commitb161512b300e70c1e786dd299867dad284e11019 (patch)
treed0537a6f97b8a117a1a7763c50dca18735b64aca /app/presenters/ml
parenteb4b72630a9f479f33858fc9011e18666da3bbba (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/presenters/ml')
-rw-r--r--app/presenters/ml/candidates_csv_presenter.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/app/presenters/ml/candidates_csv_presenter.rb b/app/presenters/ml/candidates_csv_presenter.rb
new file mode 100644
index 00000000000..8e2baf6bd28
--- /dev/null
+++ b/app/presenters/ml/candidates_csv_presenter.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+module Ml
+ class CandidatesCsvPresenter
+ CANDIDATE_ASSOCIATIONS = [:latest_metrics, :params, :experiment].freeze
+ # This file size limit is mainly to avoid the generation to hog resources from the server. The value is arbitrary
+ # can be update once we have better insight into usage.
+ TARGET_FILESIZE = 2.megabytes
+
+ def initialize(candidates)
+ @candidates = candidates
+ end
+
+ def present
+ CsvBuilder.new(@candidates, headers, CANDIDATE_ASSOCIATIONS).render(TARGET_FILESIZE)
+ end
+
+ private
+
+ def headers
+ metric_names = columns_names(&:metrics)
+ param_names = columns_names(&:params)
+
+ candidate_to_metrics = @candidates.to_h do |candidate|
+ [candidate.id, candidate.latest_metrics.to_h { |m| [m.name, m.value] }]
+ end
+
+ candidate_to_params = @candidates.to_h do |candidate|
+ [candidate.id, candidate.params.to_h { |m| [m.name, m.value] }]
+ end
+
+ {
+ project_id: 'project_id',
+ experiment_iid: ->(c) { c.experiment.iid },
+ candidate_iid: 'internal_id',
+ name: 'name',
+ external_id: 'eid',
+ start_time: 'start_time',
+ end_time: 'end_time',
+ **param_names.index_with { |name| ->(c) { candidate_to_params.dig(c.id, name) } },
+ **metric_names.index_with { |name| ->(c) { candidate_to_metrics.dig(c.id, name) } }
+ }
+ end
+
+ def columns_names(&selector)
+ @candidates.flat_map(&selector).map(&:name).uniq
+ end
+ end
+end