1 class PipelineInstancesController < ApplicationController
2 skip_before_filter :find_object_by_uuid, only: :compare
3 before_filter :find_objects_by_uuid, only: :compare
4 include PipelineInstancesHelper
15 p.components.each do |k, v|
18 uuid = j[:uuid].intern
20 pips[uuid] = 0 unless pips[uuid] != nil
23 collections << j[:output]
24 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
28 uuid = j[:script_version].intern
29 provenance[uuid] = {:uuid => uuid}
30 pips[uuid] = 0 unless pips[uuid] != nil
34 Collection.where(uuid: collections.compact).each do |c|
37 pips[uuid] = 0 unless pips[uuid] != nil
44 return provenance, pips
48 if @object.components.empty? and @object.pipeline_template_uuid
49 template = PipelineTemplate.find(@object.pipeline_template_uuid)
51 template.components.each do |component_name, component_props|
52 pipeline[component_name] = {}
53 component_props.each do |k, v|
54 if k == :script_parameters
55 pipeline[component_name][:script_parameters] = {}
56 v.each do |param_name, param_value|
57 if param_value.is_a? Hash
58 if param_value[:value]
59 pipeline[component_name][:script_parameters][param_name] = param_value[:value]
60 elsif param_value[:default]
61 pipeline[component_name][:script_parameters][param_name] = param_value[:default]
62 elsif param_value[:optional] != nil or param_value[:required] != nil or param_value[:dataclass] != nil
63 pipeline[component_name][:script_parameters][param_name] = ""
65 pipeline[component_name][:script_parameters][param_name] = param_value
68 pipeline[component_name][:script_parameters][param_name] = param_value
72 pipeline[component_name][k] = v
76 @object.components= pipeline
80 @pipelines = [@object]
83 PipelineInstance.where(uuid: params[:compare]).each do |p|
88 provenance, pips = graph(@pipelines)
90 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
91 :all_script_parameters => true,
92 :combine_jobs => :script_and_version,
93 :script_version_nodes => true,
99 @breadcrumb_page_name = 'compare'
101 @rows = [] # each is {name: S, components: [...]}
103 # Build a table: x=pipeline y=component
104 @objects.each_with_index do |pi, pi_index|
105 pipeline_jobs(pi).each do |component|
106 # Find a cell with the same name as this component but no
107 # entry for this pipeline
109 @rows.each_with_index do |row, row_index|
110 if row[:name] == component[:name] and !row[:components][pi_index]
115 target_row = {name: component[:name], components: []}
118 target_row[:components][pi_index] = component
123 # Build a "normal" pseudo-component for this row by picking the
124 # most common value for each attribute. If all values are
125 # equally common, there is no "normal".
126 normal = {} # attr => most common value
127 highscore = {} # attr => how common "normal" is
128 score = {} # attr => { value => how common }
129 row[:components].each do |pj|
132 vstr = for_comparison v
134 score[k][vstr] = (score[k][vstr] || 0) + 1
136 if score[k][vstr] == highscore[k]
137 # tie for first place = no "normal"
139 elsif score[k][vstr] == highscore[k] + 1
140 # more pipelines have v than anything else
141 highscore[k] = score[k][vstr]
147 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
148 row[:components].each do |pj|
152 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
157 provenance, pips = graph(@objects)
159 @pipelines = @objects
161 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
162 :all_script_parameters => true,
163 :combine_jobs => :script_and_version,
164 :script_version_nodes => true,
169 %w(Components Graph Attributes Metadata JSON API)
172 def compare_pane_list
177 updates = params[@object.class.to_s.underscore.singularize.to_sym]
178 if updates["components"]
179 require 'deep_merge/rails_compat'
180 updates["components"] = updates["components"].deeper_merge(@object.components)
187 if v.is_a? Hash or v.is_a? Array
194 def find_objects_by_uuid
195 @objects = model_class.where(uuid: params[:uuids])