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 @breadcrumb_page_name = 'compare'
9 @rows = [] # each is {name: S, components: [...]}
11 # Build a table: x=pipeline y=component
12 @objects.each_with_index do |pi, pi_index|
13 pipeline_jobs(pi).each do |component|
14 # Find a cell with the same name as this component but no
15 # entry for this pipeline
17 @rows.each_with_index do |row, row_index|
18 if row[:name] == component[:name] and !row[:components][pi_index]
23 target_row = {name: component[:name], components: []}
26 target_row[:components][pi_index] = component
31 # Build a "normal" pseudo-component for this row by picking the
32 # most common value for each attribute. If all values are
33 # equally common, there is no "normal".
34 normal = {} # attr => most common value
35 highscore = {} # attr => how common "normal" is
36 score = {} # attr => { value => how common }
37 row[:components].each do |pj|
39 vstr = for_comparison v
41 score[k][vstr] = (score[k][vstr.to_s] || 0) + 1
43 if score[k][vstr] == highscore[k]
44 # tie for first place = no "normal"
46 elsif score[k][vstr] == highscore[k] + 1
47 # more pipelines have v than anything else
48 highscore[k] = score[k][vstr]
54 # Add a hash in component[:is_normal]: { attr => is_the_value_normal? }
55 row[:components].each do |pj|
58 pj[:is_normal][k] = (normal.has_key?(k) && normal[k] == for_comparison(v))
66 if v.is_a? Hash or v.is_a? Array
73 def find_objects_by_uuid
74 @objects = model_class.where(uuid: params[:uuids])