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

experiments_helper.rb « ml « projects « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a67484e3d2f5c1cd9d043496dfe3b687db814583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
module Projects
  module Ml
    module ExperimentsHelper
      require 'json'
      include ActionView::Helpers::NumberHelper

      def candidates_table_items(candidates)
        items = candidates.map do |candidate|
          {
            **candidate.params.to_h { |p| [p.name, p.value] },
            **candidate.latest_metrics.to_h { |m| [m.name, number_with_precision(m.value, precision: 4)] },
            artifact: link_to_artifact(candidate),
            details: link_to_details(candidate)
          }
        end

        Gitlab::Json.generate(items)
      end

      def unique_logged_names(candidates, &selector)
        Gitlab::Json.generate(candidates.flat_map(&selector).map(&:name).uniq)
      end

      def candidate_as_data(candidate)
        data = {
          params: candidate.params,
          metrics: candidate.latest_metrics,
          info: {
            iid: candidate.iid,
            path_to_artifact: link_to_artifact(candidate),
            experiment_name: candidate.experiment.name,
            path_to_experiment: link_to_experiment(candidate),
            status: candidate.status
          }
        }

        Gitlab::Json.generate(data)
      end

      private

      def link_to_artifact(candidate)
        artifact = candidate.artifact

        return unless artifact.present?

        project_package_path(candidate.experiment.project, artifact)
      end

      def link_to_details(candidate)
        project_ml_candidate_path(candidate.experiment.project, candidate.iid)
      end

      def link_to_experiment(candidate)
        experiment = candidate.experiment

        project_ml_experiment_path(experiment.project, experiment.iid)
      end
    end
  end
end