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 # The graph is interested in whether the component is
19 # indicated as persistent, more than whether the job
20 # satisfying it (which could have been reused, or someone
22 j[:output_is_persistent] = v[:output_is_persistent]
24 uuid = j[:uuid].intern
26 pips[uuid] = 0 unless pips[uuid] != nil
29 collections << j[:output]
30 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
34 uuid = j[:script_version].intern
35 provenance[uuid] = {:uuid => uuid}
36 pips[uuid] = 0 unless pips[uuid] != nil
40 Collection.where(uuid: collections.compact).each do |c|
43 pips[uuid] = 0 unless pips[uuid] != nil
50 return provenance, pips
54 if @object.components.empty? and @object.pipeline_template_uuid
55 template = PipelineTemplate.find(@object.pipeline_template_uuid)
57 template.components.each do |component_name, component_props|
58 pipeline[component_name] = {}
59 component_props.each do |k, v|
60 if k == :script_parameters
61 pipeline[component_name][:script_parameters] = {}
62 v.each do |param_name, param_value|
63 if param_value.is_a? Hash
64 if param_value[:value]
65 pipeline[component_name][:script_parameters][param_name] = param_value[:value]
66 elsif param_value[:default]
67 pipeline[component_name][:script_parameters][param_name] = param_value[:default]
68 elsif param_value[:optional] != nil or param_value[:required] != nil or param_value[:dataclass] != nil
69 pipeline[component_name][:script_parameters][param_name] = ""
71 pipeline[component_name][:script_parameters][param_name] = param_value
74 pipeline[component_name][:script_parameters][param_name] = param_value
78 pipeline[component_name][k] = v
82 @object.components= pipeline
86 @pipelines = [@object]
89 PipelineInstance.where(uuid: params[:compare]).each do |p|
94 provenance, pips = graph(@pipelines)
96 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
98 :all_script_parameters => true,
99 :combine_jobs => :script_and_version,
100 :script_version_nodes => true,
106 @breadcrumb_page_name = 'compare'
108 @rows = [] # each is {name: S, components: [...]}
110 # Build a table: x=pipeline y=component
111 @objects.each_with_index do |pi, pi_index|
112 pipeline_jobs(pi).each do |component|
113 # Find a cell with the same name as this component but no
114 # entry for this pipeline
116 @rows.each_with_index do |row, row_index|
117 if row[:name] == component[:name] and !row[:components][pi_index]
122 target_row = {name: component[:name], components: []}
125 target_row[:components][pi_index] = component
130 # Build a "normal" pseudo-component for this row by picking the
131 # most common value for each attribute. If all values are
132 # equally common, there is no "normal".
133 normal = {} # attr => most common value
134 highscore = {} # attr => how common "normal" is
135 score = {} # attr => { value => how common }
136 row[:components].each do |pj|
139 vstr = for_comparison v
141 score[k][vstr] = (score[k][vstr] || 0) + 1
143 if score[k][vstr] == highscore[k]
144 # tie for first place = no "normal"
146 elsif score[k][vstr] == highscore[k] + 1
147 # more pipelines have v than anything else
148 highscore[k] = score[k][vstr]
154 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
155 row[:components].each do |pj|
159 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
164 provenance, pips = graph(@objects)
166 @pipelines = @objects
168 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
170 :all_script_parameters => true,
171 :combine_jobs => :script_and_version,
172 :script_version_nodes => true,
177 %w(Components Graph Attributes Metadata JSON API)
180 def compare_pane_list
185 updates = params[@object.class.to_s.underscore.singularize.to_sym]
186 if updates["components"]
187 require 'deep_merge/rails_compat'
188 updates["components"] = updates["components"].deeper_merge(@object.components)
194 @objects ||= model_class.limit(20).all
200 if v.is_a? Hash or v.is_a? Array
207 def find_objects_by_uuid
208 @objects = model_class.where(uuid: params[:uuids])