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)
50 @object.components= template.components
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", {
65 :all_script_parameters => true,
66 :combine_jobs => :script_and_version,
67 :script_version_nodes => true,
73 @breadcrumb_page_name = 'compare'
75 @rows = [] # each is {name: S, components: [...]}
77 # Build a table: x=pipeline y=component
78 @objects.each_with_index do |pi, pi_index|
79 pipeline_jobs(pi).each do |component|
80 # Find a cell with the same name as this component but no
81 # entry for this pipeline
83 @rows.each_with_index do |row, row_index|
84 if row[:name] == component[:name] and !row[:components][pi_index]
89 target_row = {name: component[:name], components: []}
92 target_row[:components][pi_index] = component
97 # Build a "normal" pseudo-component for this row by picking the
98 # most common value for each attribute. If all values are
99 # equally common, there is no "normal".
100 normal = {} # attr => most common value
101 highscore = {} # attr => how common "normal" is
102 score = {} # attr => { value => how common }
103 row[:components].each do |pj|
106 vstr = for_comparison v
108 score[k][vstr] = (score[k][vstr] || 0) + 1
110 if score[k][vstr] == highscore[k]
111 # tie for first place = no "normal"
113 elsif score[k][vstr] == highscore[k] + 1
114 # more pipelines have v than anything else
115 highscore[k] = score[k][vstr]
121 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
122 row[:components].each do |pj|
126 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
131 provenance, pips = graph(@objects)
133 @pipelines = @objects
135 @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
136 :all_script_parameters => true,
137 :combine_jobs => :script_and_version,
138 :script_version_nodes => true,
143 %w(Components Graph Attributes Metadata JSON API)
146 def compare_pane_list
152 if v.is_a? Hash or v.is_a? Array
159 def find_objects_by_uuid
160 @objects = model_class.where(uuid: params[:uuids])