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 @pipelines = [@object]
57 PipelineInstance.where(uuid: params[:compare]).each do |p|
62 provenance, pips = graph(@pipelines)
64 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
66 :all_script_parameters => true,
67 :combine_jobs => :script_and_version,
68 :script_version_nodes => true,
74 @breadcrumb_page_name = 'compare'
76 @rows = [] # each is {name: S, components: [...]}
78 # Build a table: x=pipeline y=component
79 @objects.each_with_index do |pi, pi_index|
80 pipeline_jobs(pi).each do |component|
81 # Find a cell with the same name as this component but no
82 # entry for this pipeline
84 @rows.each_with_index do |row, row_index|
85 if row[:name] == component[:name] and !row[:components][pi_index]
90 target_row = {name: component[:name], components: []}
93 target_row[:components][pi_index] = component
98 # Build a "normal" pseudo-component for this row by picking the
99 # most common value for each attribute. If all values are
100 # equally common, there is no "normal".
101 normal = {} # attr => most common value
102 highscore = {} # attr => how common "normal" is
103 score = {} # attr => { value => how common }
104 row[:components].each do |pj|
107 vstr = for_comparison v
109 score[k][vstr] = (score[k][vstr] || 0) + 1
111 if score[k][vstr] == highscore[k]
112 # tie for first place = no "normal"
114 elsif score[k][vstr] == highscore[k] + 1
115 # more pipelines have v than anything else
116 highscore[k] = score[k][vstr]
122 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
123 row[:components].each do |pj|
127 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
132 provenance, pips = graph(@objects)
134 @pipelines = @objects
136 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
138 :all_script_parameters => true,
139 :combine_jobs => :script_and_version,
140 :script_version_nodes => true,
145 panes = %w(Components Graph Attributes Metadata JSON API)
146 if @object and @object.state.in? ['New', 'Ready']
147 panes = %w(Inputs) + panes
152 def compare_pane_list
163 if v.is_a? Hash or v.is_a? Array
170 def find_objects_by_uuid
171 @objects = model_class.where(uuid: params[:uuids])