class Diffux::DiffClusterFinder
This class finds clusters in a diff. A cluster is defined as rows that are different, and are closer than DIFF_ROW_THRESHOLD pixels to its neighboring diff row.
Constants
- MAXIMUM_ADJACENCY_GAP
Public Class Methods
new(number_of_rows)
click to toggle source
@param number_of_rows [Numeric]
# File lib/diffux_core/diff_cluster_finder.rb, line 10 def initialize(number_of_rows) @number_of_rows = number_of_rows @rows_with_diff = SortedSet.new end
Public Instance Methods
clusters()
click to toggle source
Calculate clusters from diff-rows that are close to each other.
@return [Array<Hash>] a list of clusters modeled as hashes:
`{ start: x, finish: y }`
# File lib/diffux_core/diff_cluster_finder.rb, line 31 def clusters results = [] @rows_with_diff.each do |row| current = results.last if !current || current[:finish] + MAXIMUM_ADJACENCY_GAP < row results << { start: row, finish: row, } else current[:finish] = row end end results end
percent_of_rows_different()
click to toggle source
@return [Float] the percent of rows that are different
# File lib/diffux_core/diff_cluster_finder.rb, line 23 def percent_of_rows_different @rows_with_diff.length.to_f / @number_of_rows * 100 end
row_is_different(row)
click to toggle source
Tell the DiffClusterFinder
about a row that is different.
@param row [Numeric]
# File lib/diffux_core/diff_cluster_finder.rb, line 18 def row_is_different(row) @rows_with_diff.add row end