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", {
92 :all_script_parameters => true,
93 :combine_jobs => :script_and_version,
94 :script_version_nodes => true,
100 @breadcrumb_page_name = 'compare'
102 @rows = [] # each is {name: S, components: [...]}
104 # Build a table: x=pipeline y=component
105 @objects.each_with_index do |pi, pi_index|
106 pipeline_jobs(pi).each do |component|
107 # Find a cell with the same name as this component but no
108 # entry for this pipeline
110 @rows.each_with_index do |row, row_index|
111 if row[:name] == component[:name] and !row[:components][pi_index]
116 target_row = {name: component[:name], components: []}
119 target_row[:components][pi_index] = component
124 # Build a "normal" pseudo-component for this row by picking the
125 # most common value for each attribute. If all values are
126 # equally common, there is no "normal".
127 normal = {} # attr => most common value
128 highscore = {} # attr => how common "normal" is
129 score = {} # attr => { value => how common }
130 row[:components].each do |pj|
133 vstr = for_comparison v
135 score[k][vstr] = (score[k][vstr] || 0) + 1
137 if score[k][vstr] == highscore[k]
138 # tie for first place = no "normal"
140 elsif score[k][vstr] == highscore[k] + 1
141 # more pipelines have v than anything else
142 highscore[k] = score[k][vstr]
148 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
149 row[:components].each do |pj|
153 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
158 provenance, pips = graph(@objects)
160 @pipelines = @objects
162 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
164 :all_script_parameters => true,
165 :combine_jobs => :script_and_version,
166 :script_version_nodes => true,
171 %w(Components Graph Attributes Metadata JSON API)
174 def compare_pane_list
179 updates = params[@object.class.to_s.underscore.singularize.to_sym]
180 if updates["components"]
181 require 'deep_merge/rails_compat'
182 updates["components"] = updates["components"].deeper_merge(@object.components)
188 @objects ||= model_class.limit(20).all
194 if v.is_a? Hash or v.is_a? Array
201 def find_objects_by_uuid
202 @objects = model_class.where(uuid: params[:uuids])