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
7 return nil, nil if params['tab_pane'] != "Graph"
17 p.components.each do |k, v|
20 # The graph is interested in whether the component is
21 # indicated as persistent, more than whether the job
22 # satisfying it (which could have been reused, or someone
24 j[:output_is_persistent] = v[:output_is_persistent]
26 uuid = j[:uuid].intern
28 pips[uuid] = 0 unless pips[uuid] != nil
31 collections << j[:output]
32 ProvenanceHelper::find_collections(j[:script_parameters]).each do |k|
36 uuid = j[:script_version].intern
37 provenance[uuid] = {:uuid => uuid}
38 pips[uuid] = 0 unless pips[uuid] != nil
42 Collection.where(uuid: collections.compact).each do |c|
45 pips[uuid] = 0 unless pips[uuid] != nil
52 return provenance, pips
56 @pipelines = [@object]
59 PipelineInstance.where(uuid: params[:compare]).each do |p|
64 provenance, pips = graph(@pipelines)
66 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
68 :all_script_parameters => true,
69 :combine_jobs => :script_and_version,
70 :script_version_nodes => true,
78 @breadcrumb_page_name = 'compare'
80 @rows = [] # each is {name: S, components: [...]}
82 # Build a table: x=pipeline y=component
83 @objects.each_with_index do |pi, pi_index|
84 pipeline_jobs(pi).each do |component|
85 # Find a cell with the same name as this component but no
86 # entry for this pipeline
88 @rows.each_with_index do |row, row_index|
89 if row[:name] == component[:name] and !row[:components][pi_index]
94 target_row = {name: component[:name], components: []}
97 target_row[:components][pi_index] = component
102 # Build a "normal" pseudo-component for this row by picking the
103 # most common value for each attribute. If all values are
104 # equally common, there is no "normal".
105 normal = {} # attr => most common value
106 highscore = {} # attr => how common "normal" is
107 score = {} # attr => { value => how common }
108 row[:components].each do |pj|
111 vstr = for_comparison v
113 score[k][vstr] = (score[k][vstr] || 0) + 1
115 if score[k][vstr] == highscore[k]
116 # tie for first place = no "normal"
118 elsif score[k][vstr] == highscore[k] + 1
119 # more pipelines have v than anything else
120 highscore[k] = score[k][vstr]
126 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
127 row[:components].each do |pj|
131 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
136 provenance, pips = graph(@objects)
138 @pipelines = @objects
140 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
142 :all_script_parameters => true,
143 :combine_jobs => :script_and_version,
144 :script_version_nodes => true,
149 panes = %w(Components Graph Attributes Metadata JSON API)
150 if @object and @object.state.in? ['New', 'Ready']
151 panes = %w(Inputs) + panes
156 def compare_pane_list
167 if v.is_a? Hash or v.is_a? Array
174 def find_objects_by_uuid
175 @objects = model_class.where(uuid: params[:uuids])